OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
rlp.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "rlp.hpp"
7
8namespace cbdc {
10 rlp_value::rlp_value(rlp_value_type type) : m_type(type) {}
12 assign(data);
13 }
14 void rlp_value::assign(const buffer& data) {
15 m_buffer.clear();
16 m_buffer.extend(data.size());
17 std::memcpy(m_buffer.data(), data.data(), data.size());
18 }
19 auto rlp_value::push_back(const rlp_value& val) -> bool {
20 auto ret = (m_type == rlp_value_type::array);
21 if(ret) {
22 m_values.push_back(val);
23 }
24 return ret;
25 }
26
27 auto rlp_value::value_at(size_t idx) const -> rlp_value {
28 return m_values.at(idx);
29 }
30
31 auto rlp_value::data() const -> const void* {
32 return m_buffer.data();
33 }
34
35 auto rlp_value::size() const -> size_t {
36 if(m_type == rlp_value_type::array) {
37 return m_values.size();
38 }
39 return m_buffer.size();
40 }
41
43 return m_type;
44 }
45}
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
auto data() -> void *
Returns a raw pointer to the start of the buffer data.
Definition buffer.cpp:28
void clear()
Removes any existing content in the buffer making its size 0.
Definition buffer.cpp:14
void extend(size_t len)
Extends the size of the buffer by the given length.
Definition buffer.cpp:48
auto size() const -> size_t
Returns the number of bytes contained in the buffer.
Definition buffer.cpp:24
This class contains a value that can be serialized into, or was deserialized from,...
Definition rlp.hpp:32
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...
Definition rlp.cpp:14
auto type() const -> rlp_value_type
Get the type of rlp_value.
Definition rlp.cpp:42
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.
Definition rlp.cpp:27
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:...
Definition rlp.cpp:19
auto data() const -> const void *
Returns a raw pointer to the start of the buffer data for rlp_value of type rlp_buffer.
Definition rlp.cpp:31
auto size() const -> size_t
Get the size of the rlp_value.
Definition rlp.cpp:35
rlp_value()
Default constructor. Sets m_type to rlp_value_type::buffer.
Definition rlp.cpp:9
rlp_value_type
Possible types for an RLP value.
Definition rlp.hpp:22
@ array
A collection of RLP values.