• @Count decorator defines a variable-length array based on a value you pass as argument.

    This decorator is useful for dynamic parsing of arrays when the length is not fixed but can be derived from another property.

    Type Parameters

    • This extends object

      The type of the class the decorator is applied to.

    • Value

      The type of the decorated property.

    • Args extends string

    Parameters

    • arg: NumberOrRecursiveKey<This, Args>

      The number of time to read the target property or a string referring to a property that specifies the array length.

    • Optionalopt: Partial<ControllerOptions>

      Optional configuration.

    Returns DecoratorType<This, Value>

    The property decorator function.

    In the following example, the @Count decorator is used to define an array (vec) whose length is determined by the value of another property (len):

    class Protocol {
    @Relation(PrimitiveSymbol.u8)
    len: Number

    @Count('len')
    @Relation(PrimitiveSymbol.u8)
    vec: Number
    }