Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StructConstructor<T, ClassName>

A ready-made constructor with static methods for a custom structure

Type parameters

  • T

  • ClassName: string

Hierarchy

  • StructConstructor

Index

Constructors

  • new StructConstructor(): StructInstance<T, ClassName>
  • new StructConstructor(size: number): StructInstance<T, ClassName>
  • new StructConstructor(raw: Buffer, clone?: boolean): StructInstance<T, ClassName>
  • new StructConstructor(array: number[]): StructInstance<T, ClassName>
  • Structure constructor. Allocates a new Buffer of baseSize bytes and uses that as the underlying buffer Each instantiated instance has a hidden field $raw. Use the static method YourStructureName.raw(instance) to access the underlying buffer.

    Returns StructInstance<T, ClassName>

    fake field __struct is only used as a type guard and should not be used

  • Structure constructor. Allocates a new Buffer of size bytes and uses that as the underlying buffer

    Parameters

    • size: number

      Size must be at least baseSize

    Returns StructInstance<T, ClassName>

    fake field __struct is only used as a type guard and should not be used

  • Structure constructor.

    Parameters

    • raw: Buffer

      use this buffer as an underlying. Buffer length must be at least baseSize

    • Optional clone: boolean

      create a copy of raw to store changes

    Returns StructInstance<T, ClassName>

    fake field __struct is only used as a type guard and should not be used

  • Structure constructor. Allocates a new Buffer using an array of bytes in the range 0 – 255 and uses that as the underlying buffer

    Parameters

    • array: number[]

    Returns StructInstance<T, ClassName>

    fake field __struct is only used as a type guard and should not be used

Properties

baseSize: number

The minimum base size of the structure.

prototype: T & { toJSON: any }

Prototype

Methods

  • getOffsetOf(name: keyof T): number
  • Returns the offset in bytes from the beginning of the structure of the specified field

    Parameters

    • name: keyof T

      The field name

    Returns number

  • getOffsets(): Record<keyof T, number>
  • Returns an object where each property stores its offset

    Returns Record<keyof T, number>

  • raw(instance: StructInstance<T, ClassName>): Buffer
  • raw(instance: { [ P in string | number | symbol]: DeepWriteable<ReplaceRecursivelyNot<ReplaceRecursively<OmitTypeRecursively<T, undefined | Function>, bigint | Date, string>, null | string | number | boolean, unknown>>[P] }): undefined | Buffer
  • Returns the underlying buffer if the object is a typed structure

    Parameters

    • instance: StructInstance<T, ClassName>

      the object from which to get the underlying buffer

    Returns Buffer

  • Parameters

    • instance: { [ P in string | number | symbol]: DeepWriteable<ReplaceRecursivelyNot<ReplaceRecursively<OmitTypeRecursively<T, undefined | Function>, bigint | Date, string>, null | string | number | boolean, unknown>>[P] }

    Returns undefined | Buffer

  • swap(instance: StructInstance<T, ClassName>, name: keyof T): Buffer
  • swaps the byte order to perform a fast in-place conversion between little-endian and big-endian

    Parameters

    • instance: StructInstance<T, ClassName>

      the object

    • name: keyof T

      property name

    Returns Buffer

Generated using TypeDoc