pdcomm::Buffer
Class
Owned, immutable copy of a byte sequence.
class BufferBuffer wraps a PdcommBuffer handle created by pdcomm_buffer_create(). The input bytes are copied at construction, so the source can change or be freed afterwards.
Notes
- Move-only. bytes() may run concurrently on one Buffer; destruction must not race with other calls.
Members
Buffer
Constructor
Takes ownership of the native handle owned by other.
Buffer(Buffer &&other) noexceptParameters
| Name | Description |
|---|---|
other | Source wrapper; it becomes empty and bytes() on it throws. |
Buffer
Constructor
Copying is disabled; the wrapper exclusively owns its native handle.
Buffer(const Buffer &) = deleteBuffer
Constructor
Copies length bytes from data into a new native buffer.
Buffer(const uint8_t *data, size_t length, size_t limit)Parameters
| Name | Description |
|---|---|
data | First byte to copy. May be nullptr only when length is 0. |
length | Number of bytes to copy. |
limit | Maximum accepted length. This is application policy, not a protocol limit. |
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhendataisnullptrwith a nonzerolength;PDCOMM_LIMIT_EXCEEDEDwhenlengthis larger thanlimit;PDCOMM_ALLOCATION_FAILEDwhen memory runs out.
bytes
Method
Copies the buffer contents into a new vector.
std::vector<uint8_t> bytes() constCalls pdcomm_buffer_copy() twice: first to read the length, then to copy.
Returns
A copy of the stored bytes; empty when the buffer holds no bytes.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhen this Buffer was moved from.
operator=
Method
Releases the current handle, then takes ownership of the handle owned by other.
Buffer &operator=(Buffer &&other) noexceptParameters
| Name | Description |
|---|---|
other | Source wrapper; it becomes empty. |
Returns
This wrapper.
operator=
Method
Copy assignment is disabled; the wrapper exclusively owns its native handle.
Buffer &operator=(const Buffer &) = delete~Buffer
Method
Releases the native handle with pdcomm_buffer_destroy().
~Buffer()A moved-from Buffer releases nothing.