package lmdb

  1. Overview
  2. Docs

Converters to and from the internal representation of keys and values. A converter contains serialising and deserialising functions as well as the flags applied when the converter is used in a map.

Types

type 'a t

Bigstrings are used to transfer the raw serialised data into and out of the database. They may point directly to a memory-mapped region of the database file.

module Flags : sig ... end

Flags describing the (sorting) properties of keys and values of a map.

Constructor and accessors

val make : ?flags:Flags.t -> serialise:((int -> bigstring) -> 'a -> bigstring) -> deserialise:(bigstring -> 'a) -> unit -> 'a t

make ~serialise ~deserialise creates a converter from a serialising and a deserialising function

  • parameter serialise

    serialise alloc x may call alloc len once to allocate a bigstring of size len. It then must fill the serialised data of x into this bigstring and return exactly this bigstring. If serialise didn't call alloc it may return any bigstring. alloc may return uninitialised memory. It is therefore recommended that serialise overwrites all allocated memory to avoid leaking possibly sensitive memory content into the database.

    If serialise calls alloc the library may utilise the MDB_RESERVE interface when appropriate to avoid calls to malloc and memcpy.

  • parameter deserialise

    The passed bigstring is only valid as long as the current transaction. It is therefore strongly recommended not to leak it out of deserialise.

  • parameter flags

    Flags to be set on a map using this converter.

    Depending on the use of a converter as key or value Map.create and Map.open_existing will select the correct set of flags: _key flags will be used for keys and _dup flags will be used for values on maps supporting duplicates.

val serialise : 'a t -> (int -> bigstring) -> 'a -> bigstring
val deserialise : 'a t -> bigstring -> 'a
val flags : _ t -> Flags.t

Predefined converters

Strings

val bigstring : bigstring t

The bigstring converter returns bigstrings as returned by the lmdb backend. These bigstrings point into the environment memory-map and are therefore only guaranteed to be valid until the transaction ends. If you need longer-lived values then use the string converter, make a copy or write a custom converter.

val string : string t

The string converter simply copies the raw database content from / to OCaml strings.

Integers

The integer converters will make use of Flags.t as appropriate so that integers are sorted in ascending order irrespective of machine endianness.

val int32_be : Int32.t t
val int64_be : Int64.t t
val int32_le : Int32.t t
val int64_le : Int64.t t

For convenience, the _as_int converters convert the internal integer representation to and from int.

val int32_be_as_int : int t
val int64_be_as_int : int t
val int32_le_as_int : int t
val int64_le_as_int : int t
OCaml

Innovation. Community. Security.