Class Decoding


  • public class Decoding
    extends java.lang.Object
    Efficient schema-less binary decoding with support for variable length encoding.

    Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.

    Encodes numbers in little-endian order (least to most significant byte order) and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/) which is also used in Protocol Buffers.

    ```js // encoding step const encoder = encoding.createEncoder() encoding.writeVarUint(encoder, 256) encoding.writeVarString(encoder, 'Hello world!') const buf = encoding.toUint8Array(encoder) ```

    ```js // decoding step const decoder = decoding.createDecoder(buf) decoding.readVarUint(decoder) // => 256 decoding.readVarString(decoder) // => 'Hello world!' decoding.hasContent(decoder) // => false - all data is read ```

    • Method Detail

      • hasContent

        public static boolean hasContent​(Decoder decoder)
      • clone

        public static Decoder clone​(Decoder decoder)
        Clone a decoder instance. Optionally set a new position parameter.
        Parameters:
        decoder -
        Returns:
      • clone

        public static Decoder clone​(Decoder decoder,
                                    int newPos)
        Clone a decoder instance. Optionally set a new position parameter.
        Parameters:
        decoder -
        newPos -
        Returns:
      • readUint8Array

        public static Uint8Array readUint8Array​(Decoder decoder,
                                                int len)
      • readVarUint8Array

        public static Uint8Array readVarUint8Array​(Decoder decoder)
      • readTailAsUint8Array

        public static Uint8Array readTailAsUint8Array​(Decoder decoder)
      • skip8

        public static void skip8​(Decoder decoder)
      • readUint8

        public static int readUint8​(Decoder decoder)
      • readUint16

        public static int readUint16​(Decoder decoder)
      • readUint32

        public static int readUint32​(Decoder decoder)
      • readUint32BigEndian

        public static int readUint32BigEndian​(Decoder decoder)
      • peekUint8

        public static int peekUint8​(Decoder decoder)
      • peekUint16

        public static int peekUint16​(Decoder decoder)
      • peekUint32

        public static int peekUint32​(Decoder decoder)
      • readVarUint

        public static long readVarUint​(Decoder decoder)
        Read unsigned long (32bit) with variable length. K-Note: treat it as long value
      • readVarInt

        public static long readVarInt​(Decoder decoder)
      • peekVarUint

        public static long peekVarUint​(Decoder decoder)
      • peekVarInt

        public static long peekVarInt​(Decoder decoder)
      • readRealVarUint

        public static int readRealVarUint​(Decoder decoder)
        Read real unsigned int (31 bit, coz max Integer is 2^31 - 1) with variable length. 1/8th of the storage is used as encoding overhead. numbers < 2^7 is stored in one byte length numbers < 2^14 is stored in two byte length
      • readRealVarInt

        public static int readRealVarInt​(Decoder decoder)
        Read real signed int (32 bit, coz max Integer is 2^31) with variable length. 1/8th of the storage is used as encoding overhead. numbers < 2^7 is stored in one byte length numbers < 2^14 is stored in two byte length
        Parameters:
        decoder -
        Returns:
        An unsigned integer
      • peekRealVarUint

        public static int peekRealVarUint​(Decoder decoder)
        Look ahead and read varUint without incrementing position
        Parameters:
        decoder -
        Returns:
      • peekRealVarInt

        public static int peekRealVarInt​(Decoder decoder)
        Look ahead and read varUint without incrementing position
        Parameters:
        decoder -
      • readFloat32

        public static float readFloat32​(Decoder decoder)
      • readFloat64

        public static double readFloat64​(Decoder decoder)
      • readBigInt64

        public static long readBigInt64​(Decoder decoder)
      • readTerminatedUint8Array

        public static Uint8Array readTerminatedUint8Array​(Decoder decoder)
      • readTerminatedString

        public static java.lang.String readTerminatedString​(Decoder decoder)
      • peekVarString

        public static java.lang.String peekVarString​(Decoder decoder)
      • readVarString

        public static java.lang.String readVarString​(Decoder decoder)
      • readAny

        public static java.lang.Object readAny​(Decoder decoder)