Kagome
Polkadot Runtime Engine in C++17
codec.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_TRIE_CODEC_HPP
7 #define KAGOME_TRIE_CODEC_HPP
8 
9 #include "common/blob.hpp"
10 #include "common/buffer.hpp"
11 #include "storage/trie/node.hpp"
12 
13 namespace kagome::storage::trie {
18  class Codec {
19  public:
20  using StoreChildren = std::function<outcome::result<void>(
22 
23  virtual ~Codec() = default;
24 
31  virtual outcome::result<common::Buffer> encodeNodeAndStoreChildren(
32  const Node &node, const StoreChildren &store_children) const = 0;
33 
39  outcome::result<common::Buffer> encodeNode(const Node &node) const {
41  node, [](common::BufferView, common::Buffer &&) {
42  return outcome::success();
43  });
44  }
45 
51  virtual outcome::result<std::shared_ptr<Node>> decodeNode(
52  gsl::span<const uint8_t> encoded_data) const = 0;
53 
59  virtual common::Buffer merkleValue(const common::BufferView &buf) const = 0;
60 
64  virtual bool isMerkleHash(const common::BufferView &buf) const = 0;
65 
71  virtual common::Hash256 hash256(const common::BufferView &buf) const = 0;
72  };
73 
74 } // namespace kagome::storage::trie
75 
76 #endif // KAGOME_TRIE_CODEC_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
common::BufferView BufferView
virtual bool isMerkleHash(const common::BufferView &buf) const =0
is this a hash of value, or value itself
virtual outcome::result< common::Buffer > encodeNodeAndStoreChildren(const Node &node, const StoreChildren &store_children) const =0
Encode node to byte representation and store children.
virtual ~Codec()=default
outcome::result< common::Buffer > encodeNode(const Node &node) const
Encode node to byte representation.
Definition: codec.hpp:39
virtual common::Buffer merkleValue(const common::BufferView &buf) const =0
Get the merkle value of a node.
virtual common::Hash256 hash256(const common::BufferView &buf) const =0
Get the hash of a node.
Internal codec for nodes in the Trie. Eth and substrate have different codecs, but rest of the code s...
Definition: codec.hpp:18
virtual outcome::result< std::shared_ptr< Node > > decodeNode(gsl::span< const uint8_t > encoded_data) const =0
Decode node from bytes.
std::function< outcome::result< void >(common::BufferView, common::Buffer &&)> StoreChildren
Definition: codec.hpp:21