package octez-proto-libs
type read_error =
| Not_enough_data
(*Decoding requires more bytes than are available in the source of the data. E.g., there are fewer bytes available in the reading buffer than is required by the length field of a dynamically-sized string.
*)| Extra_bytes
(*Decoding requires fewer bytes than were provided.
*)| No_case_matched
| Unexpected_tag of int
| Invalid_int of {
}
(*An integer is out of range. E.g., an integer is beyond a user-provided range.
*)| Invalid_float of {
}
(*A float is out of range.
*)| Trailing_zero
(*An arbitrary-precision number (N or Z) leads to a null byte.
*)| Size_limit_exceeded
(*A value is encoded with more bytes than is allowed by the encoding. E.g., the constraints of a
*)check_size
are being broken.| List_too_long
(*A list contains more elements than is specified in its
*)max_length
parameter.| Array_too_long
(*An array contains more elements than is specified in its
*)max_length
parameter.| Exception_raised_in_user_function of string
| User_invariant_guard of string
All the errors that might be returned while reading a binary value
exception Read_error of read_error
Read_error e
is an exception wrapping the read_error
e
. It is used only by function suffixed by _exn
where the suffix-less function would have returned Error e
.
val pp_read_error : Format.formatter -> read_error -> unit
val read_error_encoding : read_error Data_encoding.Encoding.t
type write_error =
All the errors that might be returned while writing a binary value
val pp_write_error : Format.formatter -> write_error -> unit
val write_error_encoding : write_error Data_encoding.Encoding.t
exception Write_error of write_error
val length : 'a Data_encoding.Encoding.t -> 'a -> int
Compute the expected length of the binary representation of a value.
val fixed_length : 'a Data_encoding.Encoding.t -> 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 Data_encoding.Encoding.t -> 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 read_opt :
'a Data_encoding.Encoding.t ->
string ->
int ->
int ->
(int * 'a) option
read_opt
is like read
but in case of failure, the error is ignored and None
is returned instead.
val read_exn : 'a Data_encoding.Encoding.t -> string -> int -> int -> int * 'a
read_exn
is like read
but in case of failure, the error is wrapped in Read_error
which is raised.
type 'ret status =
| Await of Bytes.t -> 'ret status
(*Partially decoded value.
*)| Error of read_error
(*Failure. The stream is garbled and it should be dropped.
*)
Return type for the function read_stream
.
val read_stream :
?init:Data_encoding__V1.Binary_stream.t ->
'a Data_encoding.Encoding.t ->
'a status
Streamed equivalent of read
.
The internal state that writers handle. It is presented explicitly as an abstract type so that you must use the constructor to obtain it. The constructor (make_writer_state
) performs basic bound checks.
val make_writer_state :
bytes ->
offset:int ->
allowed_bytes:int ->
writer_state option
make_writer_state buffer ~offset ~allowed_bytes
is None
if allowed_bytes < 0
, None
if allowed_bytes > length buffer - offset
, Some _
otherwise.
val write_opt : 'a Data_encoding.Encoding.t -> 'a -> writer_state -> int option
val write_exn : 'a Data_encoding.Encoding.t -> 'a -> writer_state -> int
val of_bytes_opt : 'a Data_encoding.Encoding.t -> Bytes.t -> 'a option
val of_bytes_exn : 'a Data_encoding.Encoding.t -> Bytes.t -> 'a
of_bytes_exn enc buf
is equivalent to of_bytes
, except
val of_string :
'a Data_encoding.Encoding.t ->
string ->
('a, read_error) result
of_string enc buf
is like of_bytes enc buf
but it reads bytes from a string.
val of_string_opt : 'a Data_encoding.Encoding.t -> string -> 'a option
val of_string_exn : 'a Data_encoding.Encoding.t -> string -> 'a
val to_bytes_opt :
?buffer_size:int ->
'a Data_encoding.Encoding.t ->
'a ->
Bytes.t option
val to_string :
?buffer_size:int ->
'a Data_encoding.Encoding.t ->
'a ->
(string, write_error) result
to_string enc v
is like to_bytes
but it returns a string.
Note: to_string enc v
is always equal to Bytes.to_string (to_bytes enc v)
but more efficient.
val to_string_opt :
?buffer_size:int ->
'a Data_encoding.Encoding.t ->
'a ->
string option
val to_string_exn :
?buffer_size:int ->
'a Data_encoding.Encoding.t ->
'a ->
string
val describe : 'a Data_encoding.Encoding.t -> Data_encoding__V1.Binary_schema.t
module Slicer : sig ... end
val read :
'a Data_encoding.Encoding.t ->
bytes ->
int ->
int ->
(int * 'a) option
val write :
'a Data_encoding.Encoding.t ->
'b ->
bytes ->
int ->
int ->
int option
val of_bytes : 'a Data_encoding.Encoding.t -> Bytes.t -> 'b option
val to_bytes : 'a Data_encoding.Encoding.t -> 'b -> Bytes.t option
val to_bytes_exn : 'a Data_encoding.Encoding.t -> 'b -> Bytes.t