1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.io.encoding;
18
19 import java.nio.ByteBuffer;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.KeyValue;
23 import org.apache.hadoop.hbase.util.ByteBufferUtils;
24
25
26
27
28 @InterfaceAudience.Private
29 class CompressionState {
30 int keyLength;
31 int valueLength;
32
33 short rowLength;
34 int prevOffset = FIRST_KEY;
35 byte familyLength;
36 int qualifierLength;
37 byte type;
38
39 private final static int FIRST_KEY = -1;
40
41 boolean isFirst() {
42 return prevOffset == FIRST_KEY;
43 }
44
45
46
47
48
49
50
51
52 void readKey(ByteBuffer in, int keyLength, int valueLength) {
53 readKey(in, keyLength, valueLength, 0, null);
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 void readKey(ByteBuffer in, int keyLength, int valueLength,
70 int commonPrefix, CompressionState previousState) {
71 this.keyLength = keyLength;
72 this.valueLength = valueLength;
73
74
75 in.mark();
76
77 if (commonPrefix < KeyValue.ROW_LENGTH_SIZE) {
78 rowLength = in.getShort();
79 ByteBufferUtils.skip(in, rowLength);
80
81 familyLength = in.get();
82
83 qualifierLength = keyLength - rowLength - familyLength -
84 KeyValue.KEY_INFRASTRUCTURE_SIZE;
85 ByteBufferUtils.skip(in, familyLength + qualifierLength);
86 } else {
87 rowLength = previousState.rowLength;
88 familyLength = previousState.familyLength;
89 qualifierLength = previousState.qualifierLength +
90 keyLength - previousState.keyLength;
91 ByteBufferUtils.skip(in, (KeyValue.ROW_LENGTH_SIZE +
92 KeyValue.FAMILY_LENGTH_SIZE) +
93 rowLength + familyLength + qualifierLength);
94 }
95
96 readTimestamp(in);
97
98 type = in.get();
99
100 in.reset();
101 }
102
103 protected void readTimestamp(ByteBuffer in) {
104
105 ByteBufferUtils.skip(in, KeyValue.TIMESTAMP_SIZE);
106 }
107
108 void copyFrom(CompressionState state) {
109 keyLength = state.keyLength;
110 valueLength = state.valueLength;
111
112 rowLength = state.rowLength;
113 prevOffset = state.prevOffset;
114 familyLength = state.familyLength;
115 qualifierLength = state.qualifierLength;
116 type = state.type;
117 }
118 }