2 releases

0.1.2 May 31, 2021
0.1.1 Apr 26, 2021

#1962 in Embedded development

50 downloads per month
Used in 2 crates

MIT/Apache

13KB
190 lines

rzcobs

Documentation

Reverse-Zerocompressing-COBS encoding (rzCOBS) is a variant of rCOBS which aditionally compresses messages known to contain many zero bytes.

Standard COBS/rCOBS encoding:

00000000 => end of frame
nnnnnnnn => output n-1 bytes from stream, output 0x00
11111111 => output 254 bytes from stream

rzCOBS encoding:

00000000 => end of frame
0xxxxxxx => foreach x from LSB to MSB: if x=0 output 1 byte from stream, if x=1 output 0x00
1nnnnnnn => output n+7 bytes from stream, output 0x00
11111111 => output 134 bytes from stream

Zero-compression is achieved by splitting the input in chunks of 7 bytes and encoding in a bitfield which are zeros, and then transmitting only the non-zero bytes. If there are hore than 7 non-zero bytes in a row, encoding works COBS-like, where the number of non-zero bytes is emitted. The maximum overhead is therefore ceil(n/134) bytes, for a message of n bytes.

When a message is encoded and then decoded, the result is the original message, with up to 6 zero bytes appended. Higher layer protocols must be able to deal with these appended zero bytes.

License

This work is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps