Crdt.Patch_codec_compact

crdt · API reference

Compact JSON codec for patches

Compact JSON codec for Patch.

Encodes/decodes patches in the json-joy compact JSON format. This is an array-based encoding that is more compact than verbose:

Patch: [id], op1, op2, ... ID: [sid, time] Operations: opcode, ...args

Timestamps in operations can be encoded as just the time component when the session ID matches the patch's session ID.

Compact opcodes (from json-joy):

  • 0: new_con
  • 1: new_val
  • 2: new_obj
  • 3: new_vec
  • 4: new_str
  • 5: new_bin
  • 6: new_arr
  • 9: ins_val
  • 10: ins_obj
  • 11: ins_vec
  • 12: ins_str
  • 13: ins_bin
  • 14: ins_arr
  • 15: upd_arr
  • 16: del
  • 17: nop
module J = Simdjsont.Json
val compact_opcode_of_op : Op.op_data -> int
val encode_ts : patch_sid:int -> Clock.timestamp -> J.t
val encode_timespan : patch_sid:int -> Clock.timespan -> J.t
val encode_con_value : Value.t -> J.t
val encode_op : patch_sid:int -> Op.op_data -> J.t
val encode_patch_json : Patch.t -> J.t
val encode : Patch.t -> string
val encode_bigstring : 
  Patch.t ->
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * int
val encode_pretty : Patch.t -> string
val decode_ts : patch_sid:int -> J.t -> Clock.timestamp option
val decode_timespan : patch_sid:int -> J.t -> Clock.timespan option
val decode_con_value : J.t -> Value.t
val decode_int : J.t -> int option
val get_arr_elem : 'a list -> int -> 'a option
val decode_op : patch_sid:int -> J.t -> (Op.op_data, string) result
val decode_patch_json : J.t -> (Patch.t, string) result
val decode : string -> (Patch.t, string) result
val decode_bigstring : 
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
  len:int ->
  (Patch.t, string) result
val decode_ndjson_seq : 
  ?batch_size:int ->
  Simdjsont.Raw.buffer ->
  len:int ->
  (Patch.t, string) result Seq.t
val encode_batch_json : Patch.batch -> J.t
val encode_batch : Patch.batch -> string
val encode_batch_bigstring : 
  Patch.batch ->
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t * int
val decode_batch_json : J.t -> (Patch.batch, string) result
val decode_batch : string -> (Patch.batch, string) result
val decode_batch_bigstring : 
  (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
  len:int ->
  (Patch.batch, string) result