public class Vint8 extends Object
Compatibility:
This class has been used in products that have shipped to customers, and is needed to
decode legacy data. Do not modify this class in ways that will break compatibility.
Modifier and Type | Class and Description |
---|---|
static class |
Vint8.Position
Because Java lacks call-by-reference, this class boxes the decoding position, which
is initially set by the caller, and returned after decoding, incremented by the number
of bytes processed.
|
Modifier and Type | Field and Description |
---|---|
static int |
MAXIMUM_BYTES_NEEDED
The maximum number of bytes needed to encode a number using
Vint8 . |
Modifier and Type | Method and Description |
---|---|
static int |
bytesNeeded(int number)
Returns the number of bytes needed to encode
number . |
static int |
decode(byte[] bytes,
Vint8.Position pos)
Decodes a 32-bit integer from
bytes , beginning at offset pos.pos . |
static int |
decode(InputStream in)
Decodes a 32-bit integer from bytes read from
in . |
static int |
encode(int number,
byte[] dest,
int start)
Encodes
number into dest , starting at offset start from
the beginning of the array. |
static void |
encode(int number,
OutputStream out)
Encodes
number to out . |
public static final int MAXIMUM_BYTES_NEEDED
Vint8
.public static int bytesNeeded(int number)
number
.number
- The number whose encoded length is needed.number
.public static void encode(int number, OutputStream out) throws IOException
number
to out
.number
- The value to be written in encoded form, to out
.out
- The output stream receiving the encoded bytes.IOException
- If there is a problem writing to out
.public static int encode(int number, byte[] dest, int start)
number
into dest
, starting at offset start
from
the beginning of the array. This method assumes dest
is large enough to
hold the required number of bytes.number
- The number to be encoded.dest
- The destination array.start
- The starting offset in the array.public static int decode(byte[] bytes, Vint8.Position pos)
bytes
, beginning at offset pos.pos
.
The decoded value is returned, and pos.pos
is incremented by the number of
bytes processed.bytes
- The byte array containing an encoded value.pos
- On entry, the starting position in the array; on return, one greater
than the position of the last byte decoded in the call.public static int decode(InputStream in) throws IOException
in
. Bytes are read,
one at a time, from in
, and it is assumed they represent a 32-bit
integer encoded using this class's encoding scheme. The decoded value is
returned.in
- The input stream containing the encoded bytes.EOFException
- If the stream ends before a value has been decoded.IOException