Class VarLenInt
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The max number of bytes used to encodelong
values.static final long
The max value supported by this variable-length codec, 2^62-1. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
decodeInt
(ByteBuffer byteBuffer) Decodes anint
value from the givenByteBuffer
.static long
decodeLong
(ByteBuffer byteBuffer) Decodes along
value from the givenByteBuffer
.static void
encode
(ByteBuffer byteBuffer, long value) Variable-length encodes the givenlong
value into the givenByteBuffer
, starting at its current position.static int
length
(long value) Returns the number of bytes necessary to variable-length encode the givenlong
value.boolean
tryDecode
(ByteBuffer byteBuffer, LongConsumer consumer) Tries to decode a variable-lengthlong
from the givenByteBuffer
.boolean
tryDecode
(ByteBuffer byteBuffer, VarLenInt.IntLongConsumer consumer) Tries to decode a variable-lengthlong
from the givenByteBuffer
.
-
Field Details
-
MAX_VALUE
public static final long MAX_VALUEThe max value supported by this variable-length codec, 2^62-1.- See Also:
-
MAX_LENGTH
public static final int MAX_LENGTHThe max number of bytes used to encodelong
values.- See Also:
-
-
Constructor Details
-
VarLenInt
public VarLenInt()
-
-
Method Details
-
tryDecode
Tries to decode a variable-length
long
from the givenByteBuffer
.If there are enough bytes to decode the
long
value, the givenConsumer
is invoked with the value, and this method returnstrue
. Otherwise, there are not enough bytes to decode thelong
value, and this method returnsfalse
.- Parameters:
byteBuffer
- theByteBuffer
to decode fromconsumer
- theLongConsumer
to invoke when the decoding is complete- Returns:
- whether the decoding was complete
-
tryDecode
Tries to decode a variable-length
long
from the givenByteBuffer
.If there are enough bytes to decode the
long
value, the givenIntLongConsumer
is invoked with the number of bytes consumed and the value, and this method returnstrue
. Otherwise, there are not enough bytes to decode thelong
value, and this method returnsfalse
.- Parameters:
byteBuffer
- theByteBuffer
to decode fromconsumer
- theLongConsumer
to invoke when the decoding is complete- Returns:
- whether the decoding was complete
-
decodeInt
Decodes an
int
value from the givenByteBuffer
.- Parameters:
byteBuffer
- theByteBuffer
to decode from- Returns:
- the decoded
int
value
-
decodeLong
Decodes a
long
value from the givenByteBuffer
.- Parameters:
byteBuffer
- theByteBuffer
to decode from- Returns:
- the decoded
long
value
-
encode
Variable-length encodes the given
long
value into the givenByteBuffer
, starting at its current position.- Parameters:
byteBuffer
- theByteBuffer
to encode intovalue
- thelong
value to encode
-
length
public static int length(long value) Returns the number of bytes necessary to variable-length encode the given
long
value.- Parameters:
value
- thelong
value to encode- Returns:
- the number of bytes necessary to variable-length encode the given
long
value
-