Table of Contents

Delegate ValueDecoder<T>

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

Turns a value read from the database into a T, reading it in place.

public delegate T ValueDecoder<T>(ReadOnlySpan<byte> value)

Parameters

value ReadOnlySpan<byte>

The value, pointing into RocksDb's own memory. Valid only until the decoder returns: do not keep it, or anything that refers to it.

Returns

T

The decoded value.

Type Parameters

T

What the value decodes to.

Remarks

Used by TryGet<T>(ReadOnlySpan<byte>, ValueDecoder<T>, out T, ReadOptions?) and its counterparts, which read through a pinned slice so the value is never copied into a managed array. A static lambda is cached by the compiler, so passing one allocates nothing:

db.TryGet(key, static v => BinaryPrimitives.ReadInt64LittleEndian(v), out long counter);

A delegate rather than Func<ReadOnlySpan<byte>, T>, because a span cannot be a generic argument on every framework this library targets.