Class Parser
Defined in File parser.hpp
Class Documentation
-
class Parser
This class analyzes packets and extracts the payload. It does not have any send and receive functionality.
Public Functions
-
Parser()
-
~Parser()
-
int Parse(uint8_t target_buf[], int target_len, uint8_t payload[])
The Parse function processes a buffer to extract a payload based on a specific protocol sign, data length, and checksum.
- Parameters:
buf – The
bufparameter is an array ofuint8_ttype, which is used to store the data that needs to be parsed.target_len – The
target_lenparameter in theParsefunction represents the length of thebufarray that is being parsed. It is used to iterate over the elements of thebufarray and determine the parsing logic based on the current state of the parser.payload – The
payloadparameter in theParsefunction is an output parameter where the parsed data will be stored. It is an array ofuint8_ttype that will hold the extracted payload data after parsing the input bufferbuf.
- Returns:
The
Parsefunction returns an integer value representing the length of the payload that was successfully parsed from the input buffer.
-
uint8_t Checksum(uint8_t buf[], int len)
The Checksum function calculates the XOR checksum of an array of bytes.
- Parameters:
buf – An array of uint8_t values representing the data for which the checksum needs to be calculated.
len – The
lenparameter in theChecksumfunction represents the length of thebufarray, which is the number of elements in the array that need to be included in the checksum calculation.
- Returns:
The function
Checksumis returning auint8_tvalue, which is the calculated checksum of the input bufferbufwith the specified lengthlen.
-
Parser()