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

Buffer to store and retrieve byte data. More...

#include <buffer.hpp>

Public Member Functions

 buffer ()=default
 
auto size () const -> size_t
 Returns the number of bytes contained in the buffer.
 
auto data () -> void *
 Returns a raw pointer to the start of the buffer data.
 
auto data () const -> const void *
 Returns a raw pointer to the start of the buffer data.
 
auto data_at (size_t offset) -> void *
 Returns a raw pointer to the start of the buffer data.
 
auto data_at (size_t offset) const -> const void *
 Returns a raw pointer to the start of the packet data.
 
void append (const void *data, size_t len)
 Adds the given number of bytes from the given pointer to the end of the buffer.
 
void clear ()
 Removes any existing content in the buffer making its size 0.
 
auto operator== (const buffer &other) const -> bool
 
void extend (size_t len)
 Extends the size of the buffer by the given length.
 
auto c_ptr () const -> const unsigned char *
 Returns a pointer to the data, cast to an unsigned char*.
 
auto c_str () const -> const char *
 Returns a pointer to the data, cast to a char*.
 
auto to_hex () const -> std::string
 Returns a hex string representation of the contents of the buffer.
 
auto to_hex_prefixed (const std::string &prefix="0x") const -> std::string
 Returns a hex string representation of the contents of the buffer prefixed with a prefix sequence.
 

Static Public Member Functions

static auto from_hex (const std::string &hex) -> std::optional< cbdc::buffer >
 Creates a new buffer from the provided hex string.
 
static auto from_hex_prefixed (const std::string &hex, const std::string &prefix="0x") -> std::optional< buffer >
 Creates a new buffer from the provided hex string optionally prefixed with a prefix sequence.
 

Detailed Description

Buffer to store and retrieve byte data.

Definition at line 15 of file buffer.hpp.

Constructor & Destructor Documentation

◆ buffer()

cbdc::buffer::buffer ( )
default

Member Function Documentation

◆ append()

void cbdc::buffer::append ( const void * data,
size_t len )

Adds the given number of bytes from the given pointer to the end of the buffer.

Parameters
datapointer to the start of the data.
lenthe number of bytes to read.

Definition at line 18 of file buffer.cpp.

References data().

Here is the call graph for this function:

◆ c_ptr()

auto cbdc::buffer::c_ptr ( ) const -> const unsigned char*
nodiscard

Returns a pointer to the data, cast to an unsigned char*.

Returns
unsigned char pointer.

Definition at line 52 of file buffer.cpp.

◆ c_str()

auto cbdc::buffer::c_str ( ) const -> const char*
nodiscard

Returns a pointer to the data, cast to a char*.

Returns
char pointer.

Definition at line 57 of file buffer.cpp.

◆ clear()

void cbdc::buffer::clear ( )

Removes any existing content in the buffer making its size 0.

Definition at line 14 of file buffer.cpp.

Referenced by cbdc::rlp_value::assign(), and cbdc::rlp_value::read_from().

◆ data() [1/2]

auto cbdc::buffer::data ( ) -> void*
nodiscard

Returns a raw pointer to the start of the buffer data.

Returns
a pointer to the data.

Definition at line 28 of file buffer.cpp.

Referenced by cbdc::parsec::agent::runner::add_to_bloom(), append(), cbdc::rlp_value::assign(), cbdc::rlp_value::data(), cbdc::rlp_value::read_from(), and cbdc::rlp_value::value().

◆ data() [2/2]

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

Returns a raw pointer to the start of the buffer data.

Returns
a pointer to the data.

Definition at line 32 of file buffer.cpp.

◆ data_at() [1/2]

auto cbdc::buffer::data_at ( size_t offset) -> void*
nodiscard

Returns a raw pointer to the start of the buffer data.

Parameters
offsetthe byte offset into the buffer.
Returns
a pointer to the data.

Definition at line 36 of file buffer.cpp.

Referenced by cbdc::parsec::agent::runner::add_to_bloom().

◆ data_at() [2/2]

auto cbdc::buffer::data_at ( size_t offset) const -> const void*
nodiscard

Returns a raw pointer to the start of the packet data.

Parameters
offsetthe byte offset into the packet.
Returns
a pointer to the data.

Definition at line 40 of file buffer.cpp.

◆ extend()

void cbdc::buffer::extend ( size_t len)

Extends the size of the buffer by the given length.

Parameters
lenthe number of bytes to add.

Definition at line 48 of file buffer.cpp.

Referenced by cbdc::rlp_value::assign(), and cbdc::rlp_value::read_from().

◆ from_hex()

auto cbdc::buffer::from_hex ( const std::string & hex) -> std::optional<cbdc::buffer>
static

Creates a new buffer from the provided hex string.

Parameters
hexstring-encoded hex representation of this buffer.
Returns
a new buffer.

Definition at line 85 of file buffer.cpp.

References cbdc::buffer.

Referenced by cbdc::parsec::agent::runner::address_from_json(), cbdc::parsec::agent::runner::buffer_from_json(), importinput_command(), cbdc::parsec::agent::runner::mint_initial_accounts(), and cbdc::parsec::agent::runner::raw_tx_from_json().

◆ from_hex_prefixed()

auto cbdc::buffer::from_hex_prefixed ( const std::string & hex,
const std::string & prefix = "0x" ) -> std::optional<buffer>
static

Creates a new buffer from the provided hex string optionally prefixed with a prefix sequence.

Parameters
hexstring-encoded hex representation of this buffer.
prefixtext at start of hex string. Defaults to "0x".
Returns
a new buffer.

Definition at line 108 of file buffer.cpp.

Referenced by cbdc::parsec::agent::runner::from_hex(), and cbdc::parsec::agent::runner::uint256be_from_hex().

◆ operator==()

auto cbdc::buffer::operator== ( const buffer & other) const -> bool

Definition at line 44 of file buffer.cpp.

◆ size()

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

Returns the number of bytes contained in the buffer.

Returns
the number of bytes.

Definition at line 24 of file buffer.cpp.

Referenced by cbdc::parsec::agent::runner::add_to_bloom(), cbdc::buffer_serializer::end_of_buffer(), cbdc::rlp_value::size(), and cbdc::rlp_value::value().

◆ to_hex()

auto cbdc::buffer::to_hex ( ) const -> std::string
nodiscard

Returns a hex string representation of the contents of the buffer.

Returns
a hex encoded string.

Definition at line 62 of file buffer.cpp.

◆ to_hex_prefixed()

auto cbdc::buffer::to_hex_prefixed ( const std::string & prefix = "0x") const -> std::string
nodiscard

Returns a hex string representation of the contents of the buffer prefixed with a prefix sequence.

Returns
a hex encoded string.

Definition at line 77 of file buffer.cpp.


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