Skip to content

Documentation / @andrew_l/tl-pack / BinaryReader

Class: BinaryReader ​

Constructors ​

Constructor ​

new BinaryReader(data, __namedParameters): BinaryReader

Small utility class to read binary data.

Parameters ​

data ​

Uint8Array

__namedParameters ​

BinaryReaderOptions = {}

Returns ​

BinaryReader

Properties ​

length ​

length: number


offset ​

offset: number

Methods ​

assertConstructor() ​

assertConstructor(constructorId): void

Parameters ​

constructorId ​

CORE_TYPES

Returns ​

void


assertRead() ​

assertRead(length): void

Throws error if provided length cannot be read from buffer

Parameters ​

length ​

number

Returns ​

void


decode() ​

decode<T>(value): T

Type Parameters ​

T ​

T = any

Parameters ​

value ​

Uint8Array

Returns ​

T


getBuffer() ​

getBuffer(): Uint8Array

Gets the byte array representing the current buffer as a whole.

Returns ​

Uint8Array


getDictionaryValue() ​

getDictionaryValue(index): null | string

Parameters ​

index ​

number

Returns ​

null | string


readAll() ​

readAll(): any[]

Returns ​

any[]


readBool() ​

readBool(): boolean

Reads a boolean value.

Returns ​

boolean


readByte() ​

readByte(): number

Returns ​

number


readBytes() ​

readBytes(): Uint8Array

Returns ​

Uint8Array


readChecksum() ​

readChecksum(checkConstructor): void

Parameters ​

checkConstructor ​

boolean = true

Returns ​

void


readDate() ​

readDate(): Date

Reads and converts Unix time into a Javascript {Date} object.

Returns ​

Date


readDictionary() ​

readDictionary(): null | string

Returns ​

null | string


readDouble() ​

readDouble(): number

Reads a real floating point (8 bytes) value.

Returns ​

number


readFloat() ​

readFloat(): number

Reads a real floating point (4 bytes) value.

Returns ​

number


readGzip() ​

readGzip(): any

Returns ​

any


readInt16() ​

readInt16(signed): number

Parameters ​

signed ​

boolean = true

Returns ​

number


readInt32() ​

readInt32(signed): number

Parameters ​

signed ​

boolean = true

Returns ​

number


readInt64() ​

readInt64(signed): bigint

Parameters ​

signed ​

boolean = true

Returns ​

bigint


readInt8() ​

readInt8(signed): number

Parameters ​

signed ​

boolean = true

Returns ​

number


readLength() ​

readLength(): number

Returns ​

number


readMap() ​

readMap(checkConstructor): Record<string, any>

Parameters ​

checkConstructor ​

boolean = true

Returns ​

Record<string, any>


readNull() ​

readNull(): null

Returns ​

null


readObject() ​

readObject(): any

Reads a object.

Returns ​

any


readObjectGzip() ​

readObjectGzip(): any

Returns ​

any


readString() ​

readString(): string

Reads encoded string.

Returns ​

string


readStructure() ​

readStructure<T>(checkConstructor): T

Type Parameters ​

T ​

T extends Data = Data

Parameters ​

checkConstructor ​

boolean = true

Returns ​

T


readVector() ​

readVector<T>(checkConstructor): T[]

Reads a vector (a list) of objects.

Type Parameters ​

T ​

T = any

Parameters ​

checkConstructor ​

boolean = true

Returns ​

T[]


readVectorDynamic() ​

readVectorDynamic<T>(checkConstructor): T[]

Reads a vector (a list) of objects.

Type Parameters ​

T ​

T

Parameters ​

checkConstructor ​

boolean = true

Returns ​

T[]


reset() ​

reset(data?): void

Sets the current buffer and reset initial state.

Parameters ​

data? ​

Uint8Array<ArrayBufferLike>

Returns ​

void


seek() ​

seek(offset): void

Seeks the stream position given an offset from the current position. The offset may be negative.

Parameters ​

offset ​

number

Returns ​

void


setPosition() ​

setPosition(position): void

Sets the current position on the stream.

Parameters ​

position ​

number

Returns ​

void


tellPosition() ​

tellPosition(): number

Tells the current position on the stream.

Returns ​

number