Module Conv.Bin
Binary codecs.
Encoding
type 'a enc
= Stdlib.Buffer.t -> 'a -> unit
The type for binary encoders.
enc b v
binary encodes the valuev
inb
. RaisesError
in case of error.
val enc_err : kind:string -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a
enc_err ~kind fmt
raises a binary encoding error message for kindkind
formatted according tofmt
.
val enc_byte : int enc
enc_byte
encodes an integer in range [0;255].
val enc_bytes : string enc
enc_bytes
encodes the given bytes.
Decoding
type 'a dec
= string -> start:int -> int * 'a
The type for binary decoders.
dec s ~start
binary decodes a value atstart
ins
.start
is either the index of a byte ins
or the length ofs
. The function returns(i, v)
withv
the decoded value andi
the first index ins
after the decoded value or the length ofs
if there is no such index. RaisesError
in case of error.
val dec_err : kind:string -> int -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a
dec_err ~kind i fmt
raises a binary decoding error message for kindkind
at input byte indexi
formatted according tofmt
.
val dec_err_eoi : kind:string -> int -> 'a
dec_err_eoi ~kind i
raises a decoding error message for kindkind
at input byte indexi
indicating an unexpected end of input.
val dec_err_exceed : kind:string -> int -> int -> max:int -> 'a
dec_err_exceed ~kind i v ~max
raises a decoding error message for kindkind
at input byte indexi
indicatingv
is not in the range0;max
.
val dec_need : kind:string -> string -> start:int -> len:int -> unit
dec_need ~kind s ~start ~len
checks thatlen
bytes are available starting atstart
(which can be out of bounds) ins
and callserr_eoi
if that is not the case.
val dec_byte : kind:string -> int dec
dec_byte
decodes an integer in range [0;255] for the givenkind
.
val dec_bytes : kind:string -> string dec
dec_bytes ~kind
decodes the given bytes for the givenkind
.