Kouta
A small application framework based on Boost
kouta::io::Packer Class Reference

Binary data packer. More...

#include <packer.hpp>

Collaboration diagram for kouta::io::Packer:

Public Types

using Container = std::vector< std::uint8_t >
 Underlying data container. More...
 
using Order = boost::endian::order
 Endian ordering. More...
 

Public Member Functions

 Packer ()=default
 Default constructor. More...
 
 Packer (std::size_t count)
 Constructor. More...
 
 Packer (const Packer &)=default
 
Packeroperator= (const Packer &)=default
 
 Packer (Packer &&)=default
 
Packeroperator= (Packer &&)=default
 
virtual ~Packer ()=default
 
const Containerdata () const
 Obtain a constant reference to the internal data container. More...
 
Containerdata ()
 Obtain a mutable reference to the internal data container. More...
 
std::size_t size () const
 Obtain the size of the internal data container. More...
 
template<std::integral TValue, std::size_t N = sizeof(TValue), Order Endian = Order::big>
void insert_integral (TValue value)
 Insert an integral value in the data container. More...
 
template<std::floating_point TValue, Order Endian = Order::big>
void insert_floating_point (TValue value)
 Insert a floating point value in the data container. More...
 
void insert_string (const std::string &value)
 Insert a string value in the data container. More...
 
void insert_byte (std::uint8_t value)
 Insert a single byte in the data container. More...
 
template<class InputIt >
void insert_bytes (InputIt first, InputIt last)
 Insert bytes from the given range in the data container. More...
 
void insert_bytes (std::initializer_list< std::uint8_t > bytes)
 Insert a set of raw bytes in the data container. More...
 
void insert_bytes (const std::span< const std::uint8_t > &view)
 Insert a the bytes given by the span view in the data container. More...
 

Private Attributes

Container m_data
 

Detailed Description

Binary data packer.

This class exposes an API that facilitates adding different data types to a byte sequence.

Member Typedef Documentation

◆ Container

using kouta::io::Packer::Container = std::vector<std::uint8_t>

Underlying data container.

◆ Order

using kouta::io::Packer::Order = boost::endian::order

Endian ordering.

Constructor & Destructor Documentation

◆ Packer() [1/4]

kouta::io::Packer::Packer ( )
default

Default constructor.

The underlying container will be dynamically allocated as data is added to it.

◆ Packer() [2/4]

kouta::io::Packer::Packer ( std::size_t  count)
inlineexplicit

Constructor.

Pre-allocates the underlying container by using the provided count bytes. This does not mean that the container will not grow if more bytes are inserted.

◆ Packer() [3/4]

kouta::io::Packer::Packer ( const Packer )
default

◆ Packer() [4/4]

kouta::io::Packer::Packer ( Packer &&  )
default

◆ ~Packer()

virtual kouta::io::Packer::~Packer ( )
virtualdefault

Member Function Documentation

◆ data() [1/2]

Container& kouta::io::Packer::data ( )
inline

Obtain a mutable reference to the internal data container.

◆ data() [2/2]

const Container& kouta::io::Packer::data ( ) const
inline

Obtain a constant reference to the internal data container.

◆ insert_byte()

void kouta::io::Packer::insert_byte ( std::uint8_t  value)
inline

Insert a single byte in the data container.

Parameters
[in]valueValue to insert.

◆ insert_bytes() [1/3]

void kouta::io::Packer::insert_bytes ( const std::span< const std::uint8_t > &  view)
inline

Insert a the bytes given by the span view in the data container.

Parameters
[in]viewView to insert.

◆ insert_bytes() [2/3]

template<class InputIt >
void kouta::io::Packer::insert_bytes ( InputIt  first,
InputIt  last 
)
inline

Insert bytes from the given range in the data container.

Template Parameters
InputItSource iterator type.
Parameters
[in]firstBeginning of the range to insert.
[in]lastEnd of the range to insert.

◆ insert_bytes() [3/3]

void kouta::io::Packer::insert_bytes ( std::initializer_list< std::uint8_t >  bytes)
inline

Insert a set of raw bytes in the data container.

Parameters
[in]bytesBytes to insert.

◆ insert_floating_point()

template<std::floating_point TValue, Order Endian = Order::big>
void kouta::io::Packer::insert_floating_point ( TValue  value)
inline

Insert a floating point value in the data container.

Template Parameters
TValueThe numerical type to insert in the data container.
EndianEndian order of the value to insert.
Parameters
[in]valueValue to insert.

◆ insert_integral()

template<std::integral TValue, std::size_t N = sizeof(TValue), Order Endian = Order::big>
void kouta::io::Packer::insert_integral ( TValue  value)
inline

Insert an integral value in the data container.

Template Parameters
TValueThe numerical type to insert in the data container.
NNumber of bytes to insert.
EndianEndian order of the value to insert.
Parameters
[in]valueValue to insert.

◆ insert_string()

void kouta::io::Packer::insert_string ( const std::string &  value)
inline

Insert a string value in the data container.

Note
The final null-character is ignored.
Parameters
[in]valueValue to insert.

◆ operator=() [1/2]

Packer& kouta::io::Packer::operator= ( const Packer )
default

◆ operator=() [2/2]

Packer& kouta::io::Packer::operator= ( Packer &&  )
default

◆ size()

std::size_t kouta::io::Packer::size ( ) const
inline

Obtain the size of the internal data container.

Note
This also corresponds to the number of bytes.

Member Data Documentation

◆ m_data

Container kouta::io::Packer::m_data
private

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