public final class Varint extends Object
Encodes signed and unsigned values using a common variable-length scheme, found for example in Google's Protocol Buffers. It uses fewer bytes to encode smaller values, but will use slightly more bytes to encode large values.
Signed values are further encoded using so-called zig-zag encoding in order to make them "compatible" with variable-length encoding.
| Modifier and Type | Method and Description |
|---|---|
static int |
readSignedVarInt(DataInput in) |
static long |
readSignedVarLong(DataInput in) |
static int |
readUnsignedVarInt(DataInput in) |
static long |
readUnsignedVarLong(DataInput in) |
static int |
sizeOfSignedVarInt(int value)
Simulation for what will happen when writing a signed int value
as varint.
|
static long |
sizeOfSignedVarLong(long value)
Simulation for what will happen when writing a signed long value
as varlong.
|
static int |
sizeOfUnsignedVarInt(int value)
Simulation for what will happen when writing an unsigned int value
as varint.
|
static long |
sizeOfUnsignedVarLong(long value)
Simulation for what will happen when writing an unsigned long value
as varlong.
|
static void |
writeSignedVarInt(int value,
DataOutput out)
Zig-zag encoding for signed ints
|
static void |
writeSignedVarLong(long value,
DataOutput out)
Zig-zag encoding for signed longs
|
static void |
writeUnsignedVarInt(int value,
DataOutput out) |
static void |
writeUnsignedVarLong(long value,
DataOutput out)
Encodes a value using the variable-length encoding from
Google Protocol Buffers.
|
public static void writeUnsignedVarLong(long value,
DataOutput out)
throws IOException
value - to encodeout - to write bytes toIOException - if DataOutput throws IOExceptionpublic static void writeSignedVarLong(long value,
DataOutput out)
throws IOException
value - to encodeout - to write bytes toIOException - if DataOutput throws IOExceptionpublic static void writeUnsignedVarInt(int value,
DataOutput out)
throws IOException
value - to encodeout - to write bytes toIOExceptionwriteVarLong(long, DataOutput)public static void writeSignedVarInt(int value,
DataOutput out)
throws IOException
value - to encodeout - to write bytes toIOExceptionwriteUnsignedVarInt(int, DataOutput)public static long readUnsignedVarLong(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionpublic static long readSignedVarLong(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionpublic static int readUnsignedVarInt(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionpublic static int readSignedVarInt(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionpublic static long sizeOfUnsignedVarLong(long value)
throws IOException
value - to considerIOExceptionpublic static long sizeOfSignedVarLong(long value)
throws IOException
value - to considerIOExceptionpublic static int sizeOfUnsignedVarInt(int value)
throws IOException
value - to considerIOExceptionpublic static int sizeOfSignedVarInt(int value)
throws IOException
value - to considerIOExceptionCopyright © 2011-2020 The Apache Software Foundation. All Rights Reserved.