Skip to content

sgns::storage::trie::SuperGeniusCodec

#include <supergenius_codec.hpp>

Inherits from sgns::storage::trie::Codec, IComponent

Public Types

Name
enum class Error
using sgns::base::Buffer Buffer

Public Functions

Name
~SuperGeniusCodec() override =default
virtual outcome::result< Buffer > encodeNode(const Node & node) const override
Encode node to byte representation.
virtual outcome::result< std::shared_ptr< Node > > decodeNode(const base::Buffer & encoded_data) const override
Decode node from bytes.
virtual base::Buffer merkleValue(const Buffer & buf) const override
Get the merkle value of a node.
virtual base::Hash256 hash256(const Buffer & buf) const override
Get the hash of a node.
virtual std::string GetName() override
outcome::result< Buffer > encodeHeader(const SuperGeniusNode & node) const
KeyNibbles keyToNibbles(const Buffer & key)
Buffer nibblesToKey(const KeyNibbles & nibbles)

Additional inherited members

Public Functions inherited from sgns::storage::trie::Codec

Name
~Codec() override =default

Public Functions inherited from IComponent

Name
virtual ~IComponent() =default

Public Types Documentation

enum Error

Enumerator Value Description
SUCCESS 0
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

using Buffer

using sgns::storage::trie::SuperGeniusCodec::Buffer = sgns::base::Buffer;

Public Functions Documentation

function ~SuperGeniusCodec

~SuperGeniusCodec() override =default

function encodeNode

virtual outcome::result< Buffer > encodeNode(
    const Node & node
) const override

Encode node to byte representation.

Parameters:

  • node node in the trie

Return: encoded representation of the node

Reimplements: sgns::storage::trie::Codec::encodeNode

function decodeNode

virtual outcome::result< std::shared_ptr< Node > > decodeNode(
    const base::Buffer & encoded_data
) const override

Decode node from bytes.

Parameters:

  • encoded_data a buffer containing encoded representation of a node

Return: a node in the trie

Reimplements: sgns::storage::trie::Codec::decodeNode

function merkleValue

virtual base::Buffer merkleValue(
    const Buffer & buf
) const override

Get the merkle value of a node.

Parameters:

  • buf byte representation of the node

Return: hash of the buffer, or the buffer itself if it is shorter than the hash

Reimplements: sgns::storage::trie::Codec::merkleValue

function hash256

virtual base::Hash256 hash256(
    const Buffer & buf
) const override

Get the hash of a node.

Parameters:

  • buf byte representation of the node

Return: hash of the buffer

Reimplements: sgns::storage::trie::Codec::hash256

function GetName

inline virtual std::string GetName() override

Reimplements: IComponent::GetName

function encodeHeader

outcome::result< Buffer > encodeHeader(
    const SuperGeniusNode & node
) const

See: Algorithm 3: partial key length encoding

Encodes a node header accroding to the specification

1 byte head

number of 255 in l

for last byte

fill array with 255

function keyToNibbles

static KeyNibbles keyToNibbles(
    const Buffer & key
)

Def. 14 KeyEncode Splits a key to an array of nibbles (a nibble is a half of a byte)

function nibblesToKey

static Buffer nibblesToKey(
    const KeyNibbles & nibbles
)

Collects an array of nibbles to a key


Updated on 2026-04-15 at 11:00:39 -0700