Module Bare_encoding

BARE runtime library.

See the spec.

module String_map : sig ... end
type bslice = {
  1. bs : bytes;
  2. mutable off : int;
  3. mutable len : int;
}
type 'a input = {
  1. read_byte : 'a -> char;
    (*

    Read a single byte.

    • raises Invalid_argument

      if input is exhausted

    *)
  2. read_i16 : 'a -> int;
    (*

    Read 2 bytes, in little endian.

    • raises Invalid_argument

      if input is exhausted

    *)
  3. read_i32 : 'a -> int32;
    (*

    Read 4 bytes, in little endian.

    • raises Invalid_argument

      if input is exhausted

    *)
  4. read_i64 : 'a -> int64;
    (*

    Read 8 bytes, in little endian.

    • raises Invalid_argument

      if input is exhausted

    *)
  5. read_exact : 'a -> bytes -> int -> int -> unit;
    (*

    read_exact buf i len reads len bytes into buf, starting at offset i

    • raises Invalid_argument

      if input has less than len bytes

    *)
}

Input type.

An input is a source of bytes, used to decode.

module Decode : sig ... end

Decoders.

type 'a output = {
  1. write_byte : 'a -> char -> unit;
    (*

    Write a single byte.

    *)
  2. write_i16 : 'a -> int -> unit;
    (*

    Write 2 bytes, in little endian.

    *)
  3. write_i32 : 'a -> int32 -> unit;
    (*

    Write 4 bytes, in little endian.

    *)
  4. write_i64 : 'a -> int64 -> unit;
    (*

    Write 8 bytes, in little endian.

    *)
  5. write_exact : 'a -> bytes -> int -> int -> unit;
    (*

    write_exact b i len writes the slice of length len of b starting at i.

    *)
  6. flush : 'a -> unit;
    (*

    Non specified hint that the data may be flushed onto the disk or network. Doing nothing is acceptable when this makes no sense (e.g. when writing to a Buffer.t).

    *)
}

Output

An output is a sink where one can write bytes to encode data to BARE.

module Encode : sig ... end

Encoder type and some encoding utils.

module Pp : sig ... end

Pretty printer utils, using Format.

val of_bytes_exn : ?off:int -> ?len:int -> 'a Decode.dec -> bytes -> 'a

of_bytes_exn dec bs uses dec to decode a value of type 'a from bytes stored in bs.

  • parameter off

    the initial offset in bs (default 0)

  • raises Decode.Error

    if decoding fails

val of_bytes : ?off:int -> ?len:int -> 'a Decode.dec -> bytes -> ('a, string) Stdlib.result

Same as of_bytes_exn but doesn't raise.

val of_string_exn : ?off:int -> ?len:int -> 'a Decode.dec -> string -> 'a

Decode a value stored in the string. See of_bytes_exn for more details.

  • raises Decode.Error

    if decoding fails

val of_string : ?off:int -> ?len:int -> 'a Decode.dec -> string -> ('a, string) Stdlib.result

Safe version of of_string_exn

val to_string : 'a Encode.enc -> 'a -> string

Encode a value of type 'a into a string using the given encoder.