Function postcard::to_allocvec_cobs

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

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

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

Example

use postcard::to_allocvec_cobs;

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

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