Binary data parser. More...
#include <parser.hpp>

Public Types | |
| using | View = std::span< const std::uint8_t > |
| Underlying view data type. | |
| using | Order = boost::endian::order |
| Endian ordering. | |
Public Member Functions | |
| Parser ()=delete | |
| Parser (const View &view) | |
| Constructor. | |
| Parser (const Parser &)=default | |
| Parser & | operator= (const Parser &)=default |
| Parser (Parser &&)=default | |
| Parser & | operator= (Parser &&)=default |
| virtual | ~Parser ()=default |
| const View & | view () const |
| Obtain a reference to the internal data view. | |
| std::size_t | size () const |
| Obtain the size of the internal data view. | |
| template<std::integral TValue, std::size_t N = sizeof(TValue), Order Endian = Order::big> | |
| TValue | extract_integral (std::size_t offset) const |
| Extract an integral value from the view. | |
| template<std::floating_point TValue, Order Endian = Order::big> | |
| TValue | extract_floating_point (std::size_t offset) const |
| Extract a floating point value from the view. | |
| virtual std::string | extract_string (std::size_t offset, std::size_t count) const |
| Extract a string value from the view. | |
Private Member Functions | |
| void | check_bounds (std::size_t offset, std::size_t count) const |
| Check that a specific range is within bounds. | |
Private Attributes | |
| View | m_view |
Binary data parser.
This class exposes a read-only API that facilitates extracting different data types from a byte sequence. It is backed by std::span, hence it is cheap to create it from an existing data container, or copy it from an existing parser (which could be useful when writing custom parsers).
| using kouta::io::Parser::Order = boost::endian::order |
Endian ordering.
| using kouta::io::Parser::View = std::span<const std::uint8_t> |
Underlying view data type.
|
delete |
|
inlineexplicit |
Constructor.
| [in] | view | View from which to construct the parser. |
|
default |
|
default |
|
virtualdefault |
|
inlineprivate |
Check that a specific range is within bounds.
| [in] | offset | Starting offset. |
| [in] | count | Number of bytes in the range. |
| std::out_of_range | when there are not enough bytes in the data view. |
|
inline |
Extract a floating point value from the view.
The offset must be within bounds, considering the size of type
| TValue. | Otherwise, an std::out_of_range exception will be thrown. |
It is recommended to check the size() before attempting to extract a value.
| TValue | The numerical type to extract from the data view. |
| Endian | Endian order of the value to extract. |
| offset | The offset from which to start extracting data. |
| std::out_of_range | when there are not enough bytes in the data view. |
|
inline |
Extract an integral value from the view.
The offset must be within bounds, considering the size
| N. | Otherwise, an std::out_of_range exception will be thrown. |
It is recommended to check the size() before attempting to extract a value.
| TValue | The numerical type to extract from the data view. |
| N | Number of bytes to extract. |
| Endian | Endian order of the value to extract. |
| offset | The offset from which to start extracting data. |
| std::out_of_range | when there are not enough bytes in the data view. |
|
inlinevirtual |
Extract a string value from the view.
The offset must be within bounds, considering the character count specified.
It is recommended to check the size() before attempting to extract a value.
This method is marked as virtual to allow overriding it in order to implement custmo behaviour such as interrupting the parsing whenever a null-character is found.
| offset | The starting offset from which to start extracting data. |
| count | The number of characters/bytes to extract from the view. |
| std::out_of_range | when there are not enough bytes in the data view. |
|
inline |
Obtain the size of the internal data view.
|
inline |
Obtain a reference to the internal data view.
|
private |