The fixed size or a property path that defines the size dynamically.
Optional
opt: Partial<ControllerOptions>Optional configuration.
The property decorator function.
In the following example, the @Size
decorator is used to read
a specific number of bytes from a binary data stream into the decorated
property.
class Protocol {
@Size(16)
@Relation(PrimitiveSymbol.u16)
data: number[] // Will contain 8 numbers
}
You can also use a string representing a property path to define the size dynamically.
class Protocol {
_size: number = 16
@Size('_size')
@Relation(PrimitiveSymbol.u16)
data: number[]
}
@Size
decorator reads data until the specified size in bytes is met.This decorator is useful when you need to process a fixed-size amount of data, either in bytes or based on another property that dynamically defines the size in bytes to read.
Binary format definitions often specify the size of sections in bytes. These sections can have components of dynamic size, making it difficult to deduce the exact number of components.