Pigweed
C/C++ API Reference
|
Classes | |
class | iterator |
Public Types | |
using | element_type = const std::byte |
using | value_type = std::byte |
using | pointer = std::byte * |
using | reference = std::byte & |
using | iterator = iterator |
using | const_iterator = iterator |
Public Member Functions | |
constexpr | ByteBuilder (ByteSpan buffer) |
Creates an empty ByteBuilder. | |
ByteBuilder (const ByteBuilder &)=delete | |
ByteBuilder & | operator= (const ByteBuilder &)=delete |
const std::byte * | data () const |
Returns the contents of the bytes buffer. | |
Status | status () const |
StatusWithSize | status_with_size () const |
Returns status() and size() as a StatusWithSize. | |
bool | ok () const |
True if status() is OkStatus(). | |
bool | empty () const |
True if the bytes builder is empty. | |
size_t | size () const |
Returns the current length of the bytes. | |
size_t | max_size () const |
Returns the maximum length of the bytes. | |
void | clear () |
Clears the bytes and resets its error state. | |
void | clear_status () |
Sets the statuses to OkStatus();. | |
void | push_back (std::byte b) |
void | pop_back () |
const_iterator | begin () const |
Root of bytebuffer wrapped in iterator type. | |
const_iterator | cbegin () const |
const_iterator | end () const |
End of bytebuffer wrapped in iterator type. | |
const_iterator | cend () const |
const std::byte & | front () const |
Front and Back C++ container functions. | |
const std::byte & | back () const |
ByteBuilder & | append (size_t count, std::byte b) |
Appends the provided byte count times. | |
ByteBuilder & | append (const void *bytes, size_t count) |
ByteBuilder & | append (ConstByteSpan bytes) |
Appends bytes from a byte span that calls the pointer/length version. | |
void | resize (size_t new_size) |
ByteBuilder & | PutUint8 (uint8_t val) |
Put methods for inserting different 8-bit ints. | |
ByteBuilder & | PutInt8 (int8_t val) |
ByteBuilder & | PutUint16 (uint16_t value, endian order=endian::little) |
Put methods for inserting different 16-bit ints. | |
ByteBuilder & | PutInt16 (int16_t value, endian order=endian::little) |
ByteBuilder & | PutUint32 (uint32_t value, endian order=endian::little) |
Put methods for inserting different 32-bit ints. | |
ByteBuilder & | PutInt32 (int32_t value, endian order=endian::little) |
ByteBuilder & | PutUint64 (uint64_t value, endian order=endian::little) |
Put methods for inserting different 64-bit ints. | |
ByteBuilder & | PutInt64 (int64_t value, endian order=endian::little) |
Protected Member Functions | |
constexpr | ByteBuilder (const ByteSpan &buffer, const ByteBuilder &other) |
Functions to support ByteBuffer copies. | |
void | CopySizeAndStatus (const ByteBuilder &other) |
ByteBuilder facilitates building bytes in a fixed-size buffer. BytesBuilders never overflow. Status is tracked for each operation and an overall status is maintained, which reflects the most recent error.
A ByteBuilder does not own the buffer it writes to. It can be used to write bytes to any buffer. The ByteBuffer template class, defined below, allocates a buffer alongside a ByteBuilder.
|
delete |
Disallow copy/assign to avoid confusion about where the bytes is actually stored. ByteBuffers may be copied into one another.
ByteBuilder & pw::ByteBuilder::append | ( | const void * | bytes, |
size_t | count | ||
) |
Appends count bytes from 'bytes' to the end of the ByteBuilder. If count exceeds the remaining space in the ByteBuffer, no bytes will be appended and the status is set to RESOURCE_EXHAUSTED.
|
inline |
Removes the last byte. Sets the status to OUT_OF_RANGE if the buffer is empty (in which case the unsigned overflow is intentional).
|
inline |
Appends a single byte. Sets the status to RESOURCE_EXHAUSTED if the byte cannot be added because the buffer is full.
void pw::ByteBuilder::resize | ( | size_t | new_size | ) |
Sets the ByteBuilder's size. This function only truncates; if new_size > size(), it sets status to OUT_OF_RANGE and does nothing.
|
inline |
Returns the ByteBuilder's status, which reflects the most recent error that occurred while updating the bytes. After an update fails, the status remains non-OK until it is cleared with clear() or clear_status().
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: No errors have occurred. * * RESOURCE_EXHAUSTED: Output to the ``ByteBuilder`` was truncated. * * INVALID_ARGUMENT: ``printf``-style formatting failed. * * OUT_OF_RANGE: An operation outside the buffer was attempted. * *