public final class VarEncodingHelper
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static long |
decodeSignedVarLong(Input input)
decodeSignedVarLong deserializes long values that have been encoded using
encodeSignedVarLong(Output, long). |
static long |
decodeUnsignedVarLong(Input input)
decodeUnsignedVarLong deserializes long values that have been encoded using
encodeUnsignedVarLong(Output, long). |
static double |
decodeVarDouble(Input input)
decodeSignedVarLong deserializes double values that have been encoded using
encodeVarDouble(Output, double). |
static void |
encodeSignedVarLong(Output output,
long value)
encodeSignedVarLong serializes long values using zig-zag encoding, which
ensures small-scale integers are turned into integers that have leading zeros, whether they are
positive or negative, hence allows for space-efficient encoding of those values. |
static void |
encodeUnsignedVarLong(Output output,
long value)
encodeUnsignedVarLong serializes long values 7 bits at a time, starting with
the least significant bits. |
static void |
encodeVarDouble(Output output,
double value)
encodeVarDouble serializes double values using a method that is similar to the
varint encoding and that is space-efficient for non-negative integer values. |
static byte |
signedVarLongEncodedLength(long value)
signedVarLongEncodedLength returns the number of bytes that encodeSignedVarLong(Output, long) encodes a long value into. |
static byte |
unsignedVarLongEncodedLength(long value)
unsignedVarLongEncodedLength returns the number of bytes that encodeUnsignedVarLong(Output, long) encodes a long value into. |
static byte |
varDoubleEncodedLength(double value)
varDoubleEncodedLength returns the number of bytes that encodeVarDouble(Output,
double) encodes a double value into. |
public static void encodeUnsignedVarLong(Output output, long value) throws java.io.IOException
encodeUnsignedVarLong serializes long values 7 bits at a time, starting with
the least significant bits. The most significant bit in each output byte is the continuation
bit and indicates whether there are additional non-zero bits encoded in following bytes. There
are at most 9 output bytes and the last one does not have a continuation bit, allowing for it
to encode 8 bits (\(8*7+8 = 64\)).output - what to write tovalue - the value to encodejava.io.IOException - if an IOException is thrown while writing to outputpublic static long decodeUnsignedVarLong(Input input) throws java.io.IOException
decodeUnsignedVarLong deserializes long values that have been encoded using
encodeUnsignedVarLong(Output, long).input - what to read fromjava.io.IOException - if an IOException is thrown while reading from inputpublic static byte unsignedVarLongEncodedLength(long value)
unsignedVarLongEncodedLength returns the number of bytes that encodeUnsignedVarLong(Output, long) encodes a long value into.value - the value to encodeencodeUnsignedVarLong(Output, long) encodes a long value intopublic static void encodeSignedVarLong(Output output, long value) throws java.io.IOException
encodeSignedVarLong serializes long values using zig-zag encoding, which
ensures small-scale integers are turned into integers that have leading zeros, whether they are
positive or negative, hence allows for space-efficient encoding of those values.output - what to write tovalue - the value to encodejava.io.IOException - if an IOException is thrown while writing to outputpublic static long decodeSignedVarLong(Input input) throws java.io.IOException
decodeSignedVarLong deserializes long values that have been encoded using
encodeSignedVarLong(Output, long).input - what to read fromjava.io.IOException - if an IOException is thrown while reading from inputpublic static byte signedVarLongEncodedLength(long value)
signedVarLongEncodedLength returns the number of bytes that encodeSignedVarLong(Output, long) encodes a long value into.value - the value to encodeencodeSignedVarLong(Output, long) encodes a long value intopublic static void encodeVarDouble(Output output, double value) throws java.io.IOException
encodeVarDouble serializes double values using a method that is similar to the
varint encoding and that is space-efficient for non-negative integer values. The output takes
at most 9 bytes.
Input values are first shifted as floating-point values (+1), then transmuted to
integer values, then shifted again as integer values (-Double.doubleToRawLongBits(1)).
That is in order to minimize the number of non-zero bits when dealing with non-negative integer
values.
After that transformation, any input integer value no greater than \(2^{53}\) (the largest integer value that can be encoded exactly as a 64-bit floating-point value) will have at least 6 leading zero bits. By rotating bits to the left, those bits end up at the right of the binary representation.
The resulting bits are then encoded similarly to the varint method, but starting with the most significant bits.
output - what to write tovalue - the value to encodejava.io.IOException - if an IOException is thrown while writing to outputpublic static double decodeVarDouble(Input input) throws java.io.IOException
decodeSignedVarLong deserializes double values that have been encoded using
encodeVarDouble(Output, double).input - what to read fromjava.io.IOException - if an IOException is thrown while reading from inputpublic static byte varDoubleEncodedLength(double value)
varDoubleEncodedLength returns the number of bytes that encodeVarDouble(Output,
double) encodes a double value into.value - the value to encodeencodeVarDouble(Output, double) encodes a double value into