Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Serializer<T>

A serializer for values of type T.

Collabs with a generic type T, like CVar<T> or CValueSet<T>, need a Serializer<T> so that they can send values of type T from one replica to another.

By default, all built-in Collabs use DefaultSerializer, which permits JSON values and some others. To use more general T or to optimize the encoding, you must supply your own Serializer<T>, typically in the Collab constructor's options parameter.

Serializers provided with the library (some only in package @collabs/core) include DefaultSerializer, CollabIDSerializer, StringSerializer, Uint8ArraySerializer, ArraySerializer, PairSerializer, and ConstSerializer.

Type Parameters

  • T

Hierarchy

  • Serializer

Implemented by

Index

Methods

  • deserialize(message: Uint8Array): T
  • Inverse of serialize.

    Typically, this returns a deep clone of the original value, not the same literal reference. Indeed, it is impossible to return the original reference on a different replica.

    Parameters

    • message: Uint8Array

    Returns T

  • serialize(value: T): Uint8Array
  • Returns a Uint8Array that is the serialized form of value.

    To recover the original value, use deserialize.

    Parameters

    • value: T

    Returns Uint8Array

Generated using TypeDoc