summaryrefslogtreecommitdiff
path: root/src/btree/bt_cell.c
blob: 864068f7c4922a5466155348716027e8b0661374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*-
 * Copyright (c) 2008-2012 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __wt_cell_copy --
 *	Copy an on-page cell into a return buffer, processing as needed.
 */
int
__wt_cell_copy(WT_SESSION_IMPL *session, WT_CELL *cell, WT_BUF *retb)
{
	WT_CELL_UNPACK *unpack, _unpack;

	unpack = &_unpack;

	__wt_cell_unpack(cell, unpack);
	return (__wt_cell_unpack_copy(session, unpack, retb));
}

/*
 * __wt_cell_unpack_copy --
 *	Copy an unpacked cell into a return buffer, processing as needed.
 */
int
__wt_cell_unpack_copy(
    WT_SESSION_IMPL *session, WT_CELL_UNPACK *unpack, WT_BUF *retb)
{
	WT_BTREE *btree;
	void *huffman;

	btree = session->btree;

	/* Get the cell's data. */
	switch (unpack->type) {
	case WT_CELL_KEY:
	case WT_CELL_VALUE:
		WT_RET(__wt_buf_set(session, retb, unpack->data, unpack->size));
		break;
	case WT_CELL_KEY_OVFL:
	case WT_CELL_VALUE_OVFL:
		WT_RET(__wt_ovfl_in(session, retb, unpack->data, unpack->size));
		break;
	WT_ILLEGAL_VALUE(session);
	}

	/* Select a Huffman encoding function. */
	switch (unpack->type) {
	case WT_CELL_KEY:
	case WT_CELL_KEY_OVFL:
		if ((huffman = btree->huffman_key) == NULL)
			return (0);
		break;
	case WT_CELL_VALUE:
	case WT_CELL_VALUE_OVFL:
	default:
		if ((huffman = btree->huffman_value) == NULL)
			return (0);
		break;
	}

	return (__wt_huffman_decode(
	    session, huffman, retb->data, retb->size, retb));
}