-
Notifications
You must be signed in to change notification settings - Fork 41
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
Structs not deserializable with bincode #91
Comments
It's not a known issue, but it's possible. The serde library is format-independent but an individual Please do provide a repro. |
Here is a basic repro/test-project : When I get a sec, I can try to instrument the Deserialization functions for https://github.com/rrichardson/bincode-k8s-repro/blob/main/src/main.rs The error is |
I thought it was just a specific Endpoint example, but now I think it's everything in bincode. |
Ah, the "invalid type: sequence, expected Ingress" error made me remember. It's because bincode serializes structs as sequences of fields, and why I can see if adding sequence stuff to the codegen's |
Looking at the implementation of Deserialize, and looking at the bincode docs. I am willing to say that the two implementations are at odds with one another. serialize/deserialize_struct uses a This quote seems appropos: It is hard to get a clear picture, but it looks like |
Yes, that's the "sequence stuff" I referred to. |
Hmm.. in looking for a compact alternative to bincode, I tried MessagePack, and got exactly the same result :( MessagePack is self-describing, so I figured it'd support |
Indeed, I realized while adding the sequence stuff to the |
It's self-describing in that it encodes the type, but it doesn't encode the field name. 1 2 Without the field name it's not possible to know when a field was skipped while serializing and should thus not be deserialized either. |
That makes sense. It is my understanding that MessagePack does persist field names. So maybe the rmp implementation should be updated to support the map approach. |
It's not. Like I said in the first post, the trait impl doesn't know which format it's being used with. We could have two impls for each type gated by a feature ( So the only option I can think of is making new traits similar to serde's, and having their impls not skip optional fields. Just with this you won't be able to serialize them with serde serializers (unless you use |
It looks like serde-rs/serde#2012 would give a path forward, that is actually pretty elegant. |
Actually, I forgot that However even that won't help you with either bincode or rmp currently, because both of those don't override the default |
Right, bincode would need to be updated to process the field even when told to skip. Presently it cannot, though, because |
Might still work for rmp though? |
It might work for bincode too, actually. To be clear, I'm saying their respective impls of This scheme would work with both |
Here's what I'm proposing from k8s-openapi's side. See |
I think that makes sense. I think that this is a fairly pervasive problem in the serde ecosystem, I can test it with a modified bincode, and, if it works like we hope, propose an additional config option that would swap serialize_none for skip_field. |
I have implemented an Ingress Controller using your very helpful API. For maintaining state, I store a handful of different objects in Sled, and, to save space/cpus, I serialize into Bincode in the Sled DB.
I have noticed that several
Endpoints
objects that I get back from my k8s cluster, can not be correctly deserialized from bincode-serialized bytes. (maybe they were incorrectly serialized?).I have not yet made a minimal reproduction of this, but I can, if it helps.
If I change my serde lib to serde_json from bincode, then serialization and deserialization works just fine. I'm guessing that some facet of the data, such as an empty vector or something, in some of the live k8s objects are causing problems with bincode, since it does not produce self-describing encoded data.
I'm just checking to see if this is a known issue, if not, I'll try to make a repro of it.
The text was updated successfully, but these errors were encountered: