• @Match decorator

    Define a decorator that gives the proper information to verify the content of a field. Binary files will often use magic number to validate the structure of the file.

    Type Parameters

    • This
    • Value

    Parameters

    Returns DecoratorType<This, Value | Value[]>

    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)
    @Relation(PrimitiveSymbol.char)
    magic: string,
    }