package octez-libs

  1. Overview
  2. Docs
On This Page
  1. Types
  2. Functions
exception Incorrect_tree_type
exception Uninitialized_self_ref

A key in the tree is a list of string.

exception Key_not_found of key
type tree_instance = ..

Types

type ('tag, 'a) case

Represents a partial encoder for a specific constructor of a sum-type.

type 'a t

Represents an encoder and a decoder.

Functions

val return : 'a -> 'a t

return x is an encoder that does nothing on encoding. On decoding it ignores the tree and returns x.

val conv : ('a -> 'b) -> ('b -> 'a) -> 'a t -> 'b t

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.

val conv_lwt : ('a -> 'b Lwt.t) -> ('b -> 'a Lwt.t) -> 'a t -> 'b t

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.

val tup2 : flatten:bool -> 'a t -> 'b t -> ('a * 'b) t

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"

val tup3 : flatten:bool -> 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

tup3 ?flatten e1 e2 e3 combines the given encoders e1 .. e3 into an encoder for a tuple of three elements.

val tup4 : flatten:bool -> 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

tup4 ?flatten e1 e2 e3 e4 combines the given encoders e1 .. e4 into an encoder for a tuple of four elements.

val tup5 : flatten:bool -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t

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.

val raw : key -> bytes t

raw key is an encoder for bytes under the given key.

val value_option : key -> 'a Tezos_base.TzPervasives.Data_encoding.t -> 'a option t

value_option key encoding returns an encoder that uses encoding for encoding values, but does not fail if the key is absent.

val value : ?default:'a -> key -> 'a Tezos_base.TzPervasives.Data_encoding.t -> 'a t

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.

val scope : key -> 'a t -> 'a t

scope key enc moves the given encoder enc to encode values under a branch key.

val case : 'tag -> 'b t -> ('a -> 'b option) -> ('b -> 'a) -> ('tag, 'a) case

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.

val case_lwt : 'tag -> 'b t -> ('a -> 'b Lwt.t option) -> ('b -> 'a Lwt.t) -> ('tag, 'a) case

case_lwt tag enc inj proj same as case tag enc inj proj but where inj and proj returns in lwt values.

val tagged_union : ?default:(unit -> 'a) -> 'tag t -> ('tag, 'a) case list -> 'a t

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.

val option : 'a t -> 'a option t

option enc lifts the given encoding enc to one that can encode optional values.

val delayed : (unit -> 'a t) -> 'a t

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.

val either : 'a t -> 'b t -> ('a, 'b) Either.t t

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
type wrapped_tree
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
OCaml

Innovation. Community. Security.