Function postcard::serialize_with_flavor
source ยท pub fn serialize_with_flavor<T, S, O>(value: &T, storage: S) -> Result<O>
Expand description
serialize_with_flavor()
has three generic parameters, T, F, O
.
T
: This is the type that is being serializedS
: This is the Storage that is used during serializationO
: This is the resulting storage type that is returned containing the serialized data
For more information about how Flavors work, please see the
flavors
module documentation.
use postcard::{
serialize_with_flavor,
ser_flavors::{Cobs, Slice},
};
let mut buf = [0u8; 32];
let data: &[u8] = &[0x01, 0x00, 0x20, 0x30];
let buffer = &mut [0u8; 32];
let res = serialize_with_flavor::<[u8], Cobs<Slice>, &mut [u8]>(
data,
Cobs::try_new(Slice::new(buffer)).unwrap(),
).unwrap();
assert_eq!(res, &[0x03, 0x04, 0x01, 0x03, 0x20, 0x30, 0x00]);