Package org.eclipse.rdf4j.rio.hdt
Class VByte
java.lang.Object
org.eclipse.rdf4j.rio.hdt.VByte
Variable byte encoding for numbers.
A variable number of bytes is used to encode (unsigned) numeric values, the first bit (MSB) of each byte indicates if
there are more bytes to read, the other 7 bits are used to encode the value.
In this implementation, the MSB is set to
1
if this byte is the last one.
E.g: 10000001
is value 1, 00000001 10000001
is 128 (decimal). Note that the value is stored
little-endian, so in this example 10000001 00000001
.- Author:
- Bart.Hanssens
- See Also:
- Variable byte codes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
decode(byte[] bytes, int len)
Decode a series of encoded bytes, with a maximum of 8 bytesstatic long
decode(InputStream is)
Decode a maximum of 8 bytes from the input stream.static long
decodeFrom(byte[] b, int start)
Decode a maximum of 8 bytes from a byte array.static int
encodedLength(long value)
Calculate the number of bytes needed for encoding a valuestatic boolean
hasNext(byte b)
Checks if the most significant bit is set.
-
Constructor Details
-
VByte
public VByte()
-
-
Method Details
-
hasNext
public static boolean hasNext(byte b)Checks if the most significant bit is set. If this bit is zero, then the next byte must also be read to decode the number.- Parameters:
b
-- Returns:
- true if there is a next byte
-
decode
public static long decode(byte[] bytes, int len)Decode a series of encoded bytes, with a maximum of 8 bytes- Parameters:
bytes
- byte arraylen
- number of bytes to decode- Returns:
- long value
-
decode
Decode a maximum of 8 bytes from the input stream.- Parameters:
is
- input stream- Returns:
- decode value
- Throws:
IOException
-
decodeFrom
Decode a maximum of 8 bytes from a byte array.- Parameters:
b
- byte arraystart
- starting position- Returns:
- decode value
- Throws:
IOException
-
encodedLength
public static int encodedLength(long value)Calculate the number of bytes needed for encoding a value- Parameters:
value
- numeric value- Returns:
- number of bytes
-