Rust: Add fn for deserializing multiple types in json from a stream #203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Add deserialize_json fn to the Type object for deserializing multiple types in json from a stream when the type variant is known at runtime not compile time. Also rename read_json to from_json in a backwards compatible way.
Why
In the CLI we need to be able to decode JSON for arbitrary types at runtime in much the same way we can decode XDR for arbitrary types so the commands have symmetry.
We support decoding XDR to JSON for streams, but not in reverse.
There's a function today
read_json
that can decode a JSON object into an arbitrary Type variant, but because of the interface the function used it only does so for a single JSON object and expects an EOF to occur.For streams we need to use the more complex serde interface to deserialize multiple objects from the stream.
The read_json fn is renamed to from_json to be more similar to the serde_json's own naming schemes for these two functions. It's much easier to see the correlation that the from method in our crate calls a from method on the serde_json crate which has certain meaning, vs the deserialize call which has certain meaning in that crate too.