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 classVarIntUtil.ArrayDecoderdecodes an array of varintsstatic classVarIntUtil.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 IntArraydecodeDeltaIntArray(byte[] buf)The reverse of theencodeDeltaIntArray(IntArray)method.static intdecodeZigZag(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 intencodeSigned(byte[] buf, int pos, int x)static intencodeZigZag(int x)static intgetEncodedSize(int value)get the number of bytes necessary to encode valuestatic VarIntUtil.ArrayDecodernewArrayDecoder(byte[] buf)static intreadSignedVarInt32(ByteBuffer bb)static StringreadSizeDelimitedString(ByteBuffer bb)static intreadVarInt32(ByteBuffer bb)static longreadVarInt64(ByteBuffer bb)static voidwriteSignedVarint32(ByteBuffer bb, int x)static voidwriteSizeDelimitedString(ByteBuffer bb, String s)static intwriteVarInt32(byte[] buf, int pos, int x)Encodes x as varint in the buffer at position pos and returns the new positionstatic voidwriteVarInt32(ByteBuffer bb, int x)static voidwriteVarInt64(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:
-
-