Skip to content

File syn_cobs.c

FileList > proto > syn_cobs.c

Go to the source code of this file

COBS packet framing implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_cobs.h"
  • #include <string.h>

Public Functions

Type Name
size_t syn_cobs_decode (const void * src, size_t src_len, void * dst)
Decode a COBS-encoded packet.
void syn_cobs_decoder_feed (SYN_COBS_Decoder * dec, uint8_t byte)
Feed a byte to the streaming decoder.
void syn_cobs_decoder_init (SYN_COBS_Decoder * dec, uint8_t * buf, size_t buf_size, SYN_COBS_PacketCallback callback, void * ctx)
Initialize streaming COBS decoder.
void syn_cobs_decoder_reset (SYN_COBS_Decoder * dec)
Reset the streaming decoder state.
size_t syn_cobs_encode (const void * src, size_t src_len, void * dst)
Encode data using COBS.

Public Functions Documentation

function syn_cobs_decode

Decode a COBS-encoded packet.

size_t syn_cobs_decode (
    const void * src,
    size_t src_len,
    void * dst
) 

Parameters:

  • src COBS-encoded data (without the 0x00 delimiter).
  • src_len Encoded length.
  • dst Output buffer (must be at least src_len).

Returns:

Number of decoded bytes, or 0 on error.


function syn_cobs_decoder_feed

Feed a byte to the streaming decoder.

void syn_cobs_decoder_feed (
    SYN_COBS_Decoder * dec,
    uint8_t byte
) 

When a 0x00 delimiter is received, the accumulated bytes are decoded and the callback is invoked with the decoded packet.

Parameters:

  • dec Decoder.
  • byte Received byte.

function syn_cobs_decoder_init

Initialize streaming COBS decoder.

void syn_cobs_decoder_init (
    SYN_COBS_Decoder * dec,
    uint8_t * buf,
    size_t buf_size,
    SYN_COBS_PacketCallback callback,
    void * ctx
) 

Parameters:

  • dec Decoder instance.
  • buf Receive buffer for accumulating encoded bytes.
  • buf_size Buffer capacity.
  • callback Called when a complete packet is decoded.
  • ctx User context for callback.

function syn_cobs_decoder_reset

Reset the streaming decoder state.

void syn_cobs_decoder_reset (
    SYN_COBS_Decoder * dec
) 

Parameters:

  • dec Decoder.

function syn_cobs_encode

Encode data using COBS.

size_t syn_cobs_encode (
    const void * src,
    size_t src_len,
    void * dst
) 

Parameters:

  • src Input data.
  • src_len Input length.
  • dst Output buffer (must be at least src_len + src_len/254 + 1).

Returns:

Number of bytes written to dst (excluding the trailing 0x00 delimiter).



The documentation for this class was generated from the following file src/syntropic/proto/syn_cobs.c