From 56ee83a766f41bb193acc16ad2d1a29ebce2ffa8 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 18 Jan 2019 11:54:29 +0100 Subject: [PATCH] Add ReadDataStream to CDBWrapper to allow manual deserialization --- src/dbwrapper.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 500da83806..d016daf627 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -225,8 +225,8 @@ public: CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false); ~CDBWrapper(); - template - bool Read(const K& key, V& value) const + template + bool ReadDataStream(const K& key, CDataStream& ssValue) const { CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); @@ -241,9 +241,21 @@ public: LogPrintf("LevelDB read failure: %s\n", status.ToString()); dbwrapper_private::HandleError(status); } + CDataStream ssValueTmp(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION); + ssValueTmp.Xor(obfuscate_key); + ssValue = std::move(ssValueTmp); + return true; + } + + template + bool Read(const K& key, V& value) const + { + CDataStream ssValue(SER_DISK, CLIENT_VERSION); + if (!ReadDataStream(key, ssValue)) { + return false; + } + try { - CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION); - ssValue.Xor(obfuscate_key); ssValue >> value; } catch (const std::exception&) { return false;