1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.codec.prefixtree.decode.column;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
23 import org.apache.hadoop.hbase.codec.prefixtree.encode.other.ColumnNodeType;
24 import org.apache.hadoop.hbase.util.vint.UFIntTool;
25 import org.apache.hadoop.hbase.util.vint.UVIntTool;
26
27 @InterfaceAudience.Private
28 public class ColumnNodeReader {
29
30
31
32 protected PrefixTreeBlockMeta blockMeta;
33 protected byte[] block;
34 protected ColumnNodeType nodeType;
35 protected byte[] columnBuffer;
36
37 protected int offsetIntoBlock;
38
39 protected int tokenOffsetIntoBlock;
40 protected int tokenLength;
41 protected int parentStartPosition;
42
43
44
45
46 public ColumnNodeReader(byte[] columnBuffer, ColumnNodeType nodeType) {
47 this.columnBuffer = columnBuffer;
48 this.nodeType = nodeType;
49 }
50
51 public void initOnBlock(PrefixTreeBlockMeta blockMeta, byte[] block) {
52 this.blockMeta = blockMeta;
53 this.block = block;
54 }
55
56
57
58
59 public void positionAt(int offsetIntoBlock) {
60 this.offsetIntoBlock = offsetIntoBlock;
61 tokenLength = UVIntTool.getInt(block, offsetIntoBlock);
62 tokenOffsetIntoBlock = offsetIntoBlock + UVIntTool.numBytes(tokenLength);
63 int parentStartPositionIndex = tokenOffsetIntoBlock + tokenLength;
64 int offsetWidth;
65 if(nodeType == ColumnNodeType.FAMILY) {
66 offsetWidth = blockMeta.getFamilyOffsetWidth();
67 } else if(nodeType == ColumnNodeType.QUALIFIER) {
68 offsetWidth = blockMeta.getQualifierOffsetWidth();
69 } else {
70 offsetWidth = blockMeta.getTagsOffsetWidth();
71 }
72 parentStartPosition = (int) UFIntTool.fromBytes(block, parentStartPositionIndex, offsetWidth);
73 }
74
75 public void prependTokenToBuffer(int bufferStartIndex) {
76 System.arraycopy(block, tokenOffsetIntoBlock, columnBuffer, bufferStartIndex, tokenLength);
77 }
78
79 public boolean isRoot() {
80 if (nodeType == ColumnNodeType.FAMILY) {
81 return offsetIntoBlock == blockMeta.getAbsoluteFamilyOffset();
82 } else if (nodeType == ColumnNodeType.QUALIFIER) {
83 return offsetIntoBlock == blockMeta.getAbsoluteQualifierOffset();
84 } else {
85 return offsetIntoBlock == blockMeta.getAbsoluteTagsOffset();
86 }
87 }
88
89
90
91
92 @Override
93 public String toString() {
94 return super.toString() + "[" + offsetIntoBlock + "]";
95 }
96
97
98
99
100 public int getTokenLength() {
101 return tokenLength;
102 }
103
104 public int getParentStartPosition() {
105 return parentStartPosition;
106 }
107
108 }