CConv.EncodeSourcetype 'a output = {unit : 'a;bool : bool -> 'a;float : float -> 'a;char : char -> 'a;int : int -> 'a;nativeint : nativeint -> 'a;int32 : int32 -> 'a;int64 : int64 -> 'a;string : string -> 'a;list : 'a list -> 'a;option : 'a option -> 'a;record : (string * 'a) list -> 'a;tuple : 'a list -> 'a;sum : string -> 'a list -> 'a;}Print values. Caution, inefficient! Should be used for debugging only
A way to encode values of type 'src into any serialization format
Helper to apply an encoder to a value
Encode a record, using the polymorphic record record_encoder to generate an association list
Fixpoint on record definition
Example:
type point = {x:int; y:int; c:string};;
let enc_point = record
{record_emit=fun into {x;y;c} ->
[ "x", into.int x
; "y", into.int y
; "c", into.string c
]
} ;;General encoding of tuples (returns a list of values)
Fixpoint on sum types
Example:
type tree = Empty | Leaf of int | Node of tree * tree;;
let encode_tree = sum_fix
(fun self -> {sum_emit=fun into x -> match x with
| Empty -> "empty", []
| Leaf i -> "leaf", [int.emit into i]
| Node (l,r) -> "node", [self.emit into l; self.emit into r]
});;