package bitpack_serializer

  1. Overview
  2. Docs
On This Page
  1. Lenses
Legend:
Library
Module
Module type
Parameter
Class
Class type

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

Lenses

type 'a t

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

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

Writes in a buffer.

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

Reads from a buffer.

Basic lenses

val uint : size:int -> int64 t

A lens for unsigned int of fixed size.

val sint : int t

A lens for signed integers.

val zint : Z.t t

A lens for Zarith integers

val string : string t

A lens for strings.

val bytes : bytes t

A lens for unknown sized bytes.

val fixed_size_bytes : num_bytes:int -> bytes t

A lens for fixed sized bytes.

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

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

type 'a case

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

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

Builds a case for disjunctive lenses.

val 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.

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

Builds a self dependent lens.