sgns::storage::Buffer¶
Class represents arbitrary (including empty) byte buffer.
#include <buffer.hpp>
Inherits from boost::equality_comparable< Buffer >, boost::equality_comparable< gsl::span< uint8_t > >, boost::equality_comparable< std::vector< uint8_t > >
Inherited by sgns::storage::trie::KeyNibbles
Public Types¶
| Name | |
|---|---|
| using std::vector< uint8_t >::iterator | iterator |
| using std::vector< uint8_t >::reverse_iterator | reverse_iterator |
| using std::vector< uint8_t >::const_reverse_iterator | const_reverse_iterator |
| using std::vector< uint8_t >::const_iterator | const_iterator |
| using uint8_t | value_type |
| using typename std::vector< uint8_t >::pointer | pointer |
| using typename std::vector< uint8_t >::const_pointer | const_pointer |
Public Functions¶
| Name | |
|---|---|
| Buffer(size_t size, uint8_t byte) Allocates a buffer of the given size, filled with a byte value. |
|
| Buffer(std::vector< uint8_t > v) lvalue construct buffer from a byte vector |
|
| Buffer(gsl::span< const uint8_t > s) | |
| Buffer(const uint8_t * begin, const uint8_t * end) | |
| Buffer() =default | |
| Buffer(const Buffer & b) =default | |
| Buffer(Buffer && b) =default | |
| Buffer(std::initializer_list< uint8_t > b) | |
| ~Buffer() =default | |
| Buffer & | reserve(size_t size) |
| Buffer & | resize(size_t size) |
| Buffer & | operator=(const Buffer & other) =default |
| Buffer & | operator=(Buffer && other) =default |
| Buffer & | operator+=(const Buffer & other) |
| uint8_t | operator[](size_t index) const Accessor of byte elements given an index in the byte array. |
| uint8_t & | operator[](size_t index) Accessor of byte elements given an index in the byte array. |
| bool | operator==(const Buffer & b) const Lexicographical comparison of two buffers. |
| bool | operator==(const std::vector< uint8_t > & b) const Lexicographical comparison of buffer and vector of bytes. |
| bool | operator==(gsl::span< const uint8_t > s) const Lexicographical comparison of buffer and vector of bytes. |
| bool | operator<(const Buffer & b) const Lexicographical comparison of two buffers. |
| iterator | begin() Iterator, which points to begin of this buffer. |
| const_iterator | begin() const Iterator, which points to begin of this buffer. |
| iterator | end() Iterator, which points to the element next to the last in this buffer. |
| const_iterator | end() const Iterator, which points to the element next to the last in this buffer. |
| reverse_iterator | rbegin() Iterator, which points to last of this buffer. |
| const_reverse_iterator | rbegin() const Iterator, which points to last of this buffer. |
| reverse_iterator | rend() Iterator, which points to the element previous to first in this buffer. |
| const_reverse_iterator | rend() const Iterator, which points to the element previous to first in this buffer. |
| size_t | size() const Getter for size of this buffer. |
| Buffer & | putUint8(uint8_t n) Put an 8-bit value into this buffer. |
| Buffer & | putUint32(uint32_t n) Put a 32-bit value into this buffer. |
| Buffer & | putUint64(uint64_t n) Put a 64-bit value into this buffer. |
| Buffer & | put(std::string_view str) Put a string into the byte buffer. |
| Buffer & | put(const std::vector< uint8_t > & v) Put a vector of bytes into the byte buffer. |
| Buffer & | put(gsl::span< const uint8_t > s) Put a sequence of bytes into the byte buffer. |
| Buffer & | putBytes(const uint8_t * begin, const uint8_t * end) Put an array of bytes bounded by pointers into the byte buffer. |
| Buffer & | putBuffer(const Buffer & buf) Put another buffer content at the end of current one. |
| void | clear() |
| const uint8_t * | data() const getter for raw array of bytes |
| uint8_t * | data() |
| const std::vector< uint8_t > & | toVector() const getter for vector of bytes |
| std::vector< uint8_t > & | toVector() |
| Buffer | subbuffer(size_t offset =0, size_t length =-1) const |
| std::string | toHex() const encode bytearray as hex |
| bool | empty() const |
| std::string_view | toString() const return content of bytearray as string |
| outcome::result< Buffer > | fromHex(std::string_view hex) Construct Buffer from hex string. |
Public Types Documentation¶
using iterator¶
using reverse_iterator¶
using const_reverse_iterator¶
using const_iterator¶
using value_type¶
using pointer¶
using const_pointer¶
Public Functions Documentation¶
function Buffer¶
Allocates a buffer of the given size, filled with a byte value.
Parameters:
function Buffer¶
lvalue construct buffer from a byte vector
function Buffer¶
function Buffer¶
function Buffer¶
function Buffer¶
function Buffer¶
function Buffer¶
function ~Buffer¶
function reserve¶
function resize¶
function operator=¶
function operator=¶
function operator+=¶
function operator[]¶
Accessor of byte elements given an index in the byte array.
Parameters:
- index Element index.
function operator[]¶
Accessor of byte elements given an index in the byte array.
Parameters:
- index Element index.
function operator==¶
Lexicographical comparison of two buffers.
function operator==¶
Lexicographical comparison of buffer and vector of bytes.
function operator==¶
Lexicographical comparison of buffer and vector of bytes.
function operator<¶
Lexicographical comparison of two buffers.
function begin¶
Iterator, which points to begin of this buffer.
function begin¶
Iterator, which points to begin of this buffer.
function end¶
Iterator, which points to the element next to the last in this buffer.
function end¶
Iterator, which points to the element next to the last in this buffer.
function rbegin¶
Iterator, which points to last of this buffer.
function rbegin¶
Iterator, which points to last of this buffer.
function rend¶
Iterator, which points to the element previous to first in this buffer.
function rend¶
Iterator, which points to the element previous to first in this buffer.
function size¶
Getter for size of this buffer.
function putUint8¶
Put an 8-bit value into this buffer.
Parameters:
- n Value to append.
Return: This buffer, suitable for chaining.
function putUint32¶
Put a 32-bit value into this buffer.
Parameters:
- n Value to append (serialized as big-endian).
Return: This buffer, suitable for chaining.
function putUint64¶
Put a 64-bit value into this buffer.
Parameters:
- n Value to append (serialized as big-endian).
Return: This buffer, suitable for chaining.
function put¶
Put a string into the byte buffer.
Parameters:
- str Arbitrary string.
Return: This buffer, suitable for chaining.
function put¶
Put a vector of bytes into the byte buffer.
Parameters:
- v Arbitrary vector of bytes.
Return: This buffer, suitable for chaining.
function put¶
Put a sequence of bytes into the byte buffer.
Parameters:
- s Arbitrary span of bytes.
Return: This buffer, suitable for chaining.
function putBytes¶
Put an array of bytes bounded by pointers into the byte buffer.
Parameters:
Return: This buffer, suitable for chaining.
function putBuffer¶
Put another buffer content at the end of current one.
Parameters:
- buf another buffer
Return: this buffer suitable for chaining.
function clear¶
Clear the contents of the Buffer
function data¶
getter for raw array of bytes
function data¶
function toVector¶
getter for vector of bytes
function toVector¶
function subbuffer¶
Returns a copy of a part of the buffer Works alike subspan() of gsl::span
function toHex¶
encode bytearray as hex
Return: hex-encoded string
function empty¶
Return: true, if buffer is empty, false otherwise
Check if this buffer is empty
function toString¶
return content of bytearray as string
Return: string
Note: Does not ensure correct encoding
function fromHex¶
Construct Buffer from hex string.
Parameters:
- hex hex-encoded string
Return: result containing constructed buffer if input string is hex-encoded string.
Updated on 2026-03-04 at 13:10:44 -0800