Home Reference Source
import BinaryDecoder from 'yjs/src/Util/Binary/Decoder.js'
public class | source

BinaryDecoder

A BinaryDecoder handles the decoding of an ArrayBuffer.

Constructor Summary

Public Constructor
public

constructor(buffer: Uint8Array | Buffer)

Member Summary

Public Members
public get

length: *

Number of bytes.

public
public

Method Summary

Public Methods
public

clone(newPos: *): *

Clone this decoder instance.

public

Look ahead without incrementing position.

public

Look ahead and read varString without incrementing position

public

readID(): *

Read ID.

public

Read 4 bytes as unsigned integer.

public

readUint8(): *

Read one byte as unsigned integer.

public

Read string of variable length

  • varUint is used to store the length of the string
public

Read unsigned integer (32bit) with variable length.

public

skip8()

Skip one byte, jump to the next position.

Public Constructors

public constructor(buffer: Uint8Array | Buffer) source

Params:

NameTypeAttributeDescription
buffer Uint8Array | Buffer

The binary data that this instance decodes.

Public Members

public get length: * source

Number of bytes.

public pos: number source

public uint8arr: * source

Public Methods

public clone(newPos: *): * source

Clone this decoder instance. Optionally set a new position parameter.

Params:

NameTypeAttributeDescription
newPos *
  • optional

Return:

*

public peekUint8(): number source

Look ahead without incrementing position. to the next byte and read it as unsigned integer.

Return:

number

An unsigned integer.

public peekVarString(): * source

Look ahead and read varString without incrementing position

Return:

*

public readID(): * source

Read ID.

  • If first varUint read is 0xFFFFFF a RootID is returned.
  • Otherwise an ID is returned.

Return:

*

ID

public readUint32(): number source

Read 4 bytes as unsigned integer.

Return:

number

An unsigned integer.

public readUint8(): * source

Read one byte as unsigned integer.

Return:

*

public readVarString(): String source

Read string of variable length

  • varUint is used to store the length of the string

Return:

String

The read String.

public readVarUint(): number source

Read unsigned integer (32bit) with variable length. 1/8th of the storage is used as encoding overhead.

  • numbers < 2^7 is stored in one byte.
  • numbers < 2^14 is stored in two bytes.

Return:

number

An unsigned integer.

public skip8() source

Skip one byte, jump to the next position.