Documentation / @andrew_l/tl-pack / Structure / Constructor
Interface: Constructor<T>
Base Structure class for binary serialization with type safety
Examples
ts
// Direct usage (not recommended, use defineStructure instead)
class CustomStruct extends Structure<{id: number, name: string}> {
// Custom implementation
}ts
// Typical usage through defineStructure
const MyStruct = defineStructure({
name: 'MyStruct',
version: 1,
properties: { id: { type: Number, required: true } }
});
const instance = new MyStruct({ id: 42 });
console.log(instance.value.id); // 42Type Parameters
T
T extends Data = any
Data type extending Data interface
Constructors
Constructor
new Constructor(
value):Structure<T>
Creates a new Structure instance
Parameters
value
T
The data to structure
Returns
Structure<T>
Example
ts
const data = { id: 123, name: 'Test' };
const struct = new MyStructure(data);Properties
estimatedSizeBytes
readonlyestimatedSizeBytes:number
Estimated size of bytes
extension
readonlyextension:TLExtension
Structure extension defining encoding/decoding behavior
structures
readonlystructures:Constructor<any>[]
Nested structures defining encoding/decoding behavior
Methods
fromBuffer()
fromBuffer(
buffer,options?):T
Deserializes a structure from a binary buffer
Parameters
buffer
Uint8Array
Binary data to deserialize
options?
Reader configuration options
Returns
T
Deserialized structure data
Example
ts
const buffer = user.toBuffer();
const restored = User.fromBuffer(buffer);
console.log(restored.id); // Original user ID