6#ifndef OPENCBDC_TX_SRC_COMMON_BUFFER_H_
7#define OPENCBDC_TX_SRC_COMMON_BUFFER_H_
21 [[nodiscard]]
auto size() const ->
size_t;
25 [[nodiscard]] auto
data() ->
void*;
29 [[nodiscard]] auto
data() const -> const
void*;
34 [[nodiscard]] auto
data_at(
size_t offset) ->
void*;
39 [[nodiscard]] auto
data_at(
size_t offset) const -> const
void*;
50 auto operator==(const
buffer& other) const ->
bool;
58 [[nodiscard]] auto
c_ptr() const -> const
unsigned char*;
62 [[nodiscard]] auto
c_str() const -> const
char*;
67 static auto
from_hex(const std::
string& hex)
72 [[nodiscard]] auto
to_hex() const -> std::
string;
80 const std::
string& prefix = "0x")
87 = "0x") const -> std::
string;
90 std::vector<std::
byte> m_data{};
Buffer to store and retrieve byte data.
auto data() -> void *
Returns a raw pointer to the start of the buffer data.
void clear()
Removes any existing content in the buffer making its size 0.
static auto from_hex(const std::string &hex) -> std::optional< cbdc::buffer >
Creates a new buffer from the provided hex string.
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.
auto c_str() const -> const char *
Returns a pointer to the data, cast to a char*.
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 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*.
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.
auto to_hex() const -> std::string
Returns a hex string representation of the contents of the buffer.
auto size() const -> size_t
Returns the number of bytes contained in the buffer.
auto data_at(size_t offset) -> void *
Returns a raw pointer to the start of the buffer data.