package octez-proto-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/octez-proto-libs.protocol-environment/Tezos_protocol_environment/V11/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