OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::rlp_value Class Reference

This class contains a value that can be serialized into, or was deserialized from, a Recursive Length Prefix (RLP) encoded representation. More...

#include <rlp.hpp>

Public Member Functions

 rlp_value ()
 Default constructor. Sets m_type to rlp_value_type::buffer.
 
 rlp_value (rlp_value_type type)
 Constructor.
 
 rlp_value (const buffer &data)
 Constructs an RLP value of type rlp_value_type::buffer and assigns the given data to its internal buffer.
 
void assign (const buffer &data)
 Assigns the given data to the internal buffer of this rlp_value can only be used for rlp_value instances of type rlp_value_type::buffer.
 
auto push_back (const rlp_value &val) -> bool
 Pushes an rlp_value into an rlp_value of type rlp_value_type::array You can push both rlp_value_type::buffer and rlp_value_type::array.
 
void write_to (serializer &ser) const
 Serializes the rlp_value in RLP representation into the passed serializer.
 
void read_from (serializer &ser)
 Deserializes the rlp_value in RLP representation from the passed serializer into the current rlp_value instance.
 
auto value_at (size_t idx) const -> rlp_value
 Returns the rlp_value at the given index for RLP values of type rlp_value_type::array.
 
auto size () const -> size_t
 Get the size of the rlp_value.
 
auto type () const -> rlp_value_type
 Get the type of rlp_value.
 
auto data () const -> const void *
 Returns a raw pointer to the start of the buffer data for rlp_value of type rlp_buffer.
 
template<typename T >
auto value () const -> typename std::enable_if_t< std::is_same< T, evmc::bytes32 >::value||std::is_same< T, evmc::address >::value, T >
 Return RLP value as address or byte array.
 

Detailed Description

This class contains a value that can be serialized into, or was deserialized from, a Recursive Length Prefix (RLP) encoded representation.

Definition at line 32 of file rlp.hpp.

Constructor & Destructor Documentation

◆ rlp_value() [1/3]

cbdc::rlp_value::rlp_value ( )

Default constructor. Sets m_type to rlp_value_type::buffer.

Definition at line 9 of file rlp.cpp.

◆ rlp_value() [2/3]

cbdc::rlp_value::rlp_value ( rlp_value_type type)
explicit

Constructor.

Parameters
typeThe type of RLP value to be constructed

Definition at line 10 of file rlp.cpp.

◆ rlp_value() [3/3]

cbdc::rlp_value::rlp_value ( const buffer & data)
explicit

Constructs an RLP value of type rlp_value_type::buffer and assigns the given data to its internal buffer.

Parameters
dataThe data to be assigned to the internal buffer

Definition at line 11 of file rlp.cpp.

References assign(), and data().

Here is the call graph for this function:

Member Function Documentation

◆ assign()

void cbdc::rlp_value::assign ( const buffer & data)

Assigns the given data to the internal buffer of this rlp_value can only be used for rlp_value instances of type rlp_value_type::buffer.

Parameters
dataThe data to be assigned to the internal buffer

Definition at line 14 of file rlp.cpp.

References cbdc::buffer::clear(), cbdc::buffer::data(), data(), and cbdc::buffer::extend().

Referenced by rlp_value().

Here is the call graph for this function:

◆ data()

auto cbdc::rlp_value::data ( ) const -> const void*
nodiscard

Returns a raw pointer to the start of the buffer data for rlp_value of type rlp_buffer.

Returns
a pointer to the data

Definition at line 31 of file rlp.cpp.

References cbdc::buffer::data().

Referenced by assign(), and rlp_value().

Here is the call graph for this function:

◆ push_back()

auto cbdc::rlp_value::push_back ( const rlp_value & val) -> bool

Pushes an rlp_value into an rlp_value of type rlp_value_type::array You can push both rlp_value_type::buffer and rlp_value_type::array.

Parameters
valThe rlp_value to append to the end of the array
Returns
true on success, false if the rlp_value is of the wrong type

Definition at line 19 of file rlp.cpp.

References cbdc::array.

◆ read_from()

void cbdc::rlp_value::read_from ( serializer & ser)

Deserializes the rlp_value in RLP representation from the passed serializer into the current rlp_value instance.

Parameters
serSerializer instance to read the RLP value from

Definition at line 10 of file rlp_reader.cpp.

References cbdc::buffer, cbdc::buffer::clear(), cbdc::buffer::data(), cbdc::deserialize_size(), cbdc::buffer::extend(), and cbdc::serializer::read().

Here is the call graph for this function:

◆ size()

auto cbdc::rlp_value::size ( ) const -> size_t
nodiscard

Get the size of the rlp_value.

Returns
size of the buffer for rlp_value of type rlp_value_type::buffer, or the number of items in the array for rlp_value of type rlp_value_type::array

Definition at line 35 of file rlp.cpp.

References cbdc::array, and cbdc::buffer::size().

Here is the call graph for this function:

◆ type()

auto cbdc::rlp_value::type ( ) const -> rlp_value_type
nodiscard

Get the type of rlp_value.

Returns
type of the rlp_value

Definition at line 42 of file rlp.cpp.

◆ value()

template<typename T >
auto cbdc::rlp_value::value ( ) const -> typename std::enable_if_t< std::is_same<T, evmc::bytes32>::value || std::is_same<T, evmc::address>::value, T>
inlinenodiscard

Return RLP value as address or byte array.

Template Parameters
addressor byte array type.
Returns
byte array or address.

Definition at line 93 of file rlp.hpp.

References cbdc::buffer, cbdc::buffer::data(), and cbdc::buffer::size().

Here is the call graph for this function:

◆ value_at()

auto cbdc::rlp_value::value_at ( size_t idx) const -> rlp_value
nodiscard

Returns the rlp_value at the given index for RLP values of type rlp_value_type::array.

Parameters
idxthe index in the array
Returns
the RLP value at that index

Definition at line 27 of file rlp.cpp.

◆ write_to()

void cbdc::rlp_value::write_to ( serializer & ser) const

Serializes the rlp_value in RLP representation into the passed serializer.

Parameters
serSerializer instance to write the RLP value to

Definition at line 10 of file rlp_writer.cpp.

References cbdc::buffer.


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