-
-
Notifications
You must be signed in to change notification settings - Fork 786
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
Added experimental support for deserializer state #1327
Conversation
I have also needed stateful serialization/deserialization so this this seems interesting. Are you aware of my https://travis-ci.org/Marwes/serde_state? This seems potentially simpler though as opposed to the separate traits and therefore derives that my fork requires. The fact that visitors and deserializers must be updated to be state aware seems to be the main issue? |
@Marwes yeah. I saw With regards to what needs to be updated: since state needs to be kept somewhere anything that involves buffering gets tricky. So if one wants to deserialize into serde-value/serde-json's value then this will obviously break stuff. The internal buffering in content I made state aware. The only thing that generally needs updating are deserializers wrapping another deserializer. I don't think that's a massive change and with some version checking that implementation can be added only if the serde version depended on has support for that method. I still don't like some parts of this design (in particular the TLS inspired |
Hmm, wouldn't say Line 714 in a916aa9
|
I'd imagine that technically the value deserializers would also need to be state aware but those could perhaps be ignored since it is probably not very useful https://docs.serde.rs/serde/de/value/index.html |
State awareness of value deserializers is not very helpful since they have no place to store the state (on the value). Yes the visitors need updating as well. Depending on how many are out there it might become more or less annoying to update. I did however so far not notice too many areas outside of serde itself that need updating (and I did not update all there yet, and there are still failing tests). |
@Marwes you're right there are more places that need state passing. Trying to hunt them all down but it's quite easy to screw up sadly :( |
I need to investigate this still so this is mostly a braindump, but I believe that the content deserializer temporarily passes through the value deserializer in a few places and that means state info is unavailable there. |
The last version of this PR now also introduces a Additionally the value deserializers now all can carry state. One problem there is that some of these were |
I just realized that |
I think other than it being very complex the biggest issue I foresee from this is To carry the state through in I'm planning on testing this for a few weeks now as it unblocks us but I probably want to see if I can simplify the design somehow. |
* master: Release 1.0.69 Local inner macros Link to issue picker Factor out the getting help links
Please reopen a pull request when you'd like for me to take a look. Thanks! |
We are currently still using this fork but if time permits we will try some alternative approaches since it's unlikely we want to stick to a permafork of serde. |
This implements the proposal in #1325. It's not great yet in performance most likely and i most likely will need to make this state feature optional but i'm generally happy with the concept behind it.
The basic idea is that some state can be associated with the deserializer that a
Deserialize
can access. Additionally a lot of these wrappers need to forward the state appropriately. Likewise the state is now stored with the internally buffered content as well as otherwise it's impossible to synchronize.The implementation uses
Rc
in a vec internally keyed byTypeId
. I'm planning on using this to pass path information and out of bounds metadata to wrapper types. The deserializer I'm using this with looks something like this:The state is injected by a wrapping deserializer:
Internally the
State
that is passed around is a copy-on-write like structure. It can be cloned and that either just bumps refcounts or copies aNone
over. I'm sure this can be optimized further if this approach seems sensible.