Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FixableBeetStruct<Class, Args>

Configures a class or any JavaScript object type for de/serialization aka read/write. Not all fields of that class have to be of fixed size. If none of the fields requires a FixableBeet use the BeetStruct instead.

Type Parameters

  • Class

    the type to produce when deserializing

  • Args = Partial<Class>

    contains all fields, is typically a subset of Class and is used to construct an instance of it

Hierarchy

Implements

Index

Constructors

  • new FixableBeetStruct<Class, Args>(fields: BeetField<Args, any>[], construct: ((args: Args) => Class), description?: string): FixableBeetStruct<Class, Args>
  • Creates an instance of the FixableBeetStruct.

    Type Parameters

    • Class

    • Args = Partial<Class>

    Parameters

    • fields: BeetField<Args, any>[]

      fixed or fixable de/serializers for each field of the {@link Class}

    • construct: ((args: Args) => Class)

      the function that creates an instance of {@link Class} from the args

        • (args: Args): Class
        • Parameters

          • args: Args

          Returns Class

    • description: string = FixableBeetStruct.description

      identifies this struct for diagnostics/debugging purposes

    Returns FixableBeetStruct<Class, Args>

Properties

description: string = FixableBeetStruct.description
fields: BeetField<Args, any>[]
TYPE: string = 'FixableBeetStruct'
description: string = 'FixableBeetStruct'

Accessors

  • get type(): string

Methods

  • deserialize(buffer: Buffer, offset?: number): [Class, number]
  • Deserializes an instance of the Class from the provided buffer starting to read at the provided offset.

    Parameters

    • buffer: Buffer
    • offset: number = 0

    Returns [Class, number]

    [instance of Class, offset into buffer after deserialization completed]

  • serialize(instance: Args, byteSize?: number): [Buffer, number]
  • Serializes the provided instance into a new {@link Buffer}

    NOTE: that the instance is traversed and each of its fields accessed twice, once to derive a fixed size BeetStruct and then use it to serialize the instance. Therefore ensure that none of the properties that are part of the struct have side effects, i.e. via Getters.

    Parameters

    • instance: Args

      of the struct to serialize

    • Optional byteSize: number

      allows to override the size fo the created Buffer and defaults to the size of the struct to serialize

    Returns [Buffer, number]

  • toFixedFromData(buf: Buffer, offset: number): BeetStruct<Class, Args>
  • toFixedFromValue(args: Args): BeetStruct<Class, Args>

Generated using TypeDoc