Package jadex.binary

Class VarInt


  • public class VarInt
    extends java.lang.Object
    Class 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 long decode​(byte[] varint)
      Decodes a VarInt.
      static long decode​(byte[] varint, int offset)
      Decodes a VarInt.
      static long decodeWithKnownSize​(byte[] varint, int offset, byte extsize)
      Decodes a VarInt when the extension size is known.
      static byte[] encode​(long val)
      Encodes a VarInt.
      static void encode​(long val, byte[] buffer, int offset, int size)
      Encodes a VarInt and saves it in a buffer at the given offset.
      static int getEncodedSize​(long val)
      Determines the encoded size of a value.
      static byte getExtensionSize​(byte firstbyte)
      Returns the number of bytes used for this number past the first byte.
      static byte getExtensionSize​(byte[] varint, int offset)
      Returns the number of bytes used for this number past the first byte.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VarInt

        public VarInt()
    • 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.