-
Notifications
You must be signed in to change notification settings - Fork 73
serde_json based FlatMapDeserializer implementation.
#684
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
Conversation
| }; | ||
|
|
||
| pub struct FlatMapDeserializer<'a, E> { | ||
| entries: &'a mut Vec<Option<(String, serde_json::Value)>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original FlatMapDeserializer, entries would be of type (Content, Content), accepting arbitrary values as key and values. Here I settled for a weaker (String, serde_json::Value) which should be enough considering Data-Integrity values are JSON documents.
| } | ||
|
|
||
| unsupported! { | ||
| deserialize_option() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original implementation can flatten options, but it uses a private API. For our use case, rejecting options should be fine.
| V: serde::de::Visitor<'de>, | ||
| { | ||
| visitor.visit_map(FlatMapAccess { | ||
| iter: self.entries.iter_mut(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original implementation, flattened maps would not consume entries. They would stay in the entry pool for subsequent flattened fields. Unfortunately we would need &serde_json::Value (reference) to implement Deserializer to preserve the same behavior, which is not the case. However I don't think that matters in our case.
| Type, | ||
| Cryptosuite, | ||
| Other(serde::__private::de::Content<'de>), | ||
| Other(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only accept string keys now. It's fine since Data-Integrity documents are JSON documents.
Just to make it easy to use the latest Rust version without conflicting warnings
Description
In the
data-integritylibrary we currently use aFlatMapDeserializerto deserialize proof/configuration types that is part ofserdeprivate API. That type is used byserde's derive macro to implement#[derive(flatten)]. However because Data Integrity proofs/configurations are so hard to deserialize, we can't useserde's derive macro, we have to implementflatten"by hand". That's because the deserialization behavior depends on the crypto suite type, which is unknown when the deserialization starts. The result is a fairly complex deserialization function that requires aFlatMapDeserializerimplementation. Unfortunatelyserderecently made it impossible to use their private API, and provides no public equivalent toFlatMapDeserializer. This PR implements a weaker but simpler version ofFlatMapDeserializerbased onserde_json::Value(to store arbitrary values deserialized during flattening).Close #681
Close #682
Close #683
Other changes
I moved all the deserialization utility types in a dedicated
de::utilsmodule.Tested