I'm working on a Serde Deserializer
for the LCM format. LCM has a type specification language which is similar to C, and a code generator that produces bindings and serialization code for various languages.
In LCM, the size of a variable length array is given by an integer field declared elsewhere in the struct. Multiple arrays can share the same length, like so:
struct example {
int32_t num_readings;
float temperatures[num_readings];
float pressures[num_readings];
}
... which may result in a generated Rust struct such as
struct Example {
num_readings: i32,
temperatures: Vec<f32>,
pressures: Vec<f32>,
}
When serialized, each field/element is written to a buffer sequentially; so arrays are length-prefixed, but the length does not necessarily appear immediately before the array.
How would I go about capturing these semantics in serde? I've already implemented Serializer
, and I've mostly implemented Deserializer
. I've written a small struct which implements SeqAccess
. Everything works, except I'm not sure how to initialize that struct with the value of (in this example) num_readings
.
I feel like I should be able to something with field attributes, but I'm not sure what.