Jeremy
Jeremy

Reputation: 611

Serialize and Deserialize from Vec<u32>

I have a struct of 5 u32s that implements serialize/deserialize by simply serializing: (s.first, s.second, s.third, s.fourth, s.fifth).

However this needs to be packed and unpacked from a flat buffer of Vec<u32> or an Option<Vec32> that represent the data: essentially every 5 u32s is a new struct. I keep struggling with the visitor implementation. Is there an easy way to do this while sharing code between the Option and non Option cases?

I really want to do impl Serialize for Vec<MyType> (and Deserialize) but that doesn't work.

Upvotes: 1

Views: 415

Answers (1)

Jeremy
Jeremy

Reputation: 611

I ended up abandoning my Serialize and Deserialize impls and went with #[serde(with="my_mod"] for the Vec<MyType> case.

For the Option<Vec<MyType>> case I ended up creating wrapper types that inverted the relationship so that what I was really serializing/deserializing were Option<Wrapper { Vec<T> }>

Upvotes: 1

Related Questions