6#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_RLP_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_RLP_H_
16#include <evmc/evmc.hpp>
78 [[nodiscard]]
auto size()
const -> size_t;
87 [[nodiscard]]
auto data()
const ->
const void*;
93 [[nodiscard]]
auto value() const -> typename std::enable_if_t<
94 std::is_same<T, evmc::bytes32>::
value
95 || std::is_same<T, evmc::address>::
value,
99 buf.extend(
sizeof(res.bytes));
100 std::memcpy(buf.data_at(
sizeof(res.bytes) - m_buffer.
size()),
103 std::memcpy(&res.bytes, buf.data(), buf.size());
114 std::vector<rlp_value> m_values{};
129 if(trim_leading_zeroes) {
130 size_t start_idx = 0;
132 auto sz = pkt.size();
133 while(start_idx < sz) {
134 std::memcpy(&b, pkt.data_at(start_idx), 1);
135 if(b != std::byte(0)) {
142 buf.extend(sz - start_idx);
143 std::memcpy(buf.data(), pkt.data_at(start_idx), buf.size());
152 template<
typename... Args>
154 std::vector<rlp_value> vec = {values...};
156 for(
const auto& v : vec) {
188 -> std::optional<parsec::agent::runner::evm_access_list>;
196 auto operator<<(serializer& ser,
const rlp_value& v) -> serializer&;
Buffer to store and retrieve byte data.
auto data() -> void *
Returns a raw pointer to the start of the buffer data.
auto size() const -> size_t
Returns the number of bytes contained in the buffer.
This class contains a value that can be serialized into, or was deserialized from,...
void assign(const buffer &data)
Assigns the given data to the internal buffer of this rlp_value can only be used for rlp_value instan...
auto type() const -> rlp_value_type
Get the type of rlp_value.
void write_to(serializer &ser) const
Serializes the rlp_value in RLP representation into the passed serializer.
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 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:...
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.
auto data() const -> const void *
Returns a raw pointer to the start of the buffer data for rlp_value of type rlp_buffer.
auto size() const -> size_t
Get the size of the rlp_value.
rlp_value()
Default constructor. Sets m_type to rlp_value_type::buffer.
void read_from(serializer &ser)
Deserializes the rlp_value in RLP representation from the passed serializer into the current rlp_valu...
Interface for serializing objects into and out of raw bytes representations.
std::vector< evm_access_tuple > evm_access_list
Type alias for a list of storage key accesses.
auto rlp_decode_access_list(const rlp_value &rlp) -> std::optional< parsec::agent::runner::evm_access_list >
Decodes an access list from and rlp_value of type rlp_value_type::array.
auto serialize_size(size_t size) -> std::vector< std::byte >
Creates a binary representation for sizes that exceed the single-byte presentation.
auto rlp_encode_access_list(const parsec::agent::runner::evm_access_list &access_list) -> rlp_value
RLP encodes an access list.
auto make_rlp_value(const T &obj, bool trim_leading_zeroes=false) -> rlp_value
Turns an existing value into an rlp_value by first serializing it as a cbdc::buffer,...
auto operator>>(serializer &deser, parsec::agent::rpc::request &req) -> serializer &
rlp_value_type
Possible types for an RLP value.
@ buffer
A singular RLP value (byte array)
@ array
A collection of RLP values.
void serialize_rlp_length(serializer &ser, size_t len, unsigned char offset)
Serializes the passed len from the given offset as RLP compatible size representation as documented i...
auto deserialize_size(const cbdc::buffer &buf) -> size_t
Decodes a binary representation for sizes that exceed the single-byte presentation into size_t.
auto make_buffer(const T &obj) -> std::enable_if_t< std::is_same_v< B, nuraft::ptr< nuraft::buffer > >, nuraft::ptr< nuraft::buffer > >
Serialize object into nuraft::buffer using a cbdc::nuraft_serializer.
auto operator<<(serializer &ser, const parsec::agent::rpc::request &req) -> serializer &
auto make_rlp_array(const Args &... values) -> rlp_value
Turns multiple rlp_value objects into an rlp_value of type array.