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

BinaryEncoder

A BinaryEncoder handles the encoding to an ArrayBuffer.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

data: *[]

public get

length: *

The current length of the encoded data.

public get

pos: *

The current write pointer (the same as length).

Method Summary

Public Methods
public

Create an ArrayBuffer.

public

setUint16(pos: number, num: number)

Write two bytes as an unsigned integer at a specific location.

public

setUint32(pos: number, num: number)

Write two bytes as an unsigned integer at a specific location.

public

setUint8(pos: number, num: number)

Write one byte as an unsigned Integer at a specific location.

public

writeID(id: ID)

Write an ID at the current position.

public

Write two bytes as an unsigned integer.

public

Write two bytes as an unsigned integer

public

Write one byte as an unsigned integer.

public

Write a variable length string.

public

Write a variable length unsigned integer.

Public Constructors

public constructor() source

Public Members

public data: *[] source

public get length: * source

The current length of the encoded data.

public get pos: * source

The current write pointer (the same as length).

Public Methods

public createBuffer(): Uint8Array source

Create an ArrayBuffer.

Return:

Uint8Array

A Uint8Array that represents the written data.

public setUint16(pos: number, num: number) source

Write two bytes as an unsigned integer at a specific location.

Params:

NameTypeAttributeDescription
pos number

The location where the data will be written.

num number

The number that is to be encoded.

public setUint32(pos: number, num: number) source

Write two bytes as an unsigned integer at a specific location.

Params:

NameTypeAttributeDescription
pos number

The location where the data will be written.

num number

The number that is to be encoded.

public setUint8(pos: number, num: number) source

Write one byte as an unsigned Integer at a specific location.

Params:

NameTypeAttributeDescription
pos number

The location where the data will be written.

num number

The number that is to be encoded.

public writeID(id: ID) source

Write an ID at the current position.

Params:

NameTypeAttributeDescription
id ID

The ID that is to be written.

public writeUint16(num: number) source

Write two bytes as an unsigned integer.

Params:

NameTypeAttributeDescription
num number

The number that is to be encoded.

public writeUint32(num: number) source

Write two bytes as an unsigned integer

Params:

NameTypeAttributeDescription
num number

The number that is to be encoded.

public writeUint8(num: number) source

Write one byte as an unsigned integer.

Params:

NameTypeAttributeDescription
num number

The number that is to be encoded.

public writeVarString(str: String) source

Write a variable length string.

Params:

NameTypeAttributeDescription
str String

The string that is to be encoded.

public writeVarUint(num: number) source

Write a variable length unsigned integer.

Params:

NameTypeAttributeDescription
num number

The number that is to be encoded.