Class Parser

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 of uint8_t type, which is used to store the data that needs to be parsed.

  • target_len – The target_len parameter in the Parse function represents the length of the buf array that is being parsed. It is used to iterate over the elements of the buf array and determine the parsing logic based on the current state of the parser.

  • payload – The payload parameter in the Parse function is an output parameter where the parsed data will be stored. It is an array of uint8_t type that will hold the extracted payload data after parsing the input buffer buf.

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 the Checksum function represents the length of the buf 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 a uint8_t value, which is the calculated checksum of the input buffer buf with the specified length len.