Optional
args: RelationParameters<This, Args>The property decorator function.
In the following example let's imagine the DEFINITION
object is actually
bigger than it is.
The @Select
decorator is used to pick the Primitive type of the
decorated property with the help of a combination of key found in the
Protocol
instance.
const DEFINITION = {
0: {
1: SubProtocol,
...
},
...
}
class SubProtocol {
}
class Protocol {
@Relation(PrimitiveType.u8)
foo: number
@Relation(PrimitiveType.u8)
bar: number
@Select(_ => DEFINITION[_.foo][_.bar])
sub_protocol
}
@Select
decorator works similarly to the Choice decorator but the function passed as argument directly returns the Primitive instead of declaring the condition.The
@Select
decorator should be used for a small subset of special cases, most of the time the@Choice
decorator fits the job perfectly. But sometimes certain format definitions have a long list of sub type you need match to a set of value and defining every available options in the@Choice
decorator is verbose.At the end of the day use the one you feel make your definition easier to read in your declaration, both are valid options.