pabigot
0.1.1
C++ support classes
|
Infrastructure to fill an octet buffer with data. More...
#include </mnt/devel/pabigot-cxx/include/pabigot/byteorder.hpp>
Public Types | |
using | size_type = std::size_t |
Type used for span values. | |
Public Member Functions | |
octets_helper (uint8_t *begin, uint8_t *end) | |
Reference an octet range into which data will be written. More... | |
octets_helper (uint8_t *begin, size_type count) | |
Reference an octet sequence into which data will be written. More... | |
void | reset () noexcept |
Remove all content from the buffer. More... | |
const bool | valid () const noexcept |
Indicates whether advance() caused an error. More... | |
void | invalidate () noexcept |
Explicitly mark the buffer invalid. More... | |
const void * | begin () const noexcept |
Get a pointer to the start of buffer. More... | |
const void * | end () const noexcept |
Get a pointer to the end of the filled part of the buffer. More... | |
const size_type | size () const noexcept |
Number of octets stored in the buffer. More... | |
const size_type | available () const noexcept |
Number of unused octets available in the buffer. More... | |
const size_type | max_size () const noexcept |
Maximum number of octets supported by the buffer. | |
void * | advance (size_type s) noexcept |
Allocate a region and return a pointer to it or a nullptr if the advance went too far. More... | |
bool | can_advance (size_type s) const noexcept |
Indicate whether advance() would succeed for a given span. More... | |
bool | append (const void *sp, size_type span) noexcept |
Append a value to the buffer. More... | |
template<typename T > | |
bool | append (const T &value) noexcept |
Append a value to the buffer. More... | |
template<typename T > | |
bool | append_be (const T &value) noexcept |
As with append() but stores the value converted to big-endian byte order. | |
template<typename T > | |
bool | append_le (const T &value) noexcept |
As with append() but stores the value converted to little-endian byte order. | |
Protected Attributes | |
uint8_t *const | begin_ |
uint8_t *const | end_ |
uint8_t * | bp_ = nullptr |
Friends | |
class | oob_helper |
Infrastructure to fill an octet buffer with data.
This allows safe invocation for as much data is desired, allowing overrun detection at the end rather than on each addition.
|
inline |
Reference an octet range into which data will be written.
begin | pointer to the first octet in the sequence. |
end | pointer just past the last octet available for the sequence. |
|
inline |
Reference an octet sequence into which data will be written.
begin | pointer to the first octet in the sequence. |
count | the number of octets in the sequence. |
|
inlinenoexcept |
Allocate a region and return a pointer to it or a nullptr if the advance went too far.
s | the number of octets required. |
s
octets. The pointer is null (and valid() will now return false) if the buffer had already become invalid, or did so as a result of advancing by s
.
|
inlinenoexcept |
Append a value to the buffer.
The byte-order of the value is native. If a non-native order is required use append_le() or append_be(), or use host_x_le() or host_x_be() on the argument.
T | the underlying type of the value. |
value | the value to append. |
|
inlinenoexcept |
|
inlinenoexcept |
Number of unused octets available in the buffer.
|
inlinenoexcept |
Get a pointer to the start of buffer.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Explicitly mark the buffer invalid.
This might be used by subclasses that use a more piece-wise conception of whether an allocation will fit.
|
inlinenoexcept |
Remove all content from the buffer.
After this valid() will be true
, the buffer will be zeroed, and the next write will begin at the buffer start.
|
inlinenoexcept |
Number of octets stored in the buffer.
|
inlinenoexcept |
Indicates whether advance() caused an error.
false
iff advance() was invoked to reserve more space than was available or invalidate() was called since the last reset().