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(byte[] bytes) |
static int |
readSignedVarInt(DataInput in) |
static long |
readSignedVarLong(DataInput in) |
static int |
readUnsignedVarInt(byte[] bytes) |
static int |
readUnsignedVarInt(DataInput in) |
static long |
readUnsignedVarLong(DataInput in) |
static byte[] |
writeSignedVarInt(int value) |
static void |
writeSignedVarInt(int value,
DataOutput out) |
static void |
writeSignedVarLong(long value,
DataOutput out)
Encodes a value using the variable-length encoding from
Google Protocol Buffers.
|
static byte[] |
writeUnsignedVarInt(int value) |
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 writeSignedVarLong(long value,
DataOutput out)
throws IOException
writeUnsignedVarLong(long, DataOutput) should be used.value - value to encodeout - to write bytes toIOException - if DataOutput throws IOExceptionpublic static void writeUnsignedVarLong(long value,
DataOutput out)
throws IOException
writeSignedVarLong(long, DataOutput)
instead. This method treats negative input as like a large unsigned value.value - value to encodeout - to write bytes toIOException - if DataOutput throws IOExceptionpublic static void writeSignedVarInt(int value,
DataOutput out)
throws IOException
IOExceptionwriteSignedVarLong(long, DataOutput)public static void writeUnsignedVarInt(int value,
DataOutput out)
throws IOException
IOExceptionwriteUnsignedVarLong(long, DataOutput)public static byte[] writeSignedVarInt(int value)
public static byte[] writeUnsignedVarInt(int value)
public static long readSignedVarLong(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionIllegalArgumentException - if variable-length value does not terminate
after 9 bytes have been readwriteSignedVarLong(long, DataOutput)public static long readUnsignedVarLong(DataInput in) throws IOException
in - to read bytes fromIOException - if DataInput throws IOExceptionIllegalArgumentException - if variable-length value does not terminate
after 9 bytes have been readwriteUnsignedVarLong(long, DataOutput)public static int readSignedVarInt(DataInput in) throws IOException
IllegalArgumentException - if variable-length value does not terminate
after 5 bytes have been readIOException - if DataInput throws IOExceptionreadSignedVarLong(DataInput)public static int readUnsignedVarInt(DataInput in) throws IOException
IllegalArgumentException - if variable-length value does not terminate
after 5 bytes have been readIOException - if DataInput throws IOExceptionreadUnsignedVarLong(DataInput)public static int readSignedVarInt(byte[] bytes)
public static int readUnsignedVarInt(byte[] bytes)
Copyright © 2016 AddThis. All rights reserved.