Mavryk_tree_encoding
type key = string Mavryk_base.TzPervasives.trace
A key in the tree is a list of string.
exception Key_not_found of key
val return : 'a -> 'a t
return x
is an encoder that does nothing on encoding. On decoding it ignores the tree and returns x
.
conv f g enc
transforms from one encoding to a different one using f
for mapping the results decoded using enc
, and g
for mapping from the input.
It is the user's responsibility to ensure that f
and g
are inverses, that is, that f (g x) = g (f x)
for all x
.
conv_lwt f g enc
is the same as conv
but where f
and g
are effectful (produce lwt promises).
It is the user's responsibility to ensure that f
and g
are inverses, that is, that f (g x) = g (f x)
for all x
.
tup2 ~flatten e1 e2
combines e1
and e2
into an encoder for pairs. If flatten
is true, the elements are encoded directly under the given tree, otherwise each element is wrapped under an index node to avoid colliding keys.
Example: encode
(tup2
~flatten:false
(value [] Data_encoding.string)
(value [] Data_encoding.string))
(("A", "B"))
Gives a tree: "A" "B"
While encode
(tup2
~flatten:true
(value [] Data_encoding.string)
(value [] Data_encoding.string))
(("A", "B"))
Gives a tree: 1
-> "A" 2
-> "B"
tup3 ?flatten e1 e2 e3
combines the given encoders e1 .. e3
into an encoder for a tuple of three elements.
tup4 ?flatten e1 e2 e3 e4
combines the given encoders e1 .. e4
into an encoder for a tuple of four elements.
tup5 ?flatten e1 e2 e3 e4 e5
combines the given encoders e1 .. e5
into an encoder for a tuple of five elements.
val tup6 :
flatten:bool ->
'a t ->
'b t ->
'c t ->
'd t ->
'e t ->
'f t ->
('a * 'b * 'c * 'd * 'e * 'f) t
tup6 ?flatten e1 e2 e3 e4 e5 e6
combines the given encoders e1 .. e6
into an encoder for a tuple of six elements.
val tup7 :
flatten:bool ->
'a t ->
'b t ->
'c t ->
'd t ->
'e t ->
'f t ->
'g t ->
('a * 'b * 'c * 'd * 'e * 'f * 'g) t
tup7 ?flatten e1 e2 e3 e4 e5 e6 e7
combines the given encoders e1 .. e7
into an encoder for a tuple of seven elements.
val tup8 :
flatten:bool ->
'a t ->
'b t ->
'c t ->
'd t ->
'e t ->
'f t ->
'g t ->
'h t ->
('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) t
tup8 ?flatten e1 e2 e3 e4 e5 e6 e7 e8
combines the given encoders e1 .. e8
into an encoder for a tuple of eight elements.
val tup9 :
flatten:bool ->
'a t ->
'b t ->
'c t ->
'd t ->
'e t ->
'f t ->
'g t ->
'h t ->
'i t ->
('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) t
tup9 ~flatten e1 e2 e3 e4 e5 e6 e7 e8 e9
combines the given encoders e1 .. e9
into an encoder for a tuple of nine elements.
val tup10 :
flatten:bool ->
'a t ->
'b t ->
'c t ->
'd t ->
'e t ->
'f t ->
'g t ->
'h t ->
'i t ->
'j t ->
('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j) t
tup10 ~flatten e1 e2 e3 e4 e5 e6 e7 e8 e9 e10
combines the given encoders e1 .. e10
into an encoder for a tuple of ten elements.
value_option key encoding
returns an encoder that uses encoding
for encoding values, but does not fail if the key
is absent.
value ?default key enc
creates an encoder under the given key
using the provided data-encoding enc
for encoding/decoding values, and using default
as a fallback when decoding in case the key
is absent from the tree.
scope key enc
moves the given encoder enc
to encode values under a branch key
.
case tag enc inj proj
returns a partial encoder that represents a case in a sum-type. The encoder hides the (existentially bound) type of the parameter to the specific case, provided converter functions inj
and proj
for the base encoder enc
.
case_lwt tag enc inj proj
same as case tag enc inj proj
but where inj
and proj
returns in lwt values.
tagged_union tag_enc cases
returns an encoder that use tag_enc
for encoding the value of a field tag
. The encoder searches through the list of cases for a matching branch. When a matching branch is found, it uses its embedded encoder for the value. This function is used for constructing encoders for sum-types.
The default
labeled argument can be provided to have a fallback in case the value is missing from the tree.
option enc
lifts the given encoding enc
to one that can encode optional values.
delayed f
produces a tree encoder/decoder that delays evaluation of f ()
until the encoder or decoder is actually needed. This is required to allow for directly recursive encoders/decoders.
either enc_a enc_b
returns an encoder where enc_a
is used for the left case of Either.t
, and enc_b
for the Right
case.
module type TREE = sig ... end
module Wrapped : TREE with type tree = wrapped_tree
val wrapped_tree : wrapped_tree t
wrapped_tree
is a tree encoding for wrapped tree.
module Runner : sig ... end
module Encodings_util : sig ... end
module Lazy_map_encoding : sig ... end
module Lazy_vector_encoding : sig ... end
module CBV_encoding : sig ... end