public static class SedesHelper.Varint
extends java.lang.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(java.io.DataInput in) |
static long |
readSignedVarLong(java.io.DataInput in) |
static int |
readUnsignedVarInt(java.io.DataInput in) |
static long |
readUnsignedVarLong(java.io.DataInput in) |
static void |
writeSignedVarInt(int value,
java.io.DataOutput out) |
static void |
writeSignedVarLong(long value,
java.io.DataOutput out)
Encodes a value using the variable-length encoding from
Google Protocol Buffers.
|
static void |
writeUnsignedVarInt(int value,
java.io.DataOutput out) |
static void |
writeUnsignedVarLong(long value,
java.io.DataOutput out)
Encodes a value using the variable-length encoding from
Google Protocol Buffers.
|
public static void writeSignedVarLong(long value, java.io.DataOutput out) throws java.io.IOException
writeUnsignedVarLong(long, DataOutput)
should be used.value
- value to encodeout
- to write bytes tojava.io.IOException
- if DataOutput
throws IOException
public static void writeUnsignedVarLong(long value, java.io.DataOutput out) throws java.io.IOException
writeSignedVarLong(long, DataOutput)
instead. This method treats negative input as like a large unsigned value.value
- value to encodeout
- to write bytes tojava.io.IOException
- if DataOutput
throws IOException
public static void writeSignedVarInt(int value, java.io.DataOutput out) throws java.io.IOException
java.io.IOException
writeSignedVarLong(long, DataOutput)
public static void writeUnsignedVarInt(int value, java.io.DataOutput out) throws java.io.IOException
java.io.IOException
writeUnsignedVarLong(long, DataOutput)
public static long readSignedVarLong(java.io.DataInput in) throws java.io.IOException
in
- to read bytes fromjava.io.IOException
- if DataInput
throws IOException
java.lang.IllegalArgumentException
- if variable-length value does not terminate
after 9 bytes have been readwriteSignedVarLong(long, DataOutput)
public static long readUnsignedVarLong(java.io.DataInput in) throws java.io.IOException
in
- to read bytes fromjava.io.IOException
- if DataInput
throws IOException
java.lang.IllegalArgumentException
- if variable-length value does not terminate
after 9 bytes have been readwriteUnsignedVarLong(long, DataOutput)
public static int readSignedVarInt(java.io.DataInput in) throws java.io.IOException
java.lang.IllegalArgumentException
- if variable-length value does not terminate
after 5 bytes have been readjava.io.IOException
- if DataInput
throws IOException
readSignedVarLong(DataInput)
public static int readUnsignedVarInt(java.io.DataInput in) throws java.io.IOException
java.lang.IllegalArgumentException
- if variable-length value does not terminate
after 5 bytes have been readjava.io.IOException
- if DataInput
throws IOException
readUnsignedVarLong(DataInput)
Copyright © 2007-2017 The Apache Software Foundation