LeanLmdb.ValueCodec behaviour (lean_lmdb v0.3.0)

View Source

Behaviour for opt-in value serialization used by LeanLmdb.CodecDatabase.

Codec callbacks run in the caller process before or after a native call. The native LMDB layer continues to receive and return binaries only.

id/0 and version/0 describe the persisted format. IDs must be stable non-empty binaries no larger than 255 bytes. A decoder receives the version stored with each value so it can support explicit format migrations.

Stored bytes are untrusted input. Decoders must reject malformed versions, bound encoded input, and—especially for compression—enforce a finite decoded output limit before allocating expanded data. Callback errors and exceptions are normalized to stable LeanLmdb errors. LeanLmdb never selects a callback module from stored bytes.

Summary

Types

Runtime options retained by a codec database handle.

Types

options()

@type options() :: keyword()

Runtime options retained by a codec database handle.

Callbacks

decode(payload, stored_version, options)

@callback decode(payload :: binary(), stored_version :: non_neg_integer(), options()) ::
  {:ok, term()} | {:error, term()}

deterministic?()

@callback deterministic?() :: boolean()

encode(value, options)

@callback encode(value :: term(), options()) :: {:ok, binary()} | {:error, term()}

id()

@callback id() :: binary()

validate_options(options)

(optional)
@callback validate_options(options()) :: {:ok, options()} | {:error, term()}

version()

@callback version() :: non_neg_integer()