Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ValueSerializer<Type>

This is the general class used to identify a serializer by. It does not contain any additional functionality but might do so in the future. It does contain the TYPE_PINPOINT field which is only used by TypeScript to raise an error when non matching instances are applied, since the generic is not used for those checks.

Type parameters

  • Type

Hierarchy

Index

Methods

arrayBufferToValue

  • arrayBufferToValue(arrayBuffer: ArrayBuffer): Type
  • Shortcut which deserializes the value and assumes the whole ArrayBuffer for this action.

    Parameters

    • arrayBuffer: ArrayBuffer

      the ArrayBuffer which contains the value

    Returns Type

Abstract deserialize

  • deserialize(dv: DataView, offset: number): { offset: number; val: Type }
  • Deserializes the given data into the data representation which was originally given. It returns an object with the offset (the next unread byte) and the value which was created from the DataView.

    Parameters

    • dv: DataView

      The DataView to read the data from.

    • offset: number

      The initial offset to start reading from

    Returns { offset: number; val: Type }

    • offset: number
    • val: Type

getByteSizeFromDataInBuffer

  • getByteSizeFromDataInBuffer(dv: DataView, offset: number): number
  • This method retrieves the number of bytes this serializer will consume from the given buffer and offset. This is handy if you want to split the deserialization or want to skip sections of the deserialization.

    If the getStaticSize value is given than this method will return this value, if not then it will use the given buffer to calculate the length without deserializing it.

    Be aware that this operation might be called recursively and not as fast as expected since the full byte size of a structure is not written in the data.

    Parameters

    • dv: DataView
    • offset: number

    Returns number

Abstract getSizeForValue

  • getSizeForValue(val: Type): number
  • Gets the number of bytes needed to to serialize the given value. This value will be the same as staticSize if it is static.

    Parameters

    • val: Type

      the value to serialize

    Returns number

Abstract getStaticSize

  • getStaticSize(): number | undefined
  • This attribute is used to identify if the number of bytes used by this serializer to serialize the value is dependent on the value which is serialized or if it is the same for all values.

    This value is undefined if it is dependent on the value which is serialized or is a number of bytes needed to serialize any value.

    Returns number | undefined

Abstract serialize

  • serialize(dv: DataView, offset: number, val: Type): { offset: number }
  • Serializes the given value using the provided DataView in respect to the provided offset in bytes. It returns an object with the new offset (offset + getSizeForValue(val)).

    Parameters

    • dv: DataView

      DataView which will be used to write the values to the underlying buffer.

    • offset: number

      Offset in bytes to write the values in respect to.

    • val: Type

      The Value to serialize.

    Returns { offset: number }

    • offset: number

Abstract typeCheck

  • typeCheck(val: Type, name?: undefined | string): never | void
  • This function will check whether the provided value is fully serializable by this serializer. Which includes a range and a type check.

    Parameters

    • val: Type

      the value to check

    • Optional name: undefined | string

      the name this value has in a greater scope, is used to generate more readable error messages

    Returns never | void

valueToArrayBuffer

  • valueToArrayBuffer(val: Type): ArrayBuffer
  • Shortcut which creates an appropriately sized ArrayBuffer for the value and serializes the value.

    Parameters

    • val: Type

      the value to serialize

    Returns ArrayBuffer

Generated using TypeDoc