Crdt.Model_codec_compact

crdt · API reference

Compact document codec (compact JSON with type codes)

Compact structural encoding for CRDT document snapshots.

This module implements the compact JSON format compatible with json-joy's model.compact.json format.

The compact format uses type codes and relative session IDs to reduce size while remaining human-readable.

Format overview:

  • Clock: flat array sid1, time1, sid2, time2, ...
  • Nodes: type_code, id, content...
  • IDs: relative_sid_index, time where sid_index is negative 1-based Node type codes:
  • 0: con (constant value)
  • 1: val (value reference)
  • 2: obj (object/map)
  • 3: vec (vector/tuple)
  • 4: str (string)
  • 5: bin (binary)
  • 6: arr (array)
module J = Simdjsont.Json
val type_code_con : int
val type_code_val : int
val type_code_obj : int
val type_code_vec : int
val type_code_str : int
val type_code_bin : int
val type_code_arr : int
val string_span : string -> int
val bytes_span : bytes -> int
type sid_table = {
  mutable sids : int list;
  mutable sid_to_idx : (int, int) Hashtbl.t;
}
val create_sid_table : unit -> sid_table
val get_or_add_sid : sid_table -> int -> int
val encode_timestamp : sid_table -> Clock.timestamp -> J.t
val encode_value : Value.t -> J.t
val encode_str_chunks : sid_table -> string Rga.chunk list -> J.t
val encode_bin_chunks : sid_table -> bytes Rga.chunk list -> J.t
val encode_arr_chunks : 
  sid_table ->
  Model.t ->
  Clock.timestamp Rga.chunk list ->
  J.t
val encode_node : sid_table -> Model.t -> Node.t -> J.t
val encode_clock_from_table : sid_table -> Clock.clock_vector -> 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 decode_timestamp : int array -> J.t -> Clock.timestamp option
val decode_clock : J.t -> (int array * Clock.clock_vector) option
val decode_value : J.t -> Value.t
val decode_node : int array -> Model.t -> J.t -> Clock.timestamp 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