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
buf
parameter is an array ofuint8_t
type, which is used to store the data that needs to be parsed.target_len – The
target_len
parameter in theParse
function represents the length of thebuf
array that is being parsed. It is used to iterate over the elements of thebuf
array and determine the parsing logic based on the current state of the parser.payload – The
payload
parameter in theParse
function is an output parameter where the parsed data will be stored. It is an array ofuint8_t
type that will hold the extracted payload data after parsing the input bufferbuf
.
- Returns:
The
Parse
function 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
len
parameter in theChecksum
function represents the length of thebuf
array, which is the number of elements in the array that need to be included in the checksum calculation.
- Returns:
The function
Checksum
is returning auint8_t
value, which is the calculated checksum of the input bufferbuf
with the specified lengthlen
.
-
Parser()