Data_encoding.Binaryval length : 'a encoding -> 'a -> intCompute the expected length of the binary representation of a value.
val fixed_length : 'a encoding -> int optionReturns 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 optionReturns 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 optionval of_string_opt : 'a encoding -> string -> 'a optionval to_bytes_opt : ?buffer_size:int -> 'a encoding -> 'a -> bytes optionval to_bytes_exn : ?buffer_size:int -> 'a encoding -> 'a -> bytesto_bytes_exn enc v is equivalent to to_bytes enc v, except
val to_string_opt : ?buffer_size:int -> 'a encoding -> 'a -> string optionval to_string_exn : ?buffer_size:int -> 'a encoding -> 'a -> string