Skip to main content

Interface: Serializer

Encodes and decodes values and calls against a tree, with a list of value serializers. Created with createSerializer.

Every operation takes the root of the tree as its first argument; it must be a tree root.

Properties​

serializers​

readonly serializers: readonly ValueSerializer<any, any>[];

The list of value serializers it was created with, without the built-ins.

Methods​

decodeCall()​

decodeCall(root, json): ResolvedCall;

Decodes a call encoded with encodeCall: the target is resolved and the name resolved on it, nothing is run. The arguments are decoded when args is first read.

Parameters​

ParameterTypeDescription
rootobjectRoot of the tree.
json| JsonValue | EncodedCallThe encoded call.

Returns​

ResolvedCall

The resolved call, to pass to applyCall or applyCallAsync.


decodeValue()​

decodeValue(root, json): unknown;

Decodes a value encoded with encodeValue. References are resolved against the tree; snapshots become new instances.

Parameters​

ParameterTypeDescription
rootobjectRoot of the tree.
jsonJsonValueValue to decode.

Returns​

unknown

The decoded value.


encodeCall()​

encodeCall(root, call): EncodedCall;

Encodes a call (an ActionCall, e.g. from onActionMiddleware's onStart, or a Call) as JSON. The target always goes as a reference; for a standalone action, it isn't repeated in the arguments.

Encode an ActionCall before the action runs (e.g. in onStart), so its arguments are encoded against the tree the receiver has.

Parameters​

ParameterTypeDescription
rootobjectRoot of the tree.
callActionCall | CallThe call.

Returns​

EncodedCall

The encoded call.


encodeValue()​

encodeValue(root, value): JsonValue;

Encodes a value as JSON. Nodes of the tree go as references when a reference serializer in the list claims them.

Parameters​

ParameterTypeDescription
rootobjectRoot of the tree.
valueunknownValue to encode.

Returns​

JsonValue

The encoded value.