1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.types;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22 import org.apache.hadoop.hbase.util.Bytes;
23 import org.apache.hadoop.hbase.util.Order;
24 import org.apache.hadoop.hbase.util.PositionedByteRange;
25
26
27
28
29
30
31
32
33 @InterfaceAudience.Public
34 @InterfaceStability.Evolving
35 public class RawShort implements DataType<Short> {
36
37 @Override
38 public boolean isOrderPreserving() { return false; }
39
40 @Override
41 public Order getOrder() { return null; }
42
43 @Override
44 public boolean isNullable() { return false; }
45
46 @Override
47 public boolean isSkippable() { return true; }
48
49 @Override
50 public int encodedLength(Short val) { return Bytes.SIZEOF_SHORT; }
51
52 @Override
53 public Class<Short> encodedClass() { return Short.class; }
54
55 @Override
56 public int skip(PositionedByteRange src) {
57 src.setPosition(src.getPosition() + Bytes.SIZEOF_SHORT);
58 return Bytes.SIZEOF_SHORT;
59 }
60
61 @Override
62 public Short decode(PositionedByteRange src) {
63 short val = Bytes.toShort(src.getBytes(), src.getOffset() + src.getPosition());
64 skip(src);
65 return val;
66 }
67
68 @Override
69 public int encode(PositionedByteRange dst, Short val) {
70 Bytes.putShort(dst.getBytes(), dst.getOffset() + dst.getPosition(), val);
71 return skip(dst);
72 }
73
74
75
76
77 public short decodeShort(byte[] buff, int offset) {
78 return Bytes.toShort(buff, offset);
79 }
80
81
82
83
84 public int encodeShort(byte[] buff, int offset, short val) {
85 return Bytes.putShort(buff, offset, val);
86 }
87 }