Crdt.Op_codec

crdt · API reference

JSON codec for operations (verbose format)

JSON codec for CRDT operations.

Encodes/decodes operations in the json-joy verbose JSON format.

module J = Simdjsont.Json

Timestamp Codec

val encode_timestamp : Clock.timestamp -> J.t

Encode a timestamp as sid, time JSON array

val decode_timestamp : J.t -> Clock.timestamp option

Decode a timestamp from JSON

Timespan Codec

val encode_timespan : Clock.timespan -> J.t

Encode a timespan as sid, time, span JSON array

val decode_timespan : J.t -> Clock.timespan option

Decode a timespan from JSON

Object Entry Codec

val encode_obj_entry : Op.obj_entry -> J.t

Encode an object entry as "key", [sid, time]

val decode_obj_entry : J.t -> Op.obj_entry option

Decode an object entry from "key", [sid, time]

Value Codec for new_con

val encode_con_value : Value.t -> J.t

Encode a Value.t for new_con (only primitives: null, bool, number, string)

val decode_con_value : J.t -> Value.t

Decode a Value.t from JSON for new_con

Operation Encoding

val make_obj : (string * J.t) list -> J.t

Make a JSON object with the given members

val encode_op : Op.op_data -> J.t

Encode an operation to JSON (verbose format)

Operation Decoding

val get_member : string -> (string * J.t) list -> J.t option

Get a member from a JSON object members list

val get_string : string -> (string * J.t) list -> string option

Get a string field from a JSON object

val get_timestamp : string -> (string * J.t) list -> Clock.timestamp option

Get a timestamp field from a JSON object

val get_int : string -> (string * J.t) list -> int option

Get an int field from a JSON object

val decode_op : J.t -> (Op.op_data, string) result

Decode an operation from JSON (verbose format)

String Encoding/Decoding

val encode : Op.op_data -> string

Encode an operation to a JSON string

val decode : string -> (Op.op_data, string) result

Decode an operation from a JSON string