Public Member Functions | Private Member Functions | Private Attributes | List of all members
urcl::comm::BinParser Class Reference

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 >
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 >
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_
 
BinParserparent_
 

Detailed Description

The BinParser class handles a byte buffer and functionality to iteratively parse the content.

Definition at line 44 of file bin_parser.h.

Constructor & Destructor Documentation

urcl::comm::BinParser::BinParser ( uint8_t *  buffer,
size_t  buf_len 
)
inline

Creates a new BinParser object from a given buffer.

Parameters
bufferThe byte buffer to parse
buf_lenSize of the buffer

Definition at line 88 of file bin_parser.h.

urcl::comm::BinParser::BinParser ( BinParser parent,
size_t  sub_len 
)
inline

Creates a new BinParser object for part of a buffer from a parent BinParser.

Parameters
parentParent BinParser
sub_lenSize of the sub-buffer to parse

Definition at line 99 of file bin_parser.h.

urcl::comm::BinParser::~BinParser ( )
inline

Deconstructor for the BinParser.

Definition at line 108 of file bin_parser.h.

Member Function Documentation

bool urcl::comm::BinParser::checkSize ( size_t  bytes)
inline

Checks if at least a given number of bytes is still remaining unparsed in the buffer.

Parameters
bytesNumber of bytes to check for
Returns
True, if at least the given number of bytes are unparsed, false otherwise.

Definition at line 339 of file bin_parser.h.

template<typename T >
bool urcl::comm::BinParser::checkSize ( void  )
inline

Checks if enough bytes for a given type remain unparsed in the buffer.

Template Parameters
TThe type to check for
Returns
True, if enough bytes are unparsed, false otherwise.

Definition at line 351 of file bin_parser.h.

void urcl::comm::BinParser::consume ( )
inline

Sets the current buffer position to the end of the buffer, finishing parsing.

Definition at line 318 of file bin_parser.h.

void urcl::comm::BinParser::consume ( size_t  bytes)
inline

Moves the current buffer position ahead by a given amount.

Parameters
bytesNumber of bytes to move the buffer position

Definition at line 327 of file bin_parser.h.

void urcl::comm::BinParser::debug ( )
inline

Logs debugging information about the BinParser object.

Definition at line 369 of file bin_parser.h.

template<typename T >
T urcl::comm::BinParser::decode ( val)
inlineprivate

Definition at line 52 of file bin_parser.h.

uint16_t urcl::comm::BinParser::decode ( uint16_t  val)
inlineprivate

Definition at line 56 of file bin_parser.h.

uint32_t urcl::comm::BinParser::decode ( uint32_t  val)
inlineprivate

Definition at line 60 of file bin_parser.h.

uint64_t urcl::comm::BinParser::decode ( uint64_t  val)
inlineprivate

Definition at line 64 of file bin_parser.h.

int16_t urcl::comm::BinParser::decode ( int16_t  val)
inlineprivate

Definition at line 68 of file bin_parser.h.

int32_t urcl::comm::BinParser::decode ( int32_t  val)
inlineprivate

Definition at line 72 of file bin_parser.h.

int64_t urcl::comm::BinParser::decode ( int64_t  val)
inlineprivate

Definition at line 76 of file bin_parser.h.

bool urcl::comm::BinParser::empty ( )
inline

Checks if no unparsed bytes remain in the buffer.

Returns
True, if all bytes were parsed, false otherwise.

Definition at line 361 of file bin_parser.h.

template<typename T >
void urcl::comm::BinParser::parse ( T &  val)
inline

Parses the next bytes as given type.

Template Parameters
TType to parse as
Parameters
valReference to write the parsed value to

Definition at line 139 of file bin_parser.h.

void urcl::comm::BinParser::parse ( double &  val)
inline

Parses the next bytes as a double.

Parameters
valReference to write the parsed value to

Definition at line 150 of file bin_parser.h.

void urcl::comm::BinParser::parse ( float &  val)
inline

Parses the next bytes as a float.

Parameters
valReference to write the parsed value to

Definition at line 161 of file bin_parser.h.

void urcl::comm::BinParser::parse ( bool &  val)
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

Parameters
valReference to write the parsed value to

Definition at line 177 of file bin_parser.h.

void urcl::comm::BinParser::parse ( vector3d_t val)
inline

Parses the next bytes as a vector of 3 doubles.

Parameters
valReference to write the parsed value to

Definition at line 189 of file bin_parser.h.

void urcl::comm::BinParser::parse ( vector6d_t val)
inline

Parses the next bytes as a vector of 6 doubles.

Parameters
valReference to write the parsed value to

Definition at line 202 of file bin_parser.h.

void urcl::comm::BinParser::parse ( vector6int32_t val)
inline

Parses the next bytes as a vector of 6 32 bit integers.

Parameters
valReference to write the parsed value to

Definition at line 215 of file bin_parser.h.

void urcl::comm::BinParser::parse ( vector6uint32_t val)
inline

Parses the next bytes as a vector of 6 unsigned 32 bit integers.

Parameters
valReference to write the parsed value to

Definition at line 228 of file bin_parser.h.

void urcl::comm::BinParser::parse ( std::string &  val,
size_t  len 
)
inline

Parses a given number of bytes as a string.

Parameters
valReference to write the parsed value to
lenNumber of bytes to parse

Definition at line 266 of file bin_parser.h.

void urcl::comm::BinParser::parse ( std::string &  val)
inline

Special string parse function that assumes uint8_t len followed by chars.

Parameters
valReference to write the parsed value to

Definition at line 277 of file bin_parser.h.

template<typename T , size_t N>
void urcl::comm::BinParser::parse ( std::array< T, N > &  array)
inline

Parses the next bytes as an array of a given type and size.

Template Parameters
TType of the array
NNumber of elements in the array
Parameters
arrayReference of an array to parse to.

Definition at line 292 of file bin_parser.h.

template<typename T , size_t N>
void urcl::comm::BinParser::parse ( std::bitset< N > &  set)
inline

Parses the next bytes as a value of a given type, but also copies it to a bitset.

Template Parameters
TType to parse as
NSize of the bitset to copy to
Parameters
setReference to the bitset to copy the value to.

Definition at line 308 of file bin_parser.h.

void urcl::comm::BinParser::parseRemainder ( std::string &  val)
inline

Parses the remaining bytes as a string.

Parameters
valReference to write the parsed value to

Definition at line 255 of file bin_parser.h.

template<typename T >
T urcl::comm::BinParser::peek ( )
inline

Parses the next bytes as given type without moving the buffer pointer.

Template Parameters
TType to parse as
Returns
Value of the next bytes as type T

Definition at line 121 of file bin_parser.h.

void urcl::comm::BinParser::rawData ( std::unique_ptr< uint8_t > &  buffer,
size_t &  buffer_length 
)
inline

Writes the remaining bytes into a given buffer without parsing them.

Parameters
bufferThe buffer to copy the remaining bytes to.
buffer_lengthReference to write the number of remaining bytes to.

Definition at line 242 of file bin_parser.h.

Member Data Documentation

uint8_t * urcl::comm::BinParser::buf_end_
private

Definition at line 47 of file bin_parser.h.

uint8_t* urcl::comm::BinParser::buf_pos_
private

Definition at line 47 of file bin_parser.h.

BinParser& urcl::comm::BinParser::parent_
private

Definition at line 48 of file bin_parser.h.


The documentation for this class was generated from the following file:


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26