package octez-libs

  1. Overview
  2. Docs
On This Page
  1. Types
  2. Functions
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Tezos_tree_encodingSource

Sourceexception Incorrect_tree_type
Sourceexception Uninitialized_self_ref

A key in the tree is a list of string.

Sourceexception Key_not_found of key
Sourcetype tree_instance = ..

Types

Sourcetype ('tag, 'a) case

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

Sourcetype 'a t

Represents an encoder and a decoder.

Functions

Sourceval return : 'a -> 'a t

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

Sourceval 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.

Sourceval 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.

Sourceval 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"

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval raw : key -> bytes t

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

Sourceval 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.

Sourceval 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.

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

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

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval option : 'a t -> 'a option t

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

Sourceval 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.

Sourceval 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.

Sourcemodule type TREE = sig ... end
Sourcetype wrapped_tree
Sourcemodule Wrapped : TREE with type tree = wrapped_tree
Sourceval wrapped_tree : wrapped_tree t

wrapped_tree is a tree encoding for wrapped tree.

Sourcemodule Runner : sig ... end
Sourcemodule Encodings_util : sig ... end
Sourcemodule Lazy_map_encoding : sig ... end
Sourcemodule Lazy_vector_encoding : sig ... end
Sourcemodule CBV_encoding : sig ... end
OCaml

Innovation. Community. Security.