Binary data packer.
More...
#include <packer.hpp>
|
using | Container = std::vector< std::uint8_t > |
| Underlying data container. More...
|
|
using | Order = boost::endian::order |
| Endian ordering. More...
|
|
Binary data packer.
This class exposes an API that facilitates adding different data types to a byte sequence.
◆ Container
Underlying data container.
◆ Order
◆ 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 |
◆ data() [1/2]
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] | value | Value 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
-
◆ 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
-
InputIt | Source iterator type. |
- Parameters
-
[in] | first | Beginning of the range to insert. |
[in] | last | End 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] | bytes | Bytes 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
-
TValue | The numerical type to insert in the data container. |
Endian | Endian order of the value to insert. |
- Parameters
-
[in] | value | Value 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
-
TValue | The numerical type to insert in the data container. |
N | Number of bytes to insert. |
Endian | Endian order of the value to insert. |
- Parameters
-
[in] | value | Value 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] | value | Value to insert. |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ 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.
◆ m_data
The documentation for this class was generated from the following file: