Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TransformSerializer<Origin, Base>

This class is meant to help to define serializers which map values from one type to another before serialization. This mapping is meant to be done Origin -> Base -> Binary -> Base -> Origin

In this class you just define the mapping from Origin to Base and back and add the serializer for the Base type. This also allows you to chain those serializers.

This abstract class reduces the number of methods one needs to implement in comparison to a full custom class. Just the Origin => Base, Base => Origin and the type check need to be implemented.

Type parameters

  • Origin

  • Base

Hierarchy

Index

Constructors

constructor

Methods

arrayBufferToValue

  • arrayBufferToValue(arrayBuffer: ArrayBuffer): Origin

deserialize

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

Abstract fromBaseToOrigin

  • fromBaseToOrigin(val: Base): Origin

Abstract fromOriginToBase

  • fromOriginToBase(val: Origin): Base
  • This method maps the Origin value to Base. This method should throw an error if the value is not in fact of type origin.

    Parameters

    • val: Origin

      the value to map

    Returns Base

getByteSizeFromDataInBuffer

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

getSizeForValue

  • getSizeForValue(val: Origin): number

getStaticSize

  • getStaticSize(): number | undefined

Abstract originTypeCheck

  • originTypeCheck(val: Origin, name: string): never | void
  • This method will be called by the typeCheck method. Before calling the typeCheck of the parent with the mapped Base value.

    This method should throw an error when the value is not of type Origin. This error should be precise and use the provided name as identifier when addressing the value to increase the error message readability.

    Parameters

    • val: Origin

      the value to check

    • name: string

      the identifier name this value had in the greater scope

    Returns never | void

serialize

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

typeCheck

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

valueToArrayBuffer

  • valueToArrayBuffer(val: Origin): ArrayBuffer

Generated using TypeDoc