Documentation / @andrew_l/tl-pack / Structure
Class: Structure<T> ​
Type Parameters ​
T ​
T extends Data = Data
Implements ​
Structure<T>
Constructors ​
Constructor ​
new Structure<
T>(value):Structure<T>
Parameters ​
value ​
T
Returns ​
Structure<T>
Properties ​
value ​
readonlyvalue:T
The structured data value
Example ​
ts
const user = new UserStruct({ id: 1, name: 'Alice' });
console.log(user.value.name); // 'Alice'Implementation of ​
estimatedSizeBytes ​
readonlystaticestimatedSizeBytes:number=-1
extension ​
readonlystaticextension:TLExtension
structures ​
readonlystaticstructures:Constructor<any>[] =[]
Methods ​
toBuffer() ​
toBuffer(
options?):Uint8Array
Serializes the structure to a binary buffer
Parameters ​
options? ​
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 bytests
// With custom writer options
const buffer = user.toBuffer({
initialSize: 1024,
growthFactor: 2
});Implementation of ​
fromBuffer() ​
staticfromBuffer(buffer,options):Data
Parameters ​
buffer ​
Uint8Array
options ​
BinaryReaderOptions = {}
Returns ​
Data