Optional
size: number | StringFormattedRecursiveKeyOf<This, Args> | ((instance: This, cursor: Cursor) => number)The size to move the cursor to before reading or writing the decorated property. It can be:
Optional
opt: Partial<PrePostOptions>Optional configution.
The class or property decorator function.
In the following example the structure of the bitfield is only known based
on the value of the most significant bit. For this I use @Peek
to check the
content of the next value and then I properly read it in the correct form.
@EnsureSize('_size')
class Block {
@NullTerminatedString()
@Relation(PrimitiveSymbol.char)
content: string
constructor(public _size: number) {}
}
class Protocol {
@Relation(PrimitiveSymbol.u16)
block_size: number
@Relation(PrimitiveSymbol.u32)
block_count: number
@Count('block_count')
@Relation(Block, 'block_size')
blocks: Block[]
}
@EnsureSize
decorator force the decorated property to meet a size constraint. If that size is not met the cursor will be moved.