Class BinParser
Defined in File bin_parser.h
Class Documentation
-
class BinParser
The BinParser class handles a byte buffer and functionality to iteratively parse the content.
Public Functions
-
inline BinParser(uint8_t *buffer, size_t buf_len)
Creates a new BinParser object from a given buffer.
- Parameters:
buffer – The byte buffer to parse
buf_len – Size of the buffer
-
inline BinParser(BinParser &parent, size_t sub_len)
Creates a new BinParser object for part of a buffer from a parent BinParser.
- Parameters:
parent – Parent BinParser
sub_len – Size of the sub-buffer to parse
-
template<typename T>
inline T peek() Parses the next bytes as given type without moving the buffer pointer.
- Template Parameters:
T – Type to parse as
- Returns:
Value of the next bytes as type T
-
template<typename T>
inline void parse(T &val) Parses the next bytes as given type.
- Template Parameters:
T – Type to parse as
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(double &val)
Parses the next bytes as a double.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(float &val)
Parses the next bytes as a float.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(bool &val)
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
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(vector3d_t &val)
Parses the next bytes as a vector of 3 doubles.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(vector6d_t &val)
Parses the next bytes as a vector of 6 doubles.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(vector6int32_t &val)
Parses the next bytes as a vector of 6 32 bit integers.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(vector6uint32_t &val)
Parses the next bytes as a vector of 6 unsigned 32 bit integers.
- Parameters:
val – Reference to write the parsed value to
-
inline void rawData(std::unique_ptr<uint8_t[]> &buffer, size_t &buffer_length)
Writes the remaining bytes into a given buffer without parsing them.
- Parameters:
buffer – The buffer to copy the remaining bytes to.
buffer_length – Reference to write the number of remaining bytes to.
-
inline void parseRemainder(std::string &val)
Parses the remaining bytes as a string.
- Parameters:
val – Reference to write the parsed value to
-
inline void parse(std::string &val, size_t len)
Parses a given number of bytes as a string.
- Parameters:
val – Reference to write the parsed value to
len – Number of bytes to parse
-
inline void parse(std::string &val)
Special string parse function that assumes uint8_t len followed by chars.
- Parameters:
val – Reference to write the parsed value to
-
template<typename T, size_t N>
inline void parse(std::array<T, N> &array) Parses the next bytes as an array of a given type and size.
- Template Parameters:
T – Type of the array
N – Number of elements in the array
- Parameters:
array – Reference of an array to parse to.
-
template<typename T, size_t N>
inline void parse(std::bitset<N> &set) Parses the next bytes as a value of a given type, but also copies it to a bitset.
- Template Parameters:
T – Type to parse as
N – Size of the bitset to copy to
- Parameters:
set – Reference to the bitset to copy the value to.
-
inline void consume()
Sets the current buffer position to the end of the buffer, finishing parsing.
-
inline void consume(size_t bytes)
Moves the current buffer position ahead by a given amount.
- Parameters:
bytes – Number of bytes to move the buffer position
-
inline bool checkSize(size_t bytes)
Checks if at least a given number of bytes is still remaining unparsed in the buffer.
- Parameters:
bytes – Number of bytes to check for
- Returns:
True, if at least the given number of bytes are unparsed, false otherwise.
-
template<typename T>
inline bool checkSize(void) Checks if enough bytes for a given type remain unparsed in the buffer.
- Template Parameters:
T – The type to check for
- Returns:
True, if enough bytes are unparsed, false otherwise.
-
inline bool empty()
Checks if no unparsed bytes remain in the buffer.
- Returns:
True, if all bytes were parsed, false otherwise.
-
inline BinParser(uint8_t *buffer, size_t buf_len)