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

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

#include <stl_util.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 ()
constexpr std::span< uint8_t > next (size_t bytes)
template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > 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 134 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferStuffer()

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

Definition at line 136 of file stl_util.h.

136: 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 174 of file stl_util.h.

174 {
175 auto sink = next(repeat);
176 std::fill(sink.begin(), sink.end(), b);
177 }

References next().

◆ full()

◆ next() [1/3]

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

Definition at line 151 of file stl_util.h.

151 {
152 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
153
154 auto result = m_buffer.first<bytes>();
155 m_buffer = m_buffer.subspan(bytes);
156 return result;
157 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK.

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

◆ next() [2/3]

◆ next() [3/3]

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

Definition at line 160 of file stl_util.h.

160 {
161 return StrongSpan<StrongT>(next(bytes));
162 }

References next().

◆ next_byte()

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

Definition at line 167 of file stl_util.h.

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

References next().

Referenced by Botan::Keccak_Permutation::squeeze().

◆ remaining_capacity()

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

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