Skip to content

Documentation / @andrew_l/tl-pack / Structure

Class: Structure<T> ​

Type Parameters ​

T ​

T extends Data = Data

Implements ​

Constructors ​

Constructor ​

new Structure<T>(value): Structure<T>

Parameters ​

value ​

T

Returns ​

Structure<T>

Properties ​

value ​

readonly value: T

The structured data value

Example ​

ts
const user = new UserStruct({ id: 1, name: 'Alice' });
console.log(user.value.name); // 'Alice'

Implementation of ​

Structure.value


estimatedSizeBytes ​

readonly static estimatedSizeBytes: number = -1


extension ​

readonly static extension: TLExtension


structures ​

readonly static structures: Constructor<any>[] = []

Methods ​

toBuffer() ​

toBuffer(options?): Uint8Array

Serializes the structure to a binary buffer

Parameters ​

options? ​

BinaryWriterOptions

Writer configuration options

Returns ​

Uint8Array

Serialized binary data

Examples ​

ts
const user = new User({ id: 1, name: 'Alice' });
const buffer = user.toBuffer();
console.log(buffer.length); // Size in bytes
ts
// With custom writer options
const buffer = user.toBuffer({
  initialSize: 1024,
  growthFactor: 2
});

Implementation of ​

Structure.toBuffer


fromBuffer() ​

static fromBuffer(buffer, options): Data

Parameters ​

buffer ​

Uint8Array

options ​

BinaryReaderOptions = {}

Returns ​

Data