Module Private.Codec
Topkg interprocess communication codec.
Codecs for communication between the topkg
tool and topkg description files.
Decode errors
type error
=
|
Corrupted of string * string
|
Version of int * int
The type for decode errors.
Corrupted (kind, data)
, an error occured while decodingdata
forkind
.Version (exp, fnd)
, a versioned decoder expected versionexp
but foundfnd
val pp_error : Stdlib.Format.formatter -> error -> unit
pp_error ppf e
prints an unspecified representation ofe
onppf
.
exception
Error of error
Raised on decode errors.
Codecs
val v : kind:string -> enc:('a -> string) -> dec:(string -> 'a) -> 'a t
v kind enc dec
is a codec for value identified askind
usingenc
to encode anddec
to decode.
val kind : 'a t -> string
kind c
isc
's kind.
val enc : 'a t -> 'a -> string
enc c
isc
's encoder.
val dec : 'a t -> string -> 'a
dec c
isc
's decoder. The decoder- raises Error
in case of decode error
Base type codecs
val unit : unit t
unit
codecs a()
.
val const : 'a -> 'a t
const v
codecs the constantv
.
val bool : bool t
bool
codecs booleans.
val int : int t
int
codecs integers.
val string : string t
string
codecs strings.
val result : ok:'a t -> error:'b t -> ('a, 'b) Result.result t
result ~ok ~error
codecsok
,error
results.
val t5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
t5
is likepair
but for qintuples.
val alt : kind:string -> ('a -> int) -> 'a t array -> 'a t
alt tag cs
codecs values by tagging them withtag
and using the corresponding codec incs
.- raises Invalid_argument
if
Array.length cs > 256
.
Topkg types
val msg : [ `Msg of string ] t
msg
codecs error messages.