package b0

  1. Overview
  2. Docs

Binary codecs.

Encoding

type 'a enc = Buffer.t -> 'a -> unit

The type for binary encoders. enc b v binary encodes the value v in b. Raises Error in case of error.

val enc_err : kind:string -> ('a, Format.formatter, unit, 'b) format4 -> 'a

enc_err ~kind fmt raises a binary encoding error message for kind kind formatted according to fmt.

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.

val enc_list : 'a enc -> 'a list enc

enc_list enc_v encodes a list of values encoded with enc_v.

Decoding

type 'a dec = string -> start:int -> int * 'a

The type for binary decoders. dec s ~start binary decodes a value at start in s. start is either the index of a byte in s or the length of s. The function returns (i, v) with v the decoded value and i the first index in s after the decoded value or the length of s if there is no such index. Raises Error in case of error.

val dec_err : kind:string -> int -> ('a, Format.formatter, unit, 'b) format4 -> 'a

dec_err ~kind i fmt raises a binary decoding error message for kind kind at input byte index i formatted according to fmt.

val dec_err_eoi : kind:string -> int -> 'a

dec_err_eoi ~kind i raises a decoding error message for kind kind at input byte index i 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 kind kind at input byte index i indicating v is not in the range 0;max.

val dec_need : kind:string -> string -> start:int -> len:int -> unit

dec_need ~kind s ~start ~len checks that len bytes are available starting at start (which can be out of bounds) in s and calls err_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 given kind.

val dec_bytes : kind:string -> string dec

dec_bytes ~kind decodes the given bytes for the given kind.

val dec_list : 'a dec -> kind:string -> 'a list dec

bin_dec_list dec_v ~kind decodes a list of values decoded with dec_v for the given kind.

OCaml

Innovation. Community. Security.