| 93 | |
| 94 | template <typename K, typename V> |
| 95 | bool Read(const K& key, V& value) const |
| 96 | { |
| 97 | CDataStream ssKey(SER_DISK, CLIENT_VERSION); |
| 98 | ssKey.reserve(ssKey.GetSerializeSize(key)); |
| 99 | ssKey << key; |
| 100 | leveldb::Slice slKey(ssKey.data(), ssKey.size()); |
| 101 | |
| 102 | std::string strValue; |
| 103 | leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); |
| 104 | if (!status.ok()) { |
| 105 | if (status.IsNotFound()) |
| 106 | return false; |
| 107 | LogPrintf("LevelDB read failure: %s\n", status.ToString()); |
| 108 | HandleError(status); |
| 109 | } |
| 110 | try { |
| 111 | CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION); |
| 112 | ssValue >> value; |
| 113 | } catch (const std::exception&) { |
| 114 | return false; |
| 115 | } |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | template <typename K, typename V> |
| 120 | bool Write(const K& key, const V& value, bool fSync = false) |
nothing calls this directly
no test coverage detected