Botan 3.11.0
Crypto and TLS for C&
Botan::BufferStuffer Class Referencefinal

Helper class to ease in-place marshalling of concatenated fixed-length values. More...

#include <buffer_stuffer.h>

Public Member Functions

constexpr void append (std::span< const uint8_t > buffer)
constexpr void append (uint8_t b, size_t repeat=1)
constexpr BufferStuffer (std::span< uint8_t > buffer)
constexpr bool full () const
template<size_t bytes>
constexpr std::span< uint8_t, bytes > next ()
template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > next (size_t bytes)
constexpr std::span< uint8_t > next (size_t bytes)
constexpr uint8_t & next_byte ()
constexpr size_t remaining_capacity () const

Detailed Description

Helper class to ease in-place marshalling of concatenated fixed-length values.

The size of the final buffer must be known from the start, reallocations are not performed.

Definition at line 24 of file buffer_stuffer.h.

Constructor & Destructor Documentation

◆ BufferStuffer()

Botan::BufferStuffer::BufferStuffer ( std::span< uint8_t > buffer)
inlineexplicitconstexpr

Definition at line 26 of file buffer_stuffer.h.

26: m_buffer(buffer) {}

Member Function Documentation

◆ append() [1/2]

◆ append() [2/2]

void Botan::BufferStuffer::append ( uint8_t b,
size_t repeat = 1 )
inlineconstexpr

Definition at line 64 of file buffer_stuffer.h.

64 {
65 auto sink = next(repeat);
66 std::fill(sink.begin(), sink.end(), b);
67 }

References next().

◆ full()

◆ next() [1/3]

template<size_t bytes>
std::span< uint8_t, bytes > Botan::BufferStuffer::next ( )
inlineconstexpr

Definition at line 41 of file buffer_stuffer.h.

41 {
42 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
43
44 auto result = m_buffer.first<bytes>();
45 m_buffer = m_buffer.subspan(bytes);
46 return result;
47 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK.

Referenced by append(), append(), next(), and next_byte().

◆ next() [2/3]

template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > Botan::BufferStuffer::next ( size_t bytes)
inline

Definition at line 50 of file buffer_stuffer.h.

50 {
51 return StrongSpan<StrongT>(next(bytes));
52 }

References next().

◆ next() [3/3]

◆ next_byte()

uint8_t & Botan::BufferStuffer::next_byte ( )
inlineconstexpr
Returns
a reference to the next single byte in the buffer

Definition at line 57 of file buffer_stuffer.h.

57{ return next(1)[0]; }

References next().

◆ remaining_capacity()

size_t Botan::BufferStuffer::remaining_capacity ( ) const
inlineconstexpr

The documentation for this class was generated from the following file: