Interface SerializationAdapter<Value, Payload>

Adapter that serializes/deserializes Value as a Payload.

interface SerializationAdapter<Value, Payload> {
    tag: number;
    canPack(value: any, options: Readonly<SerializationOptions>): boolean;
    hydrate?(value: Value, payload: Payload, options: Readonly<SerializationOptions>): void;
    pack(value: Value, options: Readonly<SerializationOptions>): undefined | Payload;
    unpack(payload: Dehydrated<Payload>, options: Readonly<SerializationOptions>): Value;
}

Type Parameters

  • Value = any

    The value to serialize.

  • Payload = any

    The payload that describes Value.

Properties

Methods

Properties

tag: number

The integer tag of the value type.

Tags must be unique among adapters that participate in serialization.

Methods

  • Returns true if the adapter can pack the value.

    Parameters

    Returns boolean

  • Hydrates the value that was previously returned from the unpack method.

    Parameters

    Returns void

  • Converts value into a serializable payload.

    The returned payload is dehydrated before serialization, so it can contain complex data structures and cyclic references. If the value itself is returned from this method, then the serialization would proceed as if adapter wasn't applied.

    If undefined is returned then value isn't serialized.

    Parameters

    Returns undefined | Payload

    The payload that is dehydrated and serialized.

  • Returns the shallow value to which circular references from the payload may point.

    Parameters

    Returns Value