Crdt.Model_codec_indexed

crdt · API reference

Indexed document codec (flat map by timestamp)

Indexed document codec.

The indexed format stores nodes as a flat map keyed by timestamp string. This is useful for:

  • Incremental sync (fetch individual nodes by ID)
  • Efficient lookup of specific nodes
  • Partial document loading Format:
{
  "clock": [[sid, time], ...],
  "root": "sid.time",  // Timestamp string for root node
  "nodes": {
    "sid.time": {...node data...},
    ...
  }
}

Node formats in the map:

  • con: {"t": "con", "v": value}
  • val: {"t": "val", "r": "sid.time"} or {"t": "val"} if empty
  • obj: {"t": "obj", "m": {"key": "sid.time", ...}}
  • vec: {"t": "vec", "s": ["sid.time" or null, ...]}
  • str: {"t": "str", "c": [[sid,time,value_or_span], ...]}
  • bin: {"t": "bin", "c": [[sid,time,value_or_span], ...]}
  • arr: {"t": "arr", "c": [[sid,time,ref_or_span], ...]}
module J = Simdjsont.Json
val ts_to_string : Clock.timestamp -> string
val ts_of_string : string -> Clock.timestamp option
val encode_timestamp : Clock.timestamp -> J.t
val decode_timestamp : J.t -> Clock.timestamp option
val encode_clock : Clock.clock_vector -> J.t
val decode_clock : J.t -> Clock.clock_vector option
val encode_value : Value.t -> J.t
val decode_value : J.t -> Value.t
val encode_node : Node.t -> J.t
val encode : Model.t -> J.t
val encode_string : ?minify:bool -> Model.t -> string
val encode_bigstring : 
  ?minify:bool ->
  Model.t ->
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * int
val get_member : string -> (string * J.t) list -> J.t option
val decode_node : Model.t -> J.t -> Clock.timestamp -> Node.t option
val decode : J.t -> Model.t option
val decode_string : string -> Model.t option
val decode_bigstring : 
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
  len:int ->
  Model.t option
val get_node_json : J.t -> Clock.timestamp -> J.t option
val get_node_ids : J.t -> Clock.timestamp list