public class VarInt extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_VARINT_SIZE
Maximum encoded size of 32-bit positive integers (in bytes)
|
static int |
MAX_VARLONG_SIZE
maximum encoded size of 64-bit longs, and negative 32-bit ints (in bytes)
|
| Modifier and Type | Method and Description |
|---|---|
static int |
getVarInt(byte[] src,
int offset,
int[] dst)
Reads a varint from src, places its values into the first element of dst and returns the offset
in to src of the first byte after the varint.
|
static int |
getVarInt(ByteBuffer src)
Reads a varint from the current position of the given ByteBuffer and returns the decoded value
as 32 bit integer.
|
static int |
getVarInt(InputStream inputStream)
Reads a varint from the given InputStream and returns the decoded value as an int.
|
static long |
getVarLong(ByteBuffer src)
Reads an up to 64 bit long varint from the current position of the given ByteBuffer and returns
the decoded value as long.
|
static int |
putVarInt(int v,
byte[] sink,
int offset)
Encodes an integer in a variable-length encoding, 7 bits per byte, into a destination byte[],
following the protocol buffer convention.
|
static void |
putVarInt(int v,
ByteBuffer sink)
Encodes an integer in a variable-length encoding, 7 bits per byte, to a ByteBuffer sink.
|
static void |
putVarInt(int v,
OutputStream outputStream)
Encodes an integer in a variable-length encoding, 7 bits per byte, and writes it to the given
OutputStream.
|
static void |
putVarLong(long v,
ByteBuffer sink)
Encodes a long integer in a variable-length encoding, 7 bits per byte, to a ByteBuffer sink.
|
static int |
varIntSize(int i)
Returns the encoding size in bytes of its input value.
|
static int |
varLongSize(long v)
Returns the encoding size in bytes of its input value.
|
public static final int MAX_VARINT_SIZE
public static final int MAX_VARLONG_SIZE
public static int varIntSize(int i)
i - the integer to be measuredpublic static int getVarInt(byte[] src,
int offset,
int[] dst)
src - source buffer to retrieve fromoffset - offset within srcdst - the resulting int valuepublic static int putVarInt(int v,
byte[] sink,
int offset)
v - the int value to write to sinksink - the sink buffer to write tooffset - the offset within sink to begin writingpublic static int getVarInt(ByteBuffer src)
The position of the buffer is advanced to the first byte after the decoded varint.
src - the ByteBuffer to get the var int frompublic static void putVarInt(int v,
ByteBuffer sink)
v - the value to encodesink - the ByteBuffer to add the encoded valuepublic static int getVarInt(InputStream inputStream) throws IOException
inputStream - the InputStream to read fromIOExceptionpublic static void putVarInt(int v,
OutputStream outputStream)
throws IOException
v - the value to encodeoutputStream - the OutputStream to write toIOExceptionpublic static int varLongSize(long v)
v - the long to be measuredpublic static long getVarLong(ByteBuffer src)
The position of the buffer is advanced to the first byte after the decoded varint.
src - the ByteBuffer to get the var int frompublic static void putVarLong(long v,
ByteBuffer sink)
v - the value to encodesink - the ByteBuffer to add the encoded value