Skip to content
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

Rust: Add fn for deserializing multiple types in json from a stream #203

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

leighmcculloch
Copy link
Member

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.

@leighmcculloch leighmcculloch marked this pull request as ready for review August 28, 2024 00:27
Copy link
Contributor

@sisuresh sisuresh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@leighmcculloch leighmcculloch merged commit b7bc57e into master Aug 28, 2024
3 checks passed
@leighmcculloch leighmcculloch deleted the deserialize-json branch August 28, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants