-
Notifications
You must be signed in to change notification settings - Fork 581
Compatibility with tokio #316
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
Comments
The library is now available as |
This coupled with any improvements we can make to Do you have any thoughts on this @dtolnay? I wouldn't mind spending some time in the near-future (vague GitHub commitment) experimenting with this. |
My impression was that for streaming serialization and deserialization use cases you typically want the data to be framed, as with I might approach this by building a resumable serde_json::Value parser. Resumable meaning it can make some progress, hit a WouldBlock, and resume later from the previous incomplete state. I don't see us solving the general case of resumable parser for an arbitrary implementation of Deserialize. But going through serde_json::Value, most of the branching and processing (interpreting string escape sequences, decimal-to-binary conversion of numbers) can happen while waiting on I/O and later turning Value into T will be fast. |
Sorry @dtolnay I may have overstated my 'need' for this. It's more something I'd be interested to explore. I found my way here while playing with async response bodies in But if So that's a bit of a flimsy motivation, but I'd like to play with it. |
Triage: I still think a resumable/nonblocking way to deserialize specifically a serde_json::Value is the way to go; we don't need to solve the much bigger challenge of resuming an arbitrary implementation of Deserialize. I would be interested to have an implementation of this that we can benchmark. Since I haven't worked with tokio myself -- what's the most obvious API that would support nonblocking deserialize of Value from a byte stream? If one of you could provide a sketch of the public API here, I'll file the idea in https://github.com/dtolnay/request-for-implementation (or you can file it directly). |
@dtolnay it’s been a while since I’ve thought about this 🙂 So will post on the |
@KodrAus I don't want to beat you, I just wanna say it's still a wanted feature 😉 |
I feel like we might be able to leverage
|
@dtolnay in situations when JSON doesn't fit into RAM, and you fetch it in an async manner via streams, what is the expected out-of-the-box solution then? |
Uh oh!
There was an error while loading. Please reload this page.
Hey :)
So
serde_json
's serializer and deserializer supportWrite
andRead
respectively, but unfortunately they aren't compatible with tokio.The basic rule of I/O with
tokio
(I should contribute some docs somewhere) is that any downstream I/O operation can fail withWouldBlock
, which means "come back later". So any operations must be retryable. That isn't the case withserde_json
right now, though. For example:deserialize_enum
,remaining_depth
will not be incremented again ifvisit_enum
fails. To avoid general issues of this kind, an RAII-style lock/guard pattern might help.write_all
, which is incompatible withtokio
. Instead, you'd need to use an internal buffer.I'd personally say just documenting the incompatibility is fine for now.
I'll soon be open sourcing a library to help out with testing I/O operations, so hopefully you'll find that of use here :)
The text was updated successfully, but these errors were encountered: