refactor: Split dbwrapper CDBIterator::GetValue implementation

Keep the generic serialization in the header, while moving
leveldb-specifics to the implementation file.

The context of this commit is an effort to decouple the dbwrapper header
file from leveldb includes. To this end, the includes are moved to the
dbwrapper implementation file. This is done as part of the kernel
project to reduce the number of required includes for users of the
kernel.
pull/28186/head
TheCharlatan 1 year ago
parent b7a1ab5cb4
commit ef941ff128
No known key found for this signature in database
GPG Key ID: 9B79B45691DB4173

@ -317,6 +317,11 @@ Span<const std::byte> CDBIterator::GetKeyImpl() const
return MakeByteSpan(piter->key()); return MakeByteSpan(piter->key());
} }
Span<const std::byte> CDBIterator::GetValueImpl() const
{
return MakeByteSpan(piter->value());
}
CDBIterator::~CDBIterator() { delete piter; } CDBIterator::~CDBIterator() { delete piter; }
bool CDBIterator::Valid() const { return piter->Valid(); } bool CDBIterator::Valid() const { return piter->Valid(); }
void CDBIterator::SeekToFirst() { piter->SeekToFirst(); } void CDBIterator::SeekToFirst() { piter->SeekToFirst(); }

@ -16,7 +16,6 @@
#include <cstdint> #include <cstdint>
#include <exception> #include <exception>
#include <leveldb/db.h> #include <leveldb/db.h>
#include <leveldb/iterator.h>
#include <leveldb/options.h> #include <leveldb/options.h>
#include <leveldb/slice.h> #include <leveldb/slice.h>
#include <leveldb/status.h> #include <leveldb/status.h>
@ -27,6 +26,7 @@
#include <vector> #include <vector>
namespace leveldb { namespace leveldb {
class Env; class Env;
class Iterator;
} }
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
@ -142,6 +142,7 @@ private:
void SeekImpl(Span<const std::byte> ssKey); void SeekImpl(Span<const std::byte> ssKey);
Span<const std::byte> GetKeyImpl() const; Span<const std::byte> GetKeyImpl() const;
Span<const std::byte> GetValueImpl() const;
public: public:
@ -177,9 +178,8 @@ public:
} }
template<typename V> bool GetValue(V& value) { template<typename V> bool GetValue(V& value) {
leveldb::Slice slValue = piter->value();
try { try {
CDataStream ssValue{MakeByteSpan(slValue), SER_DISK, CLIENT_VERSION}; CDataStream ssValue{GetValueImpl(), SER_DISK, CLIENT_VERSION};
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent)); ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
ssValue >> value; ssValue >> value;
} catch (const std::exception&) { } catch (const std::exception&) {

Loading…
Cancel
Save