Kagome
Polkadot Runtime Engine in C++17
in_memory_storage.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STORAGE_IN_MEMORY_IN_MEMORY_STORAGE_HPP
7 #define KAGOME_STORAGE_IN_MEMORY_IN_MEMORY_STORAGE_HPP
8 
9 #include <memory>
10 
11 #include "common/buffer.hpp"
12 #include "outcome/outcome.hpp"
14 
15 namespace kagome::storage {
16 
23  public:
24  ~InMemoryStorage() override = default;
25 
26  outcome::result<common::Buffer> load(
27  const common::BufferView &key) const override;
28 
29  outcome::result<std::optional<common::Buffer>> tryLoad(
30  const common::BufferView &key) const override;
31 
32  outcome::result<void> put(const common::BufferView &key,
33  const common::Buffer &value) override;
34 
35  outcome::result<void> put(const common::BufferView &key,
36  common::Buffer &&value) override;
37 
38  outcome::result<bool> contains(
39  const common::BufferView &key) const override;
40 
41  bool empty() const override;
42 
43  outcome::result<void> remove(const common::BufferView &key) override;
44 
45  std::unique_ptr<
47  batch() override;
48 
49  std::unique_ptr<storage::BufferStorage::Cursor> cursor() override;
50 
51  size_t size() const override;
52 
53  private:
54  std::map<std::string, common::Buffer> storage;
55  size_t size_ = 0;
56  };
57 
58 } // namespace kagome::storage
59 
60 #endif // KAGOME_STORAGE_IN_MEMORY_IN_MEMORY_STORAGE_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
outcome::result< common::Buffer > load(const common::BufferView &key) const override
std::unique_ptr< storage::BufferStorage::Cursor > cursor() override
Returns new key-value iterator.
outcome::result< bool > contains(const common::BufferView &key) const override
std::map< std::string, common::Buffer > storage
~InMemoryStorage() override=default
outcome::result< std::optional< common::Buffer > > tryLoad(const common::BufferView &key) const override
bool empty() const override
Returns true if the storage is empty.
outcome::result< void > put(const common::BufferView &key, const common::Buffer &value) override
std::unique_ptr< kagome::storage::face::WriteBatch< common::BufferView, common::Buffer > > batch() override
Creates new Write Batch - an object, which can be used to efficiently write bulk data.