Class Decoding
- java.lang.Object
-
- io.keikai.doc.collab.lib0.Decoding
-
public class Decoding extends java.lang.ObjectEfficient 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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Decoderclone(Decoder decoder)Clone a decoder instance.static Decoderclone(Decoder decoder, int newPos)Clone a decoder instance.static DecodercreateDecoder(Uint8Array uint8Array)static booleanhasContent(Decoder decoder)static intpeekRealVarInt(Decoder decoder)Look ahead and read varUint without incrementing positionstatic intpeekRealVarUint(Decoder decoder)Look ahead and read varUint without incrementing positionstatic intpeekUint16(Decoder decoder)static intpeekUint32(Decoder decoder)static intpeekUint8(Decoder decoder)static longpeekVarInt(Decoder decoder)static java.lang.StringpeekVarString(Decoder decoder)static longpeekVarUint(Decoder decoder)static java.lang.ObjectreadAny(Decoder decoder)static longreadBigInt64(Decoder decoder)static floatreadFloat32(Decoder decoder)static doublereadFloat64(Decoder decoder)static intreadRealVarInt(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.static intreadRealVarUint(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.static Uint8ArrayreadTailAsUint8Array(Decoder decoder)static java.lang.StringreadTerminatedString(Decoder decoder)static Uint8ArrayreadTerminatedUint8Array(Decoder decoder)static intreadUint16(Decoder decoder)static intreadUint32(Decoder decoder)static intreadUint32BigEndian(Decoder decoder)static intreadUint8(Decoder decoder)static Uint8ArrayreadUint8Array(Decoder decoder, int len)static longreadVarInt(Decoder decoder)static java.lang.StringreadVarString(Decoder decoder)static longreadVarUint(Decoder decoder)Read unsigned long (32bit) with variable length.static Uint8ArrayreadVarUint8Array(Decoder decoder)static voidskip8(Decoder decoder)
-
-
-
Method Detail
-
createDecoder
public static Decoder createDecoder(Uint8Array uint8Array)
-
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)
-
-