I'd like to serialize my struct to binary and de-serialize it on the other end of the pipe. Is there a way to achieve this with the serialize crate? It seems to only support JSON, hex and base64.
I would suggest bincode
.
It provides encode()
and decode()
functions which operate on anything with RustcEncodable
& RustcDecodable
traits, which can generally be #[derive]
d, and return Vec<u8>
.
It has a few quirks (isize
and usize
become i64
and u64
, for example), but they are mostly there to improve portability and it tends to work as you would expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With