• @Offset decorator define the address where the cursor should move to continue the next reading or writing operation.

    This is useful when dealing with binary file format with sections of data located at specific address.

    Type Parameters

    • This extends object

      The type of the class the decorator is applied to.

    • Args extends string

    Parameters

    • offset: number | StringFormattedRecursiveKeyOf<This, Args> | ((instance: This, cursor: Cursor) => number)
    • Optionalopt: Partial<PrePostOptions>

      Optional configution.

    Returns ClassAndPropertyDecoratorType<This>

    The class or property decorator function.

    Some binary file format will define arbitrary area where part its definition is stored based on an address referenced somewhere else.

    In the following example, the @Offset decorator moves the cursor to an address defined in the 'header.address' property and then read null-terminated strings until the enf of the file.

    class ProtocolHeader {
    @Relation(PrimitiveSymbol.u32)
    address: number
    }

    class Protocol {
    @Relation(ProtocolHeader)
    header: ProtocolHeader

    @Offset('header.address') // Move the cursor the the address in the header
    @Until(EOF) // Keep reading strings until the end of the file
    @NullTerminatedString() // Read a null-terminated string
    area: string[]
    }