Library
Module
Module type
Parameter
Class
Class type
A 'a decodee describes a way to traverse a value of some type representing a serialization format such as JSON or B-encode
Decode a value of type 'src
and ('src, 'into) inner_decoder = {
accept_unit : 'src source -> unit -> 'into;
accept_bool : 'src source -> bool -> 'into;
accept_float : 'src source -> float -> 'into;
accept_int : 'src source -> int -> 'into;
accept_int32 : 'src source -> int32 -> 'into;
accept_int64 : 'src source -> int64 -> 'into;
accept_nativeint : 'src source -> nativeint -> 'into;
accept_char : 'src source -> char -> 'into;
accept_string : 'src source -> string -> 'into;
accept_list : 'src source -> 'src list -> 'into;
accept_option : 'src source -> 'src option -> 'into;
accept_record : 'src source -> (string * 'src) list -> 'into;
accept_tuple : 'src source -> 'src list -> 'into;
accept_sum : 'src source -> string -> 'src list -> 'into;
}
Decode a value of type 'src into a type 'into.
val int : int decoder
val char : char decoder
val int32 : int32 decoder
val int64 : int64 decoder
val nativeint : nativeint decoder
val float : float decoder
val bool : bool decoder
val unit : unit decoder
val string : string decoder
Only accepts a 2-elements list/tuple
Only accepts a 3-elements list/tuple
record_get name dec l
is a helper for decoding records. It is given a list of fields l
, and searches name
through it. If name
is found with a value v
, dec.accept v
is called. Otherwise an error is raised
val record : 'into record_decoder -> 'into decoder
Decoder for records. It will adapt itself to association tuples and lists.
val record_fix : ('into decoder -> 'into record_decoder) -> 'into decoder
val sum : 'into sum_decoder -> 'into decoder
Decoder for sums. It will adapt itself to strings, lists and tuples
val sum_fix : ('into decoder -> 'into sum_decoder) -> 'into decoder
val tuple : 'into tuple_decoder -> 'into decoder
Tuple decoder
Examples:
type mytuple = int * string * float list ;;
let decode_mytuple = tuple {
tuple_accept=fun src l -> arg3 int int (list string) src l);
};;
(* OR, because triples are really easy: *)
let decode_mytuple = triple int int (list string);;
type point = { x:int; y:int; color:string };;
let decode_point = record ~expected:"point" {
record_accept=(fun src l ->
let x = record_get "x" int src l in
let y = record_get "y" int src l in
let color = record_get "color" string src l in
{x;y;color}
);
};;