Skip to content
Start free evaluation

pdcomm::Buffer

Class

Owned, immutable copy of a byte sequence.

class Buffer

Declared in: #include <pdcomm.hpp>

Buffer 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) noexcept

Declared in: #include <pdcomm.hpp>

Parameters

NameDescription
otherSource wrapper; it becomes empty and bytes() on it throws.

Buffer

Constructor

Copying is disabled; the wrapper exclusively owns its native handle.

Buffer(const Buffer &) = delete

Declared in: #include <pdcomm.hpp>

Buffer

Constructor

Copies length bytes from data into a new native buffer.

Buffer(const uint8_t *data, size_t length, size_t limit)

Declared in: #include <pdcomm.hpp>

Parameters

NameDescription
dataFirst byte to copy. May be nullptr only when length is 0.
lengthNumber of bytes to copy.
limitMaximum accepted length. This is application policy, not a protocol limit.

Notes

  • Throws pdcomm::Error: PDCOMM_INVALID_ARGUMENT when data is nullptr with a nonzero length; PDCOMM_LIMIT_EXCEEDED when length is larger than limit; PDCOMM_ALLOCATION_FAILED when memory runs out.

bytes

Method

Copies the buffer contents into a new vector.

std::vector<uint8_t> bytes() const

Declared in: #include <pdcomm.hpp>

Calls 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_ARGUMENT when this Buffer was moved from.

operator=

Method

Releases the current handle, then takes ownership of the handle owned by other.

Buffer &operator=(Buffer &&other) noexcept

Declared in: #include <pdcomm.hpp>

Parameters

NameDescription
otherSource 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

Declared in: #include <pdcomm.hpp>

~Buffer

Method

Releases the native handle with pdcomm_buffer_destroy().

~Buffer()

Declared in: #include <pdcomm.hpp>

A moved-from Buffer releases nothing.