package octez-proto-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=c6df840ebbf115e454db949028c595bec558a59a66cade73b52a6d099d6fa4d4
sha512=d8aee903b9fe130d73176bc8ec38b78c9ff65317da3cb4f3415f09af0c625b4384e7498201fdb61aa39086a7d5d409d0ab3423f9bc3ab989a680cf444a79bc13
doc/octez-proto-libs.protocol-environment/Tezos_protocol_environment/V8/Make/Data_encoding/Binary/index.html
Module Data_encoding.Binary
val length : 'a encoding -> 'a -> int
Compute the expected length of the binary representation of a value.
val fixed_length : 'a encoding -> int option
Returns the size of the binary representation that the given encoding might produce, only when this size does not depends of the value itself.
E.g., fixed_length (tup2 int64 (Fixed.string 2))
is Some _
E.g., fixed_length (result int64 (Fixed.string 2))
is None
E.g., fixed_length (list (tup2 int64 (Fixed.string 2)))
is None
val maximum_length : 'a encoding -> int option
Returns the maximum size of the binary representation that the given encoding might produce, only when this maximum size does not depends of the value itself.
E.g., maximum_length (tup2 int64 (Fixed.string 2))
is Some _
E.g., maximum_length (result int64 (Fixed.string 2))
is Some _
E.g., maximum_length (list (tup2 int64 (Fixed.string 2)))
is None
Note that the function assumes that recursive encodings (build using mu
) are used for recursive data types. As a result, maximum_length
will return None
if given a recursive encoding.
If there are static guarantees about the maximum size of the representation for values of a given type, you can wrap your encoding in check_size
. This will cause maximum_length
to return Some _
.
val of_bytes_opt : 'a encoding -> bytes -> 'a option
val of_string_opt : 'a encoding -> string -> 'a option
val to_bytes_opt : ?buffer_size:int -> 'a encoding -> 'a -> bytes option
val to_bytes_exn : ?buffer_size:int -> 'a encoding -> 'a -> bytes
to_bytes_exn enc v
is equivalent to to_bytes enc v
, except
val to_string_opt : ?buffer_size:int -> 'a encoding -> 'a -> string option
val to_string_exn : ?buffer_size:int -> 'a encoding -> 'a -> string