pub fn decode(src: &[u8], out: &mut WriteBuf<'_>) -> Result<()>Expand description
Decode one COBS block (without its 0x00 delimiter) from src into
out.
Like the reference decoder, this accepts both encodings of a payload
that ends with a full 254-byte run: with and without a trailing empty
block (0x01). encode only ever produces the shorter form. If the
encoded bytes must be canonical (for example because they are hashed or
signed), re-encode the decoded payload and compare.
§Errors
Error::InvalidEncodingifsrcis empty, contains a0x00byte, or a code byte points past the end of the block.Error::BufferFullifouthas insufficient room. The decoded size is always smaller thansrc.len().
Nothing is written on error.
§Example
use wire_codec::{cobs, WriteBuf};
let mut out = [0u8; 8];
let mut buf = WriteBuf::new(&mut out);
cobs::decode(&[0x03, 0x11, 0x22, 0x02, 0x33], &mut buf).unwrap();
assert_eq!(buf.written(), &[0x11, 0x22, 0x00, 0x33]);