33template <
typename SIZE_TYPE>
37 static constexpr size_t SIZE_UNDEF = std::numeric_limits<size_t>::max();
95 const unsigned char *data = buf.
read_alloc(needed);
119 throw packet_not_fully_formed();
134 buf.
prepend((
const unsigned char *)&net_len,
sizeof(net_len));
162 result = htons(numeric_cast<std::uint16_t>(value));
167 result = htonl(numeric_cast<std::uint32_t>(value));
184 return buf.
size() >=
sizeof(SIZE_TYPE);
190 buf.
read((
unsigned char *)&net_len,
sizeof(net_len));
199 throw embedded_packet_size_error();
209template <
typename SIZE_TYPE>
void clear()
Clears the contents of the buffer.
void swap(BufferAllocatedType< T_ > &other)
Swaps the contents of this BufferAllocatedType object with another BufferAllocatedType object.
bool defined() const
Returns true if the buffer is not empty.
void append(const B &other)
Append data from another buffer to this buffer.
void push_back(const T &value)
Append a T object to the end of the array, resizing the array if necessary.
void prepend(const T *data, const size_t size)
Prepend data to the buffer.
size_t capacity() const
Returns the capacity (raw size) of the allocated buffer in T objects.
size_t size() const
Returns the size of the buffer in T objects.
bool empty() const
Returns true if the buffer is empty.
void write(const T *data, const size_t size)
Write data to the buffer.
auto * read_alloc(const size_t size)
Allocate memory and read data from the buffer into the allocated memory.
T pop_front()
Removes and returns the first element from the buffer.
size_t offset() const
Returns the current offset (headroom) into the buffer.
void reset_content()
Resets the content of the buffer.
void read(NCT *data, const size_t size)
Read data from the buffer into the specified memory location.
size_t prepare(Buffer &buf) const
BufferFlags buffer_flags() const
void realign(Buffer &buf) const
static void prepend_size(Buffer &buf)
PacketStream< SIZE_TYPE > pktstream
void put(BufferAllocated &buf, const Frame::Context &frame_context)
void get(BufferAllocated &ret, const Frame::Context &frame_context)
static void prepend_size(Buffer &buf)
static size_t read_size(Buffer &buf)
static constexpr size_t SIZE_UNDEF
OPENVPN_SIMPLE_EXCEPTION(packet_not_fully_formed)
void get(BufferAllocated &ret)
static void validate_size(const size_t size, const Frame::Context &frame_context)
static void host_to_network(std::uint16_t &result, const size_t value)
void extract_size(Buffer &buf, const Frame::Context &frame_context)
static size_t network_to_host(const std::uint16_t value)
OPENVPN_SIMPLE_EXCEPTION(embedded_packet_size_error)
bool declared_size_defined() const
void get(BufferAllocated &ret, const Frame::Context &frame_context)
static bool size_defined(const Buffer &buf)
static size_t network_to_host(const std::uint32_t value)
void put(BufferAllocated &buf, const Frame::Context &frame_context)
static void host_to_network(std::uint32_t &result, const size_t value)
constexpr BufferFlags GROW(1u<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)