API
Every object and union type provides the following functions:
| Function | Description |
|---|---|
encode(obj) → bytes | Serialize to binary |
decode(bytes) → obj | Deserialize from binary |
encodeDiff(prev, next) → bytes | Delta-compress only the changes between two states |
decodeDiff(prev, diff) → obj | Apply a delta to reconstruct the new state |
equals(a, b) → bool | Deep equality comparison (respects float precision) |
clone(obj) → obj | Deep clone |
fromJson(json) → obj | Parse from JSON with lenient type coercion |
toJson(obj) → json | Convert 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.