Botan 3.6.1
Crypto and TLS for C&
Botan::BufferStuffer Class Reference

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 142 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferStuffer()

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

Definition at line 144 of file stl_util.h.

144: 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 182 of file stl_util.h.

182 {
183 auto sink = next(repeat);
184 std::fill(sink.begin(), sink.end(), b);
185 }
const SIMD_8x32 & b

References Botan::b, and next().

◆ full()

◆ next() [1/3]

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

Definition at line 159 of file stl_util.h.

159 {
160 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
161
162 auto result = m_buffer.first<bytes>();
163 m_buffer = m_buffer.subspan(bytes);
164 return result;
165 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41

References BOTAN_STATE_CHECK.

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

◆ next() [2/3]

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

◆ next() [3/3]

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

Definition at line 168 of file stl_util.h.

168 {
169 return StrongSpan<StrongT>(next(bytes));
170 }

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 175 of file stl_util.h.

175{ 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: