Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObjectSerializer<Structure>

The ObjectSerializer is meant to give you a an easy to use way to map an simple object structure to a binary representation by iteratively serializing / deserializing the properties of the object.

Type parameters

  • Structure: object

Hierarchy

Index

Constructors

constructor

  • new ObjectSerializer(initialSerializer?: MappedSerializer<Structure>, __namedParameters?: { instanceCreator: InstanceCreator<Structure> }): ObjectSerializer
  • You defined the whole structure for serialization in the constructor by defining all property name to serializer mapping via the initialSerializer argument. See the README for an example.

    The serializerOptions is used to define the instance creator, which should be used to create new object instances of this type. This can be useful if you want to create a instance of a class of attach a prototype manually.

    In any case, any member will be overwritten by the defined serializers or the static members. The default is just the object literal {}.

    Parameters

    • Default value initialSerializer: MappedSerializer<Structure> = {}
    • Default value __namedParameters: { instanceCreator: InstanceCreator<Structure> } = {}
      • instanceCreator: InstanceCreator<Structure>

    Returns ObjectSerializer

Properties

instanceCreator

instanceCreator: InstanceCreator<Structure>

Methods

append

  • append<Name, Serializer>(name: Name, serializer: Serializer): this
  • Appends a serializer for the given name. This serializer needs to be able to serialize the type of the field from the object. There is no check whether the field actually exists or if there is already another serializer registered for this field identifier.

    All serializer will be called in their appended order.

    Type parameters

    Parameters

    • name: Name

      The field name to attach this serializer on.

    • serializer: Serializer

      The serializer to attach on that field.

    Returns this

appendStatic

  • appendStatic<Name, Value>(name: Name, value: Value): this
  • This method sets a static value which will not be serialized and transferred but added after the serialization is finished. This can be useful when you have an identifier member which is always the same for all instanced of this type.

    Type parameters

    • Name: StringKeys<Structure>

    • Value: Structure[Name]

    Parameters

    • name: Name

      The name of the field for the static value.

    • value: Value

      The value which should be put there.

    Returns this

arrayBufferToValue

  • arrayBufferToValue(arrayBuffer: ArrayBuffer): Structure

clone

  • Clones this object serializer, which can be handy if you want to create the serializers for two different subtypes of a more general instance.

    Returns ObjectSerializer<Structure>

    A clone of this object serializer

deserialize

  • deserialize(dv: DataView, offset: number): { offset: number; val: Structure }

getByteSizeFromDataInBuffer

  • getByteSizeFromDataInBuffer(dv: DataView, offset: number): number

getSerializationSteps

  • getSerializationSteps(): AppendedSerializer<Structure>[]

getSizeForValue

  • getSizeForValue(val: Structure): number

getStaticMembers

  • getStaticMembers(): StaticMember<Structure>[]

getStaticSize

  • getStaticSize(): number | undefined

remove

  • remove<Name>(name: Name): this
  • Removes the serializer which are appended using this field identifier.

    Type parameters

    • Name: StringKeys<Structure>

    Parameters

    • name: Name

      the name to search for

    Returns this

serialize

  • serialize(dv: DataView, offset: number, val: Structure): { offset: number }

typeCheck

  • typeCheck(val: Structure, name?: string): void

valueToArrayBuffer

  • valueToArrayBuffer(val: Structure): ArrayBuffer

Generated using TypeDoc