• @Match decorator validates that the value of the decorated property matches a specified value.

    This is commonly used to enforce "magic numbers" or other fixed values in binary formats that help verify file structure or integrity.

    Type Parameters

    • This

      The type of the class the decorator is applied to.

    • Value

      The type of the decorated property.

    Parameters

    • matchingValue: Value | Value[]

      The value or array of values to match against the decorated property value.

    • Optionalopt: Partial<ValidatorOptions>

      Optional configuration.

    Returns DecoratorType<This, Value | Value[]>

    The property decorator function.

    The most simple use case is to compare to a number.

    class Header {
    @Match(0xFE)
    @Relation(PrimitiveSymbol.char)
    magic: number,
    }

    The @Match decorator can also be used to match arrays.

    class Header {
    @Match([0xBE, 0xEF])
    @Count(2)
    @Relation(PrimitiveSymbol.char)
    magic: number[],
    }

    Or to check the value is one of the value from an array passed as a parameter.

    class Header {
    @Match([1, 8, 16])
    @Relation(PrimitiveSymbol.u8)
    magic: number,
    }

    Or an ASCII string.

    class Header {
    @Match('.PNG')
    @Count(4, { targetType: String })
    @Relation(PrimitiveSymbol.char)
    magic: string,
    }