Electroneum
Loading...
Searching...
No Matches
lmdb::stream Namespace Reference

Functions

mdb_size_t count (MDB_cursor *cur)
std::pair< epee::span< const std::uint8_t >, epee::span< const std::uint8_t > > get (MDB_cursor &cur, MDB_cursor_op op, std::size_t key, std::size_t value)

Function Documentation

◆ count()

mdb_size_t lmdb::stream::count ( MDB_cursor * cur)

Definition at line 39 of file value_stream.cpp.

40 {
41 mdb_size_t out = 0;
42 if (cur)
43 {
44 const int rc = mdb_cursor_count(cur, &out);
45 if (rc)
46 ELECTRONEUM_THROW(lmdb::error(rc), "mdb_cursor_count");
47 }
48 return out;
49 }
#define ELECTRONEUM_THROW(code, msg)
Definition expect.h:66
int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp)
Return count of duplicates for current key.
size_t mdb_size_t
Definition lmdb.h:196
error
Tracks LMDB error codes.
Definition error.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

std::pair< epee::span< const std::uint8_t >, epee::span< const std::uint8_t > > lmdb::stream::get ( MDB_cursor & cur,
MDB_cursor_op op,
std::size_t key,
std::size_t value )

Calls mdb_cursor_get and does some error checking.

Parameters
curis given to mdb_cursor_get without modification.
opis passed to mdb_cursor_get without modification.
keyexpected key size or 0 to skip key size check.
valueexpected value size or 0 to skip value size check.
Exceptions
std::system_errorif key != 0 and key_.mv_size != key.
std::system_errorif value != 0 and value_.mv_size != value.
std::system_errorif mdb_cursor_get returns any error other than MDB_NOTFOUND.
Returns
{key bytes, value bytes} or two empty spans if MDB_NOTFOUND.

Definition at line 52 of file value_stream.cpp.

53 {
54 MDB_val key_bytes{};
55 MDB_val value_bytes{};
56 const int rc = mdb_cursor_get(&cur, &key_bytes, &value_bytes, op);
57 if (rc)
58 {
59 if (rc == MDB_NOTFOUND)
60 return {};
61 ELECTRONEUM_THROW(lmdb::error(rc), "mdb_cursor_get");
62 }
63
64 if (key && key != key_bytes.mv_size)
65 ELECTRONEUM_THROW(lmdb::error(MDB_BAD_VALSIZE), "mdb_cursor_get key");
66
67 if (value && (value_bytes.mv_size % value != 0 || value_bytes.mv_size == 0))
68 ELECTRONEUM_THROW(lmdb::error(MDB_BAD_VALSIZE), "mdb_cursor_get value");
69
70 return {lmdb::to_byte_span(key_bytes), lmdb::to_byte_span(value_bytes)};
71 }
#define MDB_BAD_VALSIZE
Definition lmdb.h:480
#define MDB_NOTFOUND
Definition lmdb.h:439
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
size_t mv_size
Definition lmdb.h:287
const char * key
constexpr epee::span< const std::uint8_t > to_byte_span(MDB_val value) noexcept
Definition util.h:97
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
Generic structure used for passing keys and data in and out of the database.
Definition lmdb.h:286
Here is the call graph for this function:
Here is the caller graph for this function: