Framing Protocols

COBS

This is an implementation of Consistent-Overhead Byte Stuffing.

This uses a null byte as an end of packet marker, and uses a clever technique to encode null bytes within the packet with minimal overhead. See the link above for more information.

class packetio::COBSPrint : public packetio::PacketPrint
class packetio::COBSStream : public packetio::PacketStream

Escaped

This packet framer uses a special character to indicate end-of-frame, and an escape character to allow this to appear within a message. In the worst-case, this causes the packet to be twice the data size.

The choice of these special characters is parameterizable through template arguments. encoded/codes.h contains some example choices of values, including an implementation of SLIP. To define your own, you can use code like the following:

#include <escaped/Print.h>
#include <escaped/Stream.h>
#include <escaped/codes.h>

using namespace packetio;

// end, escape, escaped end, escaped escape
typedef EscapeCodes<'A','/','a','\\'> MyCodes;

EscapedPrint<MyCodes> printer(Serial);
EscapedStream<MyCodes> reader(Serial);

In this example, we use A to end a packet. So the packet ABCD/EFGH is encoded to /aBCD/\EFGHA. Here, the first A is replaced by the escape sequence /a, and the / is replaced with /\. Finally, an A is appended to end the packet.

template <uint8_t pEND, uint8_t pESC, uint8_t pESC_END, uint8_t pESC_ESC>
struct packetio::EscapeCodes

A trait type for indicating which markers to use in an EscapedStream or EscapedPrint. This type should be used as the type argument.

Template Parameters
  • pEND: The byte indicating end of frame
  • pESC: The byte indicating that the following byte is an escape code
  • pESC_END: The escape code for encoding an in-data END value
  • pESC_ESC: The escape code for encoding an in-data ESC value

template <typename EscapeCodes>
class packetio::EscapedPrint : public packetio::PacketPrint
template <typename EscapeCodes>
class packetio::EscapedStream : public packetio::PacketStream

SLIP

These is just a convenience aliases for escaped streams with the appropriate EscapeCodes.

typedef EscapeCodes<0xC0, 0xDB, 0xDC, 0xDD> packetio::SLIPEscapeCodes
typedef EscapedPrint<SLIPEscapeCodes> packetio::SLIPPrint
typedef EscapedStream<SLIPEscapeCodes> packetio::SLIPStream