package bitpack_serializer

  1. Overview
  2. Docs

Module Bitpack_serializer.LensSource

Lenses are useful tools defining data-types encodings. Lenses provides in a single OCaml value equivalent serializes and deserializers.

Lenses

Sourcetype 'a t

The type of lenses. An 'a lens will provide symetical functions to read and write values of type 'a.

Sourceval write : 'a t -> Buffer.writer -> 'a -> unit

Writes in a buffer.

Sourceval read : 'a t -> Buffer.reader -> 'a

Reads from a buffer.

Basic lenses

Sourceval uint : size:int -> int64 t

A lens for unsigned int of fixed size.

Sourceval sint : int t

A lens for signed integers.

Sourceval zint : Z.t t

A lens for Zarith integers

Sourceval string : string t

A lens for strings.

Sourceval bytes : bytes t

A lens for unknown sized bytes.

Sourceval fixed_size_bytes : num_bytes:int -> bytes t

A lens for fixed sized bytes.

Sourceval conj : 'a t -> 'b t -> ('a * 'b) t

Given two lenses for two types, creates a lens for a pair of these types.

Sourcetype 'a case

For creating a lens for disjunctions, we define the 'a case type for the Lens.disj function to build new lenses.

Sourceval case : destruct:('a -> 'b option) -> construct:('b -> 'a) -> 'b t -> 'a case

Builds a case for disjunctive lenses.

Sourceval disj : 'a case array -> 'a t

Creates a lens from an array of cases. Raises Failure when reading or writing if no case matches the encoding.

Sourceval mu : ('a t -> 'a t) -> 'a t

Builds a self dependent lens.

OCaml

Innovation. Community. Security.