Binary data packer.
More...
#include <packer.hpp>
|
| using | Container = std::vector< std::uint8_t > |
| | Underlying data container.
|
| |
| using | Order = boost::endian::order |
| | Endian ordering.
|
| |
|
| | Packer ()=default |
| | Default constructor.
|
| |
| | Packer (std::size_t count) |
| | Constructor.
|
| |
| | Packer (const Packer &)=default |
| |
| Packer & | operator= (const Packer &)=default |
| |
| | Packer (Packer &&)=default |
| |
| Packer & | operator= (Packer &&)=default |
| |
| virtual | ~Packer ()=default |
| |
| const Container & | data () const |
| | Obtain a constant reference to the internal data container.
|
| |
| Container & | data () |
| | Obtain a mutable reference to the internal data container.
|
| |
| std::size_t | size () const |
| | Obtain the size of the internal data container.
|
| |
| 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.
|
| |
| template<std::floating_point TValue, Order Endian = Order::big> |
| void | insert_floating_point (TValue value) |
| | Insert a floating point value in the data container.
|
| |
| void | insert_string (const std::string &value) |
| | Insert a string value in the data container.
|
| |
| void | insert_byte (std::uint8_t value) |
| | Insert a single byte in the data container.
|
| |
| template<class InputIt > |
| void | insert_bytes (InputIt first, InputIt last) |
| | Insert bytes from the given range in the data container.
|
| |
| void | insert_bytes (std::initializer_list< std::uint8_t > bytes) |
| | Insert a set of raw bytes in the data container.
|
| |
| void | insert_bytes (const std::span< const std::uint8_t > &view) |
| | Insert a the bytes given by the span view in the data container.
|
| |
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: