Arduino KVComm  master
Key-Value pair communication library for Arduino
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SLIPParser Class Reference

Class for parsing SLIP packets. More...

#include <SLIPStream/SLIPParser.hpp>

Collaboration diagram for SLIPParser:

Public Member Functions

template<size_t N>
 SLIPParser (uint8_t(&buffer)[N])
 Constructor. More...
 
 SLIPParser ()
 Default constructor for a parser without a buffer. More...
 
 SLIPParser (std::nullptr_t)
 Constructor for a parser without a buffer. More...
 
 SLIPParser (uint8_t *buffer, size_t bufferSize)
 Constructor. More...
 
template<class Callback >
size_t parse (uint8_t c, Callback callback)
 Parse the given byte, and call the callback for each data byte. More...
 
size_t parse (uint8_t c)
 Parse the given byte without using a callback function. More...
 
bool wasTruncated () const
 Check if the previous packet was truncated. More...
 
size_t numTruncated () const
 Get the number of bytes that were truncated due to the previous packet being too large for the buffer. More...
 

Private Member Functions

void reset ()
 

Private Attributes

uint8_t * buffer = nullptr
 
uint8_t * write = nullptr
 
size_t bufferSize = 0
 
size_t truncated = 0
 
bool escape = false
 

Detailed Description

Class for parsing SLIP packets.

Definition at line 17 of file SLIPParser.hpp.

Constructor & Destructor Documentation

◆ SLIPParser() [1/4]

SLIPParser ( uint8_t(&)  buffer[N])
inline

Constructor.

Parameters
bufferThe byte buffer to store the parsed packets.

Definition at line 26 of file SLIPParser.hpp.

◆ SLIPParser() [2/4]

SLIPParser ( )
inline

Default constructor for a parser without a buffer.

Definition at line 31 of file SLIPParser.hpp.

◆ SLIPParser() [3/4]

SLIPParser ( std::nullptr_t  )
inline

Constructor for a parser without a buffer.

Definition at line 36 of file SLIPParser.hpp.

◆ SLIPParser() [4/4]

SLIPParser ( uint8_t *  buffer,
size_t  bufferSize 
)
inline

Constructor.

Parameters
bufferThe byte buffer to store the parsed packets.
bufferSizeThe size of the buffer.

Definition at line 46 of file SLIPParser.hpp.

Member Function Documentation

◆ parse() [1/2]

size_t parse ( uint8_t  c,
Callback  callback 
)

Parse the given byte, and call the callback for each data byte.

Template Parameters
CallbackThe type of callback function. Should be a callable object that takes a data byte and the index of that byte in the packet:
void callback(uint8_t databyte, size_t index)
Parameters
cThe byte to parse.
callbackThe callback function to call for each data byte.
Return values
0The packet is not finished yet.
>0The packet was received in its entirety, and the return value is the size of the packet in the buffer.
If the packet is not larger than the buffer, this will be the same as the size of the packet. If the packet was larger than the buffer, the return value will be the size of the buffer, and wasTruncated will return true.

Definition at line 4 of file SLIPParser.ipp.

◆ parse() [2/2]

size_t parse ( uint8_t  c)
inline

Parse the given byte without using a callback function.

Parameters
cThe byte to parse.
Return values
0The packet is not finished yet.
>0The packet was received in its entirety, and the return value is the size of the packet in the buffer.
If the packet is not larger than the buffer, this will be the same as the size of the packet. If the packet was larger than the buffer, the return value will be the size of the buffer, and wasTruncated will return true.

Definition at line 91 of file SLIPParser.hpp.

◆ wasTruncated()

bool wasTruncated ( ) const
inline

Check if the previous packet was truncated.

Return values
trueThe previous packet didn't fit the buffer. The size returned by SLIPParser::parse was smaller than the actual size of the packet.
falseThe buffer was large enough to store the previous packet.

Definition at line 106 of file SLIPParser.hpp.

◆ numTruncated()

size_t numTruncated ( ) const
inline

Get the number of bytes that were truncated due to the previous packet being too large for the buffer.

Definition at line 112 of file SLIPParser.hpp.

◆ reset()

void reset ( )
inlineprivate

Definition at line 115 of file SLIPParser.hpp.

Member Data Documentation

◆ buffer

uint8_t* buffer = nullptr
private

Definition at line 118 of file SLIPParser.hpp.

◆ write

uint8_t* write = nullptr
private

Definition at line 119 of file SLIPParser.hpp.

◆ bufferSize

size_t bufferSize = 0
private

Definition at line 120 of file SLIPParser.hpp.

◆ truncated

size_t truncated = 0
private

Definition at line 121 of file SLIPParser.hpp.

◆ escape

bool escape = false
private

Definition at line 122 of file SLIPParser.hpp.


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