pub fn unstuff<const INPUT: usize, const OUTPUT: usize>(
buff: [u8; INPUT],
marker: u8
) -> ([u8; OUTPUT], usize)
Expand description
Takes an input buffer and a marker value and COBS-decodes it to an output buffer.
Removes all overhead bytes, inserts the marker where appropriate and stops immediately when
a marker value is found. The size of output buffer is at least 2 bytes smaller than the size
of the input buffer. All left-over space will and the end of the buffer and will be filled with
the 0x00
bytes. The tuple returned contains both the decoded buffer and the actual filled
length of that buffer.
Examples
let transferred_data: [u8; 258] = [
// ... snip
];
// We convert the COBS-encoded transferred_data to the plain data
// using the unstuff function.
let (plain_data, plain_data_length): ([u8; 256], usize) =
cobs_rs::unstuff(transferred_data, 0x00);
// ... snip
Panics
If we don’t have a marker value in the encoded data buffer, the function panics.
This function also panics when the output buffer doesn’t have enough space to fill the data from the input buffer with. This never happens if we reserve the maximum possible memory for the output, that being two less bytes than the input buffer.