Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cobs.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include <zephyr/sys/util.h>
#include <zephyr/net_buf.h>

Go to the source code of this file.

Data Structures

struct  cobs_encoder
 COBS streaming encoder state. More...
struct  cobs_decoder
 COBS streaming decoder state. More...

Macros

COBS Encoder/Decoder Flags

#define COBS_DEFAULT_DELIMITER   0x00
 Default COBS delimiter value.
#define COBS_FLAG_TRAILING_DELIMITER   BIT(8)
 Flag indicating that encode or decode should include a trailing delimiter.
#define COBS_FLAG_CUSTOM_DELIMITER(x)
 Macro for setting a custom delimiter in flags.

Typedefs

typedef int(* cobs_stream_cb) (const uint8_t *buf, size_t len, void *user_data)
 Callback function type for streaming COBS encoder/decoder.

Functions

static size_t cobs_max_encoded_len (size_t decoded_size, uint32_t flags)
 Calculate maximum encoded buffer size.
int cobs_encode (struct net_buf *src, struct net_buf *dst, uint32_t flags)
 COBS encoding.
int cobs_decode (struct net_buf *src, struct net_buf *dst, uint32_t flags)
 COBS decoding.
int cobs_encoder_init (struct cobs_encoder *enc, cobs_stream_cb cb, void *user_data, uint32_t flags)
 Initialize COBS streaming encoder.
int cobs_encoder_close (struct cobs_encoder *enc)
 Finalize COBS streaming encoder.
int cobs_encoder_write (struct cobs_encoder *enc, const uint8_t *buf, size_t len)
 Write data to COBS streaming encoder.
int cobs_decoder_init (struct cobs_decoder *dec, cobs_stream_cb cb, void *user_data, uint32_t flags)
 Initialize COBS streaming decoder.
int cobs_decoder_close (struct cobs_decoder *dec)
 Finalize COBS streaming decoder.
int cobs_decoder_write (struct cobs_decoder *dec, const uint8_t *buf, size_t len)
 Write data to COBS streaming decoder.

Macro Definition Documentation

◆ COBS_DEFAULT_DELIMITER

#define COBS_DEFAULT_DELIMITER   0x00

Default COBS delimiter value.

The standard COBS delimiter is zero (0x00). This is the delimiter value used when COBS_FLAG_CUSTOM_DELIMITER is not specified.

◆ COBS_FLAG_CUSTOM_DELIMITER

#define COBS_FLAG_CUSTOM_DELIMITER ( x)
Value:
((x) & 0xff)

Macro for setting a custom delimiter in flags.

The 8 LSB of "flags" is used for the delimiter value. When a custom delimiter is configured, the implementation applies an XOR operation with the delimiter value on the encoded data after encoding and before decoding. This allows COBS to work with delimiters other than zero.

Parameters
xCustom delimiter value (0-255)
Returns
Delimiter value masked to 8 bits

Example usage:

#define COBS_FLAG_TRAILING_DELIMITER
Flag indicating that encode or decode should include a trailing delimiter.
Definition cobs.h:42
#define COBS_FLAG_CUSTOM_DELIMITER(x)
Macro for setting a custom delimiter in flags.
Definition cobs.h:61
int cobs_encode(struct net_buf *src, struct net_buf *dst, uint32_t flags)
COBS encoding.

◆ COBS_FLAG_TRAILING_DELIMITER

#define COBS_FLAG_TRAILING_DELIMITER   BIT(8)

Flag indicating that encode or decode should include a trailing delimiter.

When set, the encoder will append a delimiter byte after the encoded data, and the decoder will accept a delimiter byte at the end of the encoded data.