Package org.yamcs.utils
Class VarIntUtil
- java.lang.Object
-
- org.yamcs.utils.VarIntUtil
-
public class VarIntUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VarIntUtil.ArrayDecoder
decodes an array of varintsstatic class
VarIntUtil.SignedArrayDecoder
-
Constructor Summary
Constructors Constructor Description VarIntUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]
decodeDeltaDeltaZigZag(int[] ddz)
static IntArray
decodeDeltaIntArray(byte[] buf)
The reverse of theencodeDeltaIntArray(IntArray)
method.static int
decodeZigZag(int x)
static int[]
encodeDeltaDeltaZigZag(int[] x)
static int[]
encodeDeltaDeltaZigZag(IntArray a)
static int[]
encodeDeltaDeltaZigZag(SortedIntArray a)
static byte[]
encodeDeltaIntArray(IntArray s)
Encode an int array as a sequence of varints representing the deltas between the subsequent elements of the input array.static int
encodeSigned(byte[] buf, int pos, int x)
static int
encodeZigZag(int x)
static int
getEncodedSize(int value)
get the number of bytes necessary to encode valuestatic VarIntUtil.ArrayDecoder
newArrayDecoder(byte[] buf)
static int
readSignedVarInt32(ByteBuffer bb)
static String
readSizeDelimitedString(ByteBuffer bb)
static int
readVarInt32(ByteBuffer bb)
static long
readVarInt64(ByteBuffer bb)
static void
writeSignedVarint32(ByteBuffer bb, int x)
static void
writeSizeDelimitedString(ByteBuffer bb, String s)
static int
writeVarInt32(byte[] buf, int pos, int x)
Encodes x as varint in the buffer at position pos and returns the new positionstatic void
writeVarInt32(ByteBuffer bb, int x)
static void
writeVarInt64(ByteBuffer bb, long x)
-
-
-
Method Detail
-
writeVarInt32
public static int writeVarInt32(byte[] buf, int pos, int x)
Encodes x as varint in the buffer at position pos and returns the new position- Parameters:
buf
-x
-- Returns:
- the decoded integer
-
writeVarInt32
public static void writeVarInt32(ByteBuffer bb, int x)
-
writeVarInt64
public static void writeVarInt64(ByteBuffer bb, long x)
-
readVarInt32
public static int readVarInt32(ByteBuffer bb) throws DecodingException
- Throws:
DecodingException
-
readVarInt64
public static long readVarInt64(ByteBuffer bb)
-
writeSignedVarint32
public static void writeSignedVarint32(ByteBuffer bb, int x)
-
readSignedVarInt32
public static int readSignedVarInt32(ByteBuffer bb) throws DecodingException
- Throws:
DecodingException
-
encodeSigned
public static int encodeSigned(byte[] buf, int pos, int x)
-
newArrayDecoder
public static VarIntUtil.ArrayDecoder newArrayDecoder(byte[] buf)
-
decodeZigZag
public static int decodeZigZag(int x)
-
encodeZigZag
public static int encodeZigZag(int x)
-
writeSizeDelimitedString
public static void writeSizeDelimitedString(ByteBuffer bb, String s)
-
readSizeDelimitedString
public static String readSizeDelimitedString(ByteBuffer bb) throws DecodingException
- Throws:
DecodingException
-
encodeDeltaDeltaZigZag
public static int[] encodeDeltaDeltaZigZag(int[] x)
-
decodeDeltaDeltaZigZag
public static int[] decodeDeltaDeltaZigZag(int[] ddz)
-
encodeDeltaDeltaZigZag
public static int[] encodeDeltaDeltaZigZag(SortedIntArray a)
-
encodeDeltaDeltaZigZag
public static int[] encodeDeltaDeltaZigZag(IntArray a)
-
getEncodedSize
public static int getEncodedSize(int value)
get the number of bytes necessary to encode value- Parameters:
value
-- Returns:
-
encodeDeltaIntArray
public static byte[] encodeDeltaIntArray(IntArray s)
Encode an int array as a sequence of varints representing the deltas between the subsequent elements of the input array. It is best if the array is sorted in ascending order (because encoding negative numbers in varint is not efficient).- Parameters:
s
-- Returns:
-
decodeDeltaIntArray
public static IntArray decodeDeltaIntArray(byte[] buf)
The reverse of theencodeDeltaIntArray(IntArray)
method.- Parameters:
buf
-- Returns:
-
-