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.
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 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.
Given two lenses for two types, creates a lens for a pair of these types.
For creating a lens for disjunctions, we define the 'a case
type for the Lens.disj
function to build new lenses.
Builds a case for disjunctive lenses.
Creates a lens from an array of cases. Raises Failure
when reading or writing if no case matches the encoding.