public static class SedesHelper.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.
This is taken from mahout-core, and is included to avoid having to pull in the entirety of Mahout.
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 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 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 IOException
public 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 IOException
public static void writeSignedVarInt(int value, DataOutput out) throws IOException
IOException
writeSignedVarLong(long, DataOutput)
public static void writeUnsignedVarInt(int value, DataOutput out) throws IOException
IOException
writeUnsignedVarLong(long, DataOutput)
public static long readSignedVarLong(DataInput in) throws IOException
in
- to read bytes fromIOException
- if DataInput
throws IOException
IllegalArgumentException
- 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 IOException
IllegalArgumentException
- 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 IOException
readSignedVarLong(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 IOException
readUnsignedVarLong(DataInput)
Copyright © 2007-2012 The Apache Software Foundation