• Public
  • Public/Protected
  • All

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





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


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


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


  • get type(): string


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


    • 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.


    • 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