Crdt.Value

crdt · API reference

Value types including JSON and CBOR extensions

Value types including JSON and CBOR extensions.

This module defines the internal value type supporting JSON values plus CBOR extensions (bytes, undefined).

type t = 
  | Null
  | Undefined (* CBOR extension - not in standard JSON *)
  | Bool of bool
  | Int of int (* 53-bit safe integer *)
  | Float of float
  | String of string
  | Bytes of bytes (* CBOR extension - not in standard JSON *)
  | Array of t list
  | Object of (string * t) list
  | Timestamp_ref of int * int (* Reference to another node as (sid, time) *)

The value type supporting JSON + CBOR extensions

val equal : t -> t -> bool

equal a b returns true if values are structurally equal

val compare : t -> t -> int

compare a b provides total ordering for values

val null : t

null is the JSON null value

val undefined : t

undefined is the CBOR undefined value

val bool : bool -> t

bool b creates a boolean value

val int : int -> t

int i creates an integer value

val float : float -> t

float f creates a float value

val string : string -> t

string s creates a string value

val bytes : bytes -> t

bytes b creates a bytes value (CBOR extension)

val array : t list -> t

array vs creates an array value

val obj : (string * t) list -> t

obj pairs creates an object value

val timestamp_ref : int -> int -> t

timestamp_ref sid time creates a timestamp reference

val is_null : t -> bool

is_null v returns true if the value is null

val is_undefined : t -> bool

is_undefined v returns true if the value is undefined

val is_bool : t -> bool

is_bool v returns true if the value is a boolean

val is_int : t -> bool

is_int v returns true if the value is an integer

val is_float : t -> bool

is_float v returns true if the value is a float

val is_string : t -> bool

is_string v returns true if the value is a string

val is_bytes : t -> bool

is_bytes v returns true if the value is bytes

val is_array : t -> bool

is_array v returns true if the value is an array

val is_object : t -> bool

is_object v returns true if the value is an object

val is_timestamp_ref : t -> bool

is_timestamp_ref v returns true if the value is a timestamp reference

val to_bool : t -> bool option

to_bool v extracts a boolean, or None if not a boolean

val to_int : t -> int option

to_int v extracts an integer, or None if not an integer

val to_float : t -> float option

to_float v extracts a float, or None if not a float

val to_string_opt : t -> string option

to_string_opt v extracts a string, or None if not a string

val to_bytes : t -> bytes option

to_bytes v extracts bytes, or None if not bytes

val to_array : t -> t list option

to_array v extracts an array, or None if not an array

val to_object : t -> (string * t) list option

to_object v extracts an object, or None if not an object

val to_timestamp_ref : t -> (int * int) option

to_timestamp_ref v extracts a timestamp reference, or None

val pp : Format.formatter -> t -> unit

pp fmt v pretty-prints a value

val to_string : t -> string

to_string v converts a value to a string representation

val type_name : t -> string

type_name v returns the type name of the value