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, timewhere 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.Jsonval type_code_con : intval type_code_val : intval type_code_obj : intval type_code_vec : intval type_code_str : intval type_code_bin : intval type_code_arr : intval string_span : string -> intval bytes_span : bytes -> inttype sid_table = {
mutable sids : int list;
mutable sid_to_idx : (int, int) Hashtbl.t;
}val create_sid_table : unit -> sid_tableval get_or_add_sid : sid_table -> int -> intval encode_timestamp : sid_table -> Clock.timestamp -> J.tval encode_value : Value.t -> J.tval encode_str_chunks : sid_table -> string Rga.chunk list -> J.tval encode_bin_chunks : sid_table -> bytes Rga.chunk list -> J.tval encode_arr_chunks :
sid_table ->
Model.t ->
Clock.timestamp Rga.chunk list ->
J.tval encode_node : sid_table -> Model.t -> Node.t -> J.tval encode_clock_from_table : sid_table -> Clock.clock_vector -> J.tval encode : Model.t -> J.tval encode_string : ?minify:bool -> Model.t -> stringval encode_bigstring :
?minify:bool ->
Model.t ->
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * intval decode_timestamp : int array -> J.t -> Clock.timestamp optionval decode_clock : J.t -> (int array * Clock.clock_vector) optionval decode_value : J.t -> Value.tval decode_node : int array -> Model.t -> J.t -> Clock.timestamp optionval decode : J.t -> Model.t optionval decode_string : string -> Model.t optionval decode_bigstring :
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
len:int ->
Model.t option