Function cobs_rs::stuff[][src]

pub fn stuff<const INPUT: usize, const OUTPUT: usize>(
    buff: [u8; INPUT],
    marker: u8
) -> [u8; OUTPUT]

Takes an input buffer and a marker value and COBS-encodes it to an output buffer.

Removes all occurrences of the marker value and adds one occurrence at the end. The returned buffer should at least be 2 greater than the input buffer and for roughly 256 bytes there is a possibility for an extra byte in the output buffer. All left-over space will and the end of the buffer and will be filled with the marker value.

Examples

Stuffing arbitrary data

let transfer: [u8; 256] = cobs_rs::stuff(
    *b"Hi everyone! This is a pretty nifty example.",
    b'i'
);

// Now the data won't contain 'i's anymore except for the terminator byte.

Making sure there are no null bytes anymore

let data = [
    // ...snip
];

let transfer: [u8; 256] = cobs_rs::stuff(data, 0x00);

// Now the data won't contain null bytes anymore except for the terminator byte.

Panics

This function panics when the output buffer doesn’t have enough space to fill the data from the input buffer with.