The BinParser class handles a byte buffer and functionality to iteratively parse the content. More...
#include <bin_parser.h>
Public Member Functions | |
BinParser (uint8_t *buffer, size_t buf_len) | |
Creates a new BinParser object from a given buffer. More... | |
BinParser (BinParser &parent, size_t sub_len) | |
Creates a new BinParser object for part of a buffer from a parent BinParser. More... | |
bool | checkSize (size_t bytes) |
Checks if at least a given number of bytes is still remaining unparsed in the buffer. More... | |
template<typename T > | |
bool | checkSize (void) |
Checks if enough bytes for a given type remain unparsed in the buffer. More... | |
void | consume () |
Sets the current buffer position to the end of the buffer, finishing parsing. More... | |
void | consume (size_t bytes) |
Moves the current buffer position ahead by a given amount. More... | |
void | debug () |
Logs debugging information about the BinParser object. More... | |
bool | empty () |
Checks if no unparsed bytes remain in the buffer. More... | |
template<typename T > | |
void | parse (T &val) |
Parses the next bytes as given type. More... | |
void | parse (double &val) |
Parses the next bytes as a double. More... | |
void | parse (float &val) |
Parses the next bytes as a float. More... | |
void | parse (bool &val) |
Parses the next byte as a bool. More... | |
void | parse (vector3d_t &val) |
Parses the next bytes as a vector of 3 doubles. More... | |
void | parse (vector6d_t &val) |
Parses the next bytes as a vector of 6 doubles. More... | |
void | parse (vector6int32_t &val) |
Parses the next bytes as a vector of 6 32 bit integers. More... | |
void | parse (vector6uint32_t &val) |
Parses the next bytes as a vector of 6 unsigned 32 bit integers. More... | |
void | parse (std::string &val, size_t len) |
Parses a given number of bytes as a string. More... | |
void | parse (std::string &val) |
Special string parse function that assumes uint8_t len followed by chars. More... | |
template<typename T , size_t N> | |
void | parse (std::array< T, N > &array) |
Parses the next bytes as an array of a given type and size. More... | |
template<typename T , size_t N> | |
void | parse (std::bitset< N > &set) |
Parses the next bytes as a value of a given type, but also copies it to a bitset. More... | |
void | parseRemainder (std::string &val) |
Parses the remaining bytes as a string. More... | |
template<typename T > | |
T | peek () |
Parses the next bytes as given type without moving the buffer pointer. More... | |
void | rawData (std::unique_ptr< uint8_t > &buffer, size_t &buffer_length) |
Writes the remaining bytes into a given buffer without parsing them. More... | |
~BinParser () | |
Deconstructor for the BinParser. More... | |
Private Member Functions | |
template<typename T > | |
T | decode (T val) |
uint16_t | decode (uint16_t val) |
uint32_t | decode (uint32_t val) |
uint64_t | decode (uint64_t val) |
int16_t | decode (int16_t val) |
int32_t | decode (int32_t val) |
int64_t | decode (int64_t val) |
Private Attributes | |
uint8_t * | buf_end_ |
uint8_t * | buf_pos_ |
BinParser & | parent_ |
The BinParser class handles a byte buffer and functionality to iteratively parse the content.
Definition at line 44 of file bin_parser.h.
|
inline |
Creates a new BinParser object from a given buffer.
buffer | The byte buffer to parse |
buf_len | Size of the buffer |
Definition at line 88 of file bin_parser.h.
|
inline |
Creates a new BinParser object for part of a buffer from a parent BinParser.
parent | Parent BinParser |
sub_len | Size of the sub-buffer to parse |
Definition at line 99 of file bin_parser.h.
|
inline |
Deconstructor for the BinParser.
Definition at line 108 of file bin_parser.h.
|
inline |
Checks if at least a given number of bytes is still remaining unparsed in the buffer.
bytes | Number of bytes to check for |
Definition at line 339 of file bin_parser.h.
|
inline |
Checks if enough bytes for a given type remain unparsed in the buffer.
T | The type to check for |
Definition at line 351 of file bin_parser.h.
|
inline |
Sets the current buffer position to the end of the buffer, finishing parsing.
Definition at line 318 of file bin_parser.h.
|
inline |
Moves the current buffer position ahead by a given amount.
bytes | Number of bytes to move the buffer position |
Definition at line 327 of file bin_parser.h.
|
inline |
Logs debugging information about the BinParser object.
Definition at line 369 of file bin_parser.h.
|
inlineprivate |
Definition at line 52 of file bin_parser.h.
|
inlineprivate |
Definition at line 56 of file bin_parser.h.
|
inlineprivate |
Definition at line 60 of file bin_parser.h.
|
inlineprivate |
Definition at line 64 of file bin_parser.h.
|
inlineprivate |
Definition at line 68 of file bin_parser.h.
|
inlineprivate |
Definition at line 72 of file bin_parser.h.
|
inlineprivate |
Definition at line 76 of file bin_parser.h.
|
inline |
Checks if no unparsed bytes remain in the buffer.
Definition at line 361 of file bin_parser.h.
|
inline |
Parses the next bytes as given type.
T | Type to parse as |
val | Reference to write the parsed value to |
Definition at line 139 of file bin_parser.h.
|
inline |
Parses the next bytes as a double.
val | Reference to write the parsed value to |
Definition at line 150 of file bin_parser.h.
|
inline |
Parses the next bytes as a float.
val | Reference to write the parsed value to |
Definition at line 161 of file bin_parser.h.
|
inline |
Parses the next byte as a bool.
UR uses 1 byte for boolean values but sizeof(bool) is implementation defined, so we must ensure they're parsed as uint8_t on all compilers
val | Reference to write the parsed value to |
Definition at line 177 of file bin_parser.h.
|
inline |
Parses the next bytes as a vector of 3 doubles.
val | Reference to write the parsed value to |
Definition at line 189 of file bin_parser.h.
|
inline |
Parses the next bytes as a vector of 6 doubles.
val | Reference to write the parsed value to |
Definition at line 202 of file bin_parser.h.
|
inline |
Parses the next bytes as a vector of 6 32 bit integers.
val | Reference to write the parsed value to |
Definition at line 215 of file bin_parser.h.
|
inline |
Parses the next bytes as a vector of 6 unsigned 32 bit integers.
val | Reference to write the parsed value to |
Definition at line 228 of file bin_parser.h.
|
inline |
Parses a given number of bytes as a string.
val | Reference to write the parsed value to |
len | Number of bytes to parse |
Definition at line 266 of file bin_parser.h.
|
inline |
Special string parse function that assumes uint8_t len followed by chars.
val | Reference to write the parsed value to |
Definition at line 277 of file bin_parser.h.
|
inline |
Parses the next bytes as an array of a given type and size.
T | Type of the array |
N | Number of elements in the array |
array | Reference of an array to parse to. |
Definition at line 292 of file bin_parser.h.
|
inline |
Parses the next bytes as a value of a given type, but also copies it to a bitset.
T | Type to parse as |
N | Size of the bitset to copy to |
set | Reference to the bitset to copy the value to. |
Definition at line 308 of file bin_parser.h.
|
inline |
Parses the remaining bytes as a string.
val | Reference to write the parsed value to |
Definition at line 255 of file bin_parser.h.
|
inline |
Parses the next bytes as given type without moving the buffer pointer.
T | Type to parse as |
Definition at line 121 of file bin_parser.h.
|
inline |
Writes the remaining bytes into a given buffer without parsing them.
buffer | The buffer to copy the remaining bytes to. |
buffer_length | Reference to write the number of remaining bytes to. |
Definition at line 242 of file bin_parser.h.
|
private |
Definition at line 47 of file bin_parser.h.
|
private |
Definition at line 47 of file bin_parser.h.
|
private |
Definition at line 48 of file bin_parser.h.