Skip to main content

Class: BinaryEncoder

A class that provides methods for encoding binary data.

Constructors

new BinaryEncoder()

new BinaryEncoder(writer: BufferWriter): BinaryEncoder

Creates a new binary encoder.

Parameters

ParameterTypeDescription

writer

BufferWriter

The buffer writer

Returns

BinaryEncoder

Defined in

binary-encoder.ts:19

Methods

create()

static create(byteLength: number, options: Partial<ResizeOptions>): BinaryEncoder

Creates a new binary encoder from a buffer writer.

Parameters

ParameterTypeDescription

byteLength

number

The initial byte length of the buffer

options

Partial<ResizeOptions>

BufferWriter options

Returns

BinaryEncoder

The new binary encoder instance

Throws

RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size

Defined in

binary-encoder.ts:30


reset()

reset(): void

Resets the buffer writer.

Returns

void

Defined in

binary-encoder.ts:37


encode()

encode<T>(schema: T, value: InferBaseType<T>): void

Encodes a value to the buffer.

Type Parameters

Type Parameter

T extends BaseType<unknown>

Parameters

ParameterTypeDescription

schema

T

The schema of the value to encode

value

InferBaseType<T>

The value to encode

Returns

void

Throws

RangeError if the value is invalid or the value size is larger than the buffer maximum size

Defined in

binary-encoder.ts:47


commit()

commit(): ArrayBuffer

Commits the buffer as an ArrayBuffer.

Returns

ArrayBuffer

The ArrayBuffer containing the encoded data

Defined in

binary-encoder.ts:55


commitUint8Array()

commitUint8Array(): Uint8Array

Commits the buffer as an Uint8Array.

Returns

Uint8Array

The Uint8Array containing the encoded data

Defined in

binary-encoder.ts:63


toUint8Array()

toUint8Array(): Uint8Array

Converts the buffer to an Uint8Array.

Returns

Uint8Array

The Uint8Array containing the encoded data

Defined in

binary-encoder.ts:71

Properties

PropertyModifierTypeDescriptionDefined in
writerreadonlyBufferWriterThe buffer writer.binary-encoder.ts:13