Package jadex.binary
Class VarInt
- java.lang.Object
-
- jadex.binary.VarInt
-
public class VarInt extends java.lang.ObjectClass providing methods for encoding integers (longs) as byte array in a variable-length format.
-
-
Constructor Summary
Constructors Constructor Description VarInt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longdecode(byte[] varint)Decodes a VarInt.static longdecode(byte[] varint, int offset)Decodes a VarInt.static longdecodeWithKnownSize(byte[] varint, int offset, byte extsize)Decodes a VarInt when the extension size is known.static byte[]encode(long val)Encodes a VarInt.static voidencode(long val, byte[] buffer, int offset, int size)Encodes a VarInt and saves it in a buffer at the given offset.static intgetEncodedSize(long val)Determines the encoded size of a value.static bytegetExtensionSize(byte firstbyte)Returns the number of bytes used for this number past the first byte.static bytegetExtensionSize(byte[] varint, int offset)Returns the number of bytes used for this number past the first byte.
-
-
-
Method Detail
-
getExtensionSize
public static final byte getExtensionSize(byte[] varint, int offset)Returns the number of bytes used for this number past the first byte.- Parameters:
varint- Encoded VarInt.offset- The offset.- Returns:
- Number of bytes belonging to the number after the first byte.
-
getExtensionSize
public static final byte getExtensionSize(byte firstbyte)
Returns the number of bytes used for this number past the first byte.- Parameters:
firstbyte- First byte of encoded VarInt.- Returns:
- Number of bytes belonging to the number after the first byte.
-
decode
public static final long decode(byte[] varint)
Decodes a VarInt.- Parameters:
varint- The encoded VarInt.- Returns:
- The decoded VarInt.
-
decode
public static final long decode(byte[] varint, int offset)Decodes a VarInt.- Parameters:
varint- The encoded VarInt.- Returns:
- The decoded VarInt.
-
decodeWithKnownSize
public static final long decodeWithKnownSize(byte[] varint, int offset, byte extsize)Decodes a VarInt when the extension size is known.- Parameters:
varint- The encoded VarInt.offset- The offset.The- number of bytes after the first byte.- Returns:
- The decoded VarInt.
-
encode
public static final byte[] encode(long val)
Encodes a VarInt.- Parameters:
val- The value being encoded.- Returns:
- Encoded VarInt.
-
getEncodedSize
public static final int getEncodedSize(long val)
Determines the encoded size of a value.- Parameters:
val- The value.- Returns:
- The size of the encoded value.
-
encode
public static final void encode(long val, byte[] buffer, int offset, int size)Encodes a VarInt and saves it in a buffer at the given offset.- Parameters:
val- The value being encoded.buffer- The target buffer.offset- The buffer offset.size- Size of the encoded VarInt.
-
-