Kagome
Polkadot Runtime Engine in C++17
rocksdb_cursor.cpp
Go to the documentation of this file.
1 
7 
8 #include "rocksdb_util.hpp"
9 
10 namespace kagome::storage {
11 
12  RocksDBCursor::RocksDBCursor(std::shared_ptr<rocksdb::Iterator> it)
13  : i_{std::move(it)} {}
14 
15  outcome::result<bool> RocksDBCursor::seekFirst() {
16  i_->SeekToFirst();
17  return isValid();
18  }
19 
20  outcome::result<bool> RocksDBCursor::seek(const BufferView &key) {
21  i_->Seek(make_slice(key));
22  return isValid();
23  }
24 
25  outcome::result<bool> RocksDBCursor::seekLast() {
26  i_->SeekToLast();
27  return isValid();
28  }
29 
30  bool RocksDBCursor::isValid() const {
31  return i_->Valid();
32  }
33 
34  outcome::result<void> RocksDBCursor::next() {
35  i_->Next();
36  return outcome::success();
37  }
38 
39  std::optional<Buffer> RocksDBCursor::key() const {
40  return isValid() ? std::make_optional(make_buffer(i_->key()))
41  : std::nullopt;
42  }
43 
44  std::optional<Buffer> RocksDBCursor::value() const {
45  return isValid() ? std::make_optional(make_buffer(i_->value()))
46  : std::nullopt;
47  }
48 } // namespace kagome::storage
outcome::result< void > next() override
Make step forward.
outcome::result< bool > seekLast() override
Same as std::rbegin(...);, e.g. points to the last valid element.
outcome::result< bool > seek(const BufferView &key) override
rocksdb::Slice make_slice(const common::BufferView &buf)
common::Buffer make_buffer(const rocksdb::Slice &s)
std::optional< Buffer > value() const override
Getter for value of the element currently pointed at.
outcome::result< bool > seekFirst() override
Same as std::begin(...);.
bool isValid() const override
Is the cursor in a valid state?
std::shared_ptr< rocksdb::Iterator > i_
std::optional< Buffer > key() const override
Getter for the key of the element currently pointed at.
RocksDBCursor(std::shared_ptr< rocksdb::Iterator > it)