A function that return a boolean and receive three arguments: the currently read relation, the count and a reference the target instance.
Optional
opt: Partial<ControllerOptions>The property decorator function ran at runtime
Don't use this decorator to compare the current value to EOF. Use Until instead.
Use this decorator to make decisions based on the object currently interpreted.
class BinObject {
@Relation(PrimitiveSymbol.u8)
type: number
@Relation(PrimitiveSymbol.u8)
len: number
@Count('len')
@Relation(PrimitiveSymbol.u8)
blob: number[]
}
class BinProtocol {
@While((obj) => obj.type !== 0x00)
@Relation(BinObject)
objs: BinObject[]
}
Use the peek
option to not include the element that does not match the condition.
With this option the cursor will then be set back before the element was read and not
included in the resulting array.
class BinProtocol {
@While((elem) => elem !== 0x00, { peek: true })
@Relation(PrimitiveSymbol.u8)
array: number[]
@Match(0x00)
@Relation(PrimitiveSymbol.u8)
end_elem: number
}
While decorator continue the execution flow while the condition passed as a parameter is not met.
By default the relation that does not match the condition will be included in the result and the cursor will be set after that relation. This is the default behavior because that's what we expect most of the time.
To not include the relation that doesn't match the condition and move back the cursor to the position before it was read use the
peek
option.