Options
All
  • Public
  • Public/Protected
  • All
Menu

Base class for layout objects.

NOTE This is an abstract base class; you can create instances if it amuses you, but they won't support the {@link Layout#encode|encode} or {@link Layout#decode|decode} functions.

param span

Initializer for {@link Layout#span|span}. The parameter must be an integer; a negative value signifies that the span is {@link Layout#getSpan|value-specific}.

param [property]

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

abstract

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

  • new Layout<T>(span: number, property?: string): Layout<T>
  • Type parameters

    • T

    Parameters

    • span: number
    • Optional property: string

    Returns Layout<T>

Properties

Optional boundConstructor_

boundConstructor_?: any

Optional property

property?: string

span

span: number

Methods

Abstract decode

  • decode(b: Uint8Array, offset?: number): T
  • Decode from a Uint8Array into a JavaScript value.

    abstract

    Parameters

    • b: Uint8Array

      the buffer from which encoded data is read.

    • Optional offset: number

    Returns T

    • the value of the decoded data.

Abstract encode

  • encode(src: T, b: Uint8Array, offset?: number): number
  • Encode a JavaScript value into a Uint8Array.

    abstract

    Parameters

    • src: T

      the value to be encoded into the buffer. The type accepted depends on the (sub-)type of Layout.

    • b: Uint8Array

      the buffer into which encoded data will be written.

    • Optional offset: number

    Returns number

    • the number of bytes encoded, including the space skipped for internal padding, but excluding data such as {@link Sequence#count|lengths} when stored externally. This is the adjustment to offset producing the offset where data for the next layout would be written.

fromArray

  • Create an object from layout properties and an array of values.

    NOTE This function returns undefined if invoked on a layout that does not return its value as an Object. Objects are returned for things that are a Structure, which includes variant layouts if they are structures, and excludes Unions. If you want this feature for a union you must use getVariant to select the desired layout.

    Parameters

    • values: any[]

      an array of values that correspond to the default order for properties. As with {@link Layout#decode|decode} layout elements that have no property name are skipped when iterating over the array values. Only the top-level properties are assigned; arguments are not assigned to properties of contained layouts. Any unused values are ignored.

    Returns undefined | LayoutObject

getSpan

  • getSpan(b?: Uint8Array, offset?: number): number
  • Calculate the span of a specific instance of a layout.

    throws

    {RangeError} - if the length of the value cannot be determined.

    Parameters

    • Optional b: Uint8Array

      the buffer that contains an encoded instance.

    • Optional offset: number

    Returns number

    • the number of bytes covered by the layout instance. If this method is not overridden in a subclass the definition-time constant {@link Layout#span|span} will be returned.

makeDestinationObject

replicate

  • replicate(property: string): Layout<T>
  • 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 Layout<T>

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

Generated using TypeDoc