Options
All
  • Public
  • Public/Protected
  • All
Menu

Represent a contiguous sequence of arbitrary layout elements as an Object.

Factory: {@link module:Layout.struct|struct}

NOTE The {@link Layout#span|span} of the structure is variable if any layout in {@link Structure#fields|fields} has a variable span. When {@link Layout#encode|encoding} we must have a value for all variable-length fields, or we wouldn't be able to figure out how much space to use for storage. We can only identify the value for a field when it has a {@link Layout#property|property}. As such, although a structure may contain both unnamed fields and variable-length fields, it cannot contain an unnamed variable-length field.

param fields

initializer for {@link Structure#fields|fields}. An error is raised if this contains a variable-length field for which a {@link Layout#property|property} is not defined.

param [property]

initializer for {@link Layout#property|property}.

param [decodePrefixes]

initializer for {@link Structure#decodePrefixes|property}.

throws

{Error} - if fields contains an unnamed variable-length layout.

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

  • new Structure<T>(fields: Layout<T[keyof T]>[], property?: string, decodePrefixes?: boolean): Structure<T>

Properties

Optional boundConstructor_

boundConstructor_?: any

decodePrefixes

decodePrefixes: boolean

fields

fields: Layout<T[keyof T]>[]

Optional property

property?: string

span

span: number

Methods

decode

  • decode(b: Uint8Array, offset?: number): T

encode

  • encode(src: T, b: Uint8Array, offset?: number): number
  • Implement {@link Layout#encode|encode} for Structure.

    If src is missing a property for a member with a defined {@link Layout#property|property} the corresponding region of the buffer is left unmodified.

    Parameters

    • src: T
    • b: Uint8Array
    • offset: number = 0

    Returns number

fromArray

getSpan

  • getSpan(b: Uint8Array, offset?: number): number

layoutFor

  • Get access to the layout of a given property.

    Parameters

    • property: string

      the structure member of interest.

    Returns undefined | Layout<LayoutObject>

    • the layout associated with property, or undefined if there is no such property.

makeDestinationObject

offsetOf

  • offsetOf(property: string): undefined | number
  • Get the offset of a structure member.

    Parameters

    • property: string

      the structure member of interest.

    Returns undefined | number

    • the offset in bytes to the start of property within the structure, or undefined if property is not a field within the structure. If the property is a member but follows a variable-length structure member a negative number will be returned.

replicate

  • Replicate the layout using a new property.

    This function must be used to get a structurally-equivalent layout with a different name since all Layout instances are immutable.

    NOTE This is a shallow copy. All fields except {@link Layout#property|property} are strictly equal to the origin layout.

    Parameters

    • property: string

      the value for {@link Layout#property|property} in the replica.

    Returns Structure<T>

    • the copy with {@link Layout#property|property} set to property.

Generated using TypeDoc