Skip to content

API

Every object and union type provides the following functions:

FunctionDescription
encode(obj) → bytesSerialize to binary
decode(bytes) → objDeserialize from binary
encodeDiff(prev, next) → bytesDelta-compress only the changes between two states
decodeDiff(prev, diff) → objApply a delta to reconstruct the new state
equals(a, b) → boolDeep equality comparison (respects float precision)
clone(obj) → objDeep clone
fromJson(json) → objParse from JSON with lenient type coercion
toJson(obj) → jsonConvert to a JSON-serializable representation

Typical flow

          encode              decode
 Server ────────→ [bytes] ────────→ Client
   T                                  T

          encodeDiff          decodeDiff
 Server ────────→ [bytes] ────────→ Client
 (prev,next)                     (prev,diff)

The server sends a full encode snapshot when a client first connects, then sends encodeDiff deltas for subsequent state changes. The client applies each delta to its local copy using decodeDiff.

Released under the MIT License.