ZestCode
 
Loading...
Searching...
No Matches
cobs.h File Reference
#include <stdint.h>

Go to the source code of this file.

Macros

#define COBS_ENCODE_MEASURE_MAX(src_len)
 

Functions

int cobs_encode (uint8_t *restrict dest, const uint8_t *restrict src, const size_t src_len, const uint32_t prefix)
 
size_t cobs_encode_measure (const uint8_t *restrict src, const size_t src_len, const uint32_t prefix)
 

Detailed Description

Consistent Overhead Byte Stuffing header

See common/cobs.c for discussion

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Macro Definition Documentation

◆ COBS_ENCODE_MEASURE_MAX

#define COBS_ENCODE_MEASURE_MAX ( src_len)
Value:
((src_len) + (((src_len) + 253) / 254))

Function Documentation

◆ cobs_encode()

int cobs_encode ( uint8_t *restrict dest,
const uint8_t *restrict src,
const size_t src_len,
const uint32_t prefix )

Encodes src in the Consistent Overhead Byte Stuffing algorithm, and writes the result to dest. dest must be sufficiently long. use cobs_encode_measure() to compute the size of the buff or use COBS_ENCODE_MEASURE_MAX(src_len) macro to get the max buffer size needed (e.g. for static allocation)

Parameters
[out]destThe location to write the stuffed data to
[in]srcThe location of the incoming data
src_lenThe length of the source data
prefixThe four character stream identifier
Returns
The number of bytes written

◆ cobs_encode_measure()

size_t cobs_encode_measure ( const uint8_t *restrict src,
const size_t src_len,
const uint32_t prefix )

Same as cobs_encode() but doesn't write to an output buffer. Used to determine how much space is needed for src.

Parameters
[in]srcThe location of the incoming data
src_lenThe length of the source data
prefixThe four character stream identifier
Returns
The size of src when encoded