Kagome
Polkadot Runtime Engine in C++17
kagome::storage::trie::PolkadotCodec Class Reference

#include <polkadot_codec.hpp>

Inheritance diagram for kagome::storage::trie::PolkadotCodec:
Collaboration diagram for kagome::storage::trie::PolkadotCodec:

Public Types

enum  Error {
  Error::SUCCESS = 0, Error::TOO_MANY_NIBBLES, Error::UNKNOWN_NODE_TYPE, Error::INPUT_TOO_SMALL,
  Error::NO_NODE_VALUE
}
 
using Buffer = common::Buffer
 
using BufferView = common::BufferView
 
- Public Types inherited from kagome::storage::trie::Codec
using StoreChildren = std::function< outcome::result< void >(common::BufferView, common::Buffer &&)>
 

Public Member Functions

 ~PolkadotCodec () override=default
 
outcome::result< BufferencodeNodeAndStoreChildren (const Node &node, const StoreChildren &store_children) const override
 Encode node to byte representation and store children. More...
 
outcome::result< std::shared_ptr< Node > > decodeNode (gsl::span< const uint8_t > encoded_data) const override
 Decode node from bytes. More...
 
common::Buffer merkleValue (const BufferView &buf) const override
 Get the merkle value of a node. More...
 
bool isMerkleHash (const common::BufferView &buf) const override
 is this a hash of value, or value itself More...
 
common::Hash256 hash256 (const BufferView &buf) const override
 Get the hash of a node. More...
 
outcome::result< BufferencodeHeader (const TrieNode &node) const
 
- Public Member Functions inherited from kagome::storage::trie::Codec
virtual ~Codec ()=default
 
outcome::result< common::BufferencodeNode (const Node &node) const
 Encode node to byte representation. More...
 

Private Member Functions

outcome::result< BufferencodeBranch (const BranchNode &node, const StoreChildren &store_children) const
 
outcome::result< BufferencodeLeaf (const LeafNode &node) const
 
outcome::result< std::pair< TrieNode::Type, size_t > > decodeHeader (BufferStream &stream) const
 
outcome::result< KeyNibblesdecodePartialKey (size_t nibbles_num, BufferStream &stream) const
 
outcome::result< std::shared_ptr< Node > > decodeBranch (TrieNode::Type type, const KeyNibbles &partial_key, BufferStream &stream) const
 

Detailed Description

Definition at line 19 of file polkadot_codec.hpp.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
SUCCESS 
TOO_MANY_NIBBLES 

number of nibbles in key is >= 2**16

UNKNOWN_NODE_TYPE 

node type is unknown

INPUT_TOO_SMALL 

cannot decode a node, not enough bytes on input

NO_NODE_VALUE 

leaf node without value

Definition at line 24 of file polkadot_codec.hpp.

Constructor & Destructor Documentation

kagome::storage::trie::PolkadotCodec::~PolkadotCodec ( )
overridedefault

Member Function Documentation

outcome::result< std::shared_ptr< Node > > kagome::storage::trie::PolkadotCodec::decodeBranch ( TrieNode::Type  type,
const KeyNibbles partial_key,
BufferStream stream 
) const
private

Definition at line 338 of file polkadot_codec.cpp.

outcome::result< std::pair< TrieNode::Type, size_t > > kagome::storage::trie::PolkadotCodec::decodeHeader ( BufferStream stream) const
private

Definition at line 265 of file polkadot_codec.cpp.

outcome::result< std::shared_ptr< Node > > kagome::storage::trie::PolkadotCodec::decodeNode ( gsl::span< const uint8_t >  encoded_data) const
overridevirtual

Decode node from bytes.

Parameters
encoded_dataa buffer containing encoded representation of a node
Returns
a node in the trie

Implements kagome::storage::trie::Codec.

Definition at line 225 of file polkadot_codec.cpp.

outcome::result< KeyNibbles > kagome::storage::trie::PolkadotCodec::decodePartialKey ( size_t  nibbles_num,
BufferStream stream 
) const
private

Definition at line 317 of file polkadot_codec.cpp.

outcome::result< common::Buffer > kagome::storage::trie::PolkadotCodec::encodeBranch ( const BranchNode node,
const StoreChildren store_children 
) const
private

Definition at line 170 of file polkadot_codec.cpp.

outcome::result< common::Buffer > kagome::storage::trie::PolkadotCodec::encodeHeader ( const TrieNode node) const

Encodes a node header according to the specification

See also
Algorithm 3: partial key length encoding

Definition at line 103 of file polkadot_codec.cpp.

outcome::result< common::Buffer > kagome::storage::trie::PolkadotCodec::encodeLeaf ( const LeafNode node) const
private

Definition at line 210 of file polkadot_codec.cpp.

outcome::result< common::Buffer > kagome::storage::trie::PolkadotCodec::encodeNodeAndStoreChildren ( const Node node,
const StoreChildren store_children 
) const
overridevirtual

Encode node to byte representation and store children.

Parameters
nodenode in the trie
store_childrenchidren storer
Returns
encoded representation of a {
Parameters
node}

Implements kagome::storage::trie::Codec.

Definition at line 70 of file polkadot_codec.cpp.

common::Hash256 kagome::storage::trie::PolkadotCodec::hash256 ( const BufferView buf) const
overridevirtual

Get the hash of a node.

Parameters
bufbyte representation of the node
Returns
hash of
Parameters
buf

Implements kagome::storage::trie::Codec.

Definition at line 57 of file polkadot_codec.cpp.

bool kagome::storage::trie::PolkadotCodec::isMerkleHash ( const common::BufferView buf) const
overridevirtual

is this a hash of value, or value itself

Implements kagome::storage::trie::Codec.

Definition at line 51 of file polkadot_codec.cpp.

common::Buffer kagome::storage::trie::PolkadotCodec::merkleValue ( const BufferView buf) const
overridevirtual

Get the merkle value of a node.

Parameters
bufbyte representation of the node
Returns
hash of
Parameters
bufor
bufif it is shorter than the hash

Implements kagome::storage::trie::Codec.

Definition at line 40 of file polkadot_codec.cpp.


The documentation for this class was generated from the following files: