-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: partial backwards compatibility #159
Comments
In general, you can add enum variants and add fields to the end of a struct, BUT the issue is that this all generally breaks down if these types are nested. If you add a field to a struct that is in the middle of another struct, everything will go wrong. I don't believe this is fixable with postcard's "non self describing format" design choice. The wire format is specified enough that you could potentially add a layer on top of postcard that handles some kind of schema flexibility, but it isn't possible out of the box, as far as I am aware. |
Is it possible to provide this compatibility for non-nested simple formats? This would be really useful (undefined fields would use default values, such as Option being None and u64 being 0). For example: |
struct A {
a: u64,
b: u64,
#[serde(default)]
c: u64,
} This simple case of adding new fields (note the addition of postcard/source/postcard/src/de/deserializer.rs Lines 151 to 161 in f1c89db
However, the deserializer is generic over a Flavor , which does not require a way to tell if the input is exhausted or not:postcard/source/postcard/src/de/flavors.rs Lines 80 to 127 in f1c89db
Postcard 2.0 could add an is_empty() method to Flavor and use it to check for the exhausted input case above.
However, this would be easy to misuse with nested structs, or by forgetting to add |
I was thinking - it would be really nice to have some backwards compatibility between schemas, especially when iterating quickly on new features/comms. There's likely some ongoing or existing work/discussions regarding this (it may already exist...), but I have not been able to find a conclusive answer (docs/wire spec/etc), so I wanted to raise it here to ask.
If certain structs were frozen, it would seem that the main thing that holds back any backwards compatibility is tagged union's variant changing their discriminant during (de)serialization. Is there a way to fix this discriminant, so that I know that particular component of the comms is going to remain stable?
For example, when going from:
to
It would be great to know that the existing comms would work as before, unless you used the
MessageRequest::Shutdown
enum (for which the error could be handled). My naive view would be, if you could guarantee the discriminant for a variant (either by ordering, or by assigning a fixed "tag"), this partial backwards compatibility would be assured.The text was updated successfully, but these errors were encountered: