Kagome
Polkadot Runtime Engine in C++17
buffer_stream.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_STORAGE_TRIE_BUFFER_STREAM
7 #define KAGOME_CORE_STORAGE_TRIE_BUFFER_STREAM
8 
9 #include <gsl/span>
10 
11 #include "common/buffer.hpp"
12 
13 namespace kagome::storage::trie {
14 
19  class BufferStream {
20  using index_type = gsl::span<const uint8_t>::index_type;
21 
22  public:
23  explicit BufferStream(gsl::span<const uint8_t> buf) : data_{buf} {}
24 
25  bool hasMore(index_type num_bytes) const {
26  return data_.size() >= num_bytes;
27  }
28 
29  uint8_t next() {
30  auto byte = data_.at(0);
31  data_ = data_.last(data_.size() - 1);
32  return byte;
33  }
34 
35  gsl::span<const uint8_t> leftBytes() const {
36  return data_;
37  }
38 
39  private:
40  gsl::span<const uint8_t> data_;
41  };
42 } // namespace kagome::storage::trie
43 
44 #endif // KAGOME_CORE_STORAGE_TRIE_BUFFER_STREAM
gsl::span< const uint8_t > leftBytes() const
BufferStream(gsl::span< const uint8_t > buf)
bool hasMore(index_type num_bytes) const
gsl::span< const uint8_t > data_
gsl::span< const uint8_t >::index_type index_type