Package org.apache.drill.exec.util
Class ByteBufUtil.HadoopWritables
java.lang.Object
org.apache.drill.exec.util.ByteBufUtil.HadoopWritables
- Enclosing class:
- ByteBufUtil
Modeled after
org.apache.hadoop.io.WritableUtils
.
We copy the code to avoid wrapping DrillBuf
to/from DataInput
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
decodeVIntSize
(byte value) Parse the first byte of a vint/vlong to determine the number of bytesstatic int
getVIntSize
(long i) Get the encoded length if an integer is stored in a variable-length formatstatic boolean
isNegativeVInt
(byte value) Given the first byte of a vint/vlong, determine the signstatic int
Reads a zero-compressed encoded integer from input stream and returns it.static long
Reads a zero-compressed encoded long from input stream and returns it.static void
Serializes an integer to a binary stream with zero-compressed encoding.static void
writeVLong
(DrillBuf buffer, int start, int end, long i) Serializes a long to a binary stream with zero-compressed encoding.
-
Constructor Details
-
HadoopWritables
public HadoopWritables()
-
-
Method Details
-
writeVInt
Serializes an integer to a binary stream with zero-compressed encoding. For -120 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the integer is positive or negative, and the number of bytes that follow. If the first byte value v is between -121 and -124, the following integer is positive, with number of bytes that follow are -(v+120). If the first byte value v is between -125 and -128, the following integer is negative, with number of bytes that follow are -(v+124). Bytes are stored in the high-non-zero-byte-first order.- Parameters:
buffer
- DrillBuf to read fromi
- Integer to be serialized
-
writeVLong
Serializes a long to a binary stream with zero-compressed encoding. For -112 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the long is positive or negative, and the number of bytes that follow. If the first byte value v is between -113 and -120, the following long is positive, with number of bytes that follow are -(v+112). If the first byte value v is between -121 and -128, the following long is negative, with number of bytes that follow are -(v+120). Bytes are stored in the high-non-zero-byte-first order.- Parameters:
buffer
- DrillBuf to write toi
- Long to be serialized
-
readVInt
Reads a zero-compressed encoded integer from input stream and returns it.- Parameters:
buffer
- DrillBuf to read from- Returns:
- deserialized integer from stream.
-
readVLong
Reads a zero-compressed encoded long from input stream and returns it.- Parameters:
buffer
- DrillBuf to read from- Returns:
- deserialized long from stream.
-
decodeVIntSize
public static int decodeVIntSize(byte value) Parse the first byte of a vint/vlong to determine the number of bytes- Parameters:
value
- the first byte of the vint/vlong- Returns:
- the total number of bytes (1 to 9)
-
getVIntSize
public static int getVIntSize(long i) Get the encoded length if an integer is stored in a variable-length format- Returns:
- the encoded length
-
isNegativeVInt
public static boolean isNegativeVInt(byte value) Given the first byte of a vint/vlong, determine the sign- Parameters:
value
- the first byte- Returns:
- is the value negative
-