Module Lmdb.Conv
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 ttype bigstring= (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.tBigstrings 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 = Lmdb__.Lmdb_bindings.DbiFlagsFlags 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 tmake ~serialise ~deserialisecreates a converter from a serialising and a deserialising function- parameter serialise
serialise alloc xmay callalloc lenonce to allocate abigstringof sizelen. It then must fill the serialised data ofxinto thisbigstringand return exactly this bigstring. Ifserialisedidn't callallocit may return anybigstring.allocmay return uninitialised memory. It is therefore recommended thatserialiseoverwrites all allocated memory to avoid leaking possibly sensitive memory content into the database.If
serialisecallsallocthe library may utilise theMDB_RESERVEinterface when appropriate to avoid calls tomallocandmemcpy.
- parameter deserialise
The passed
bigstringis only valid as long as the current transaction. It is therefore strongly recommended not to leak it out ofdeserialise.
- parameter flags
Flags to be set on a map using this converter.
Depending on the use of a converter as key or value
Map.createandMap.open_existingwill select the correct set of flags:_keyflags will be used for keys and_dupflags will be used for values on maps supporting duplicates.
Predefined converters
Strings
val bigstring : bigstring tThe
bigstringconverter 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 thestringconverter, make a copy or write a custom converter.
val string : string tThe
stringconverter simply copies the raw database content from / to OCaml strings.