Options
All
  • Public
  • Public/Protected
  • All
Menu

Contain a sequence of bit fields as an unsigned integer.

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

This is a container element; within it there are BitField instances that provide the extracted properties. The container simply defines the aggregate representation and its bit ordering. The representation is an object containing properties with numeric or Boolean values.

BitFields are added with the {@link BitStructure#addField|addField} and {@link BitStructure#addBoolean|addBoolean} methods.

param word

initializer for {@link BitStructure#word|word}. The parameter must be an instance of UInt (or UIntBE) that is no more than 4 bytes wide.

param [msb]

true if the bit numbering starts at the most significant bit of the containing word; false (default) if it starts at the least significant bit of the containing word. If the parameter at this position is a string and property is undefined the value of this argument will instead be used as the value of property.

param [property]

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

Hierarchy

Index

Constructors

constructor

Properties

_packedGetValue

_packedGetValue: () => number

Type declaration

    • (): number
    • Returns number

_packedSetValue

_packedSetValue: (v: number) => BitStructure

Type declaration

Optional boundConstructor_

boundConstructor_?: any

fields

fields: BitField[]

msb

msb: boolean

Optional property

property?: string

span

span: number

word

word: UInt | UIntBE

Methods

addBoolean

  • addBoolean(property: string): Boolean
  • As with {@link BitStructure#addField|addField} for single-bit fields with boolean value representation.

    Parameters

    • property: string

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

    Returns Boolean

addField

  • addField(bits: number, property: string): BitField
  • Register a new bitfield with a containing bit structure. The resulting bitfield is returned.

    Parameters

    • bits: number

      initializer for {@link BitField#bits|bits}.

    • property: string

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

    Returns BitField

decode

encode

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

    If src is missing a property for a member with a defined {@link Layout#property|property} the corresponding region of the packed value is left unmodified. Unused bits are also left unmodified.

    Parameters

    Returns number

fieldFor

  • fieldFor(property: string): undefined | BitField
  • Get access to the bit field for a given property.

    Parameters

    • property: string

      the bit field of interest.

    Returns undefined | BitField

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

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 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 BitStructure

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

Generated using TypeDoc