Creates the struct and optionally fills it with data. If data is provided, the length of the provided buffer needs to match the structure length.
This method is stripped from type on struct build()
.
Optional
data: Buffer<ArrayBufferLike>Sets default data to initialize empty struct with.
Data to initialize empty struct with.
Returns total length of the struct. Struct length is always fixed and configured
by calls to member()
methods.
Adds a numeric member of uint8
, uint16
or uint32
type.
Internal representation is always little endian.
This method is stripped from type on struct build()
.
Underlying data type (uint8, uint16 or uint32).
Name of the struct member.
Adds another struct type as a struct member. Struct factory is provided as a child struct definition source.
This method is stripped from type on struct build()
.
Underlying data type. Must be struct
.
Name of the struct member.
Factory providing the wanted child struct.
Sets byte to use for padding.
Byte to use for padding
Returns raw contents of the structure as a sliced Buffer. Mutations to the returned buffer will not be reflected within struct.
Returns structure contents in JS object format.
Static
newCreates an empty struct. Further calls to member()
and method()
functions will form the structure.
Finally call to build()
will type the resulting structure appropriately without internal functions.
Struct provides a builder-like interface to create Buffer-based memory structures for read/write interfacing with data structures from adapters.