Function postcard::to_stdvec_cobs

source ·
pub fn to_stdvec_cobs<T>(value: &T) -> Result<Vec<u8>>where
    T: Serialize + ?Sized,
Available on crate feature use-std only.
Expand description

Serialize and COBS encode a T to a std::vec::Vec<u8>.

The terminating sentinel 0x00 byte is included in the output.


use postcard::to_stdvec_cobs;

let ser: Vec<u8> = to_stdvec_cobs(&true).unwrap();
assert_eq!(ser.as_slice(), &[0x02, 0x01, 0x00]);

let ser: Vec<u8> = to_stdvec_cobs("Hi!").unwrap();
assert_eq!(ser.as_slice(), &[0x05, 0x03, b'H', b'i', b'!', 0x00]);