serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
8.81k stars 747 forks source link

Support for SerializeMap handling all keys before all values #2750

Open cls opened 1 month ago

cls commented 1 month ago

While writing an XDR serializer, I found that I was unable to implement SerializeMap - with ints as keys - to support NFSv4's struct fattr4...

struct fattr4 {
    bitmap4         attrmask;
    attrlist4       attr_vals;
};

... without either being able to write all of the keys up front, or otherwise having to buffer all of the serialized values for attr_vals before writing attrmask followed by that data on end(). It would be significantly more memory efficient to serialize all the keys followed by all of the values, but as the documentation for serialize_entry() suggests, the expectation is that formats serialize keys and values together, which does not necessarily hold.