You can serialize a struct with the serde::Serialize
trait implemented with the following code.
Not that the alloc
feature of postcard must be enabled to use to_allocvec
.
let buffer = postcard::to_allocvec(&vehicle_state);
Deserializing is similarly simple on a struct with serde:Deserialize
implemented:
let vehicle_state = postcard::from_bytes::<VehicleState>(&buffer);
for these examples the postcard crate must be included seperately as a dependency; this library does not supply it.