3Hren/msgpack-rust

Add support for AsyncRead / AsyncWrite

wbrickner opened this issue · 1 comments

Hey!

I'd like to be able to create an async reader / async writer and then plug it straight into rmp_serde.

The current functions from_read have a trait bound Read, which means that I cannot (AFAIK) plug in an async stream.

I basically need to collect the entire stream async'ly, then do a sync pass with rmp_serde.

I would love rmp_serde to be able to parse long messages as they're coming over the network.

Let me know what you think, I may be asking for a lot and not know it!

I don't plan to add it, because:

  1. there's no "SAX" like API for using messages before they're fully parsed. It would be a big change to add it, and I don't think you even mean to use it like that.

  2. Without this you can't use any part of the result before downloading and passing the whole file.

  3. And because of that in 99% of cases it doesn't matter if you buffer into Vec and parse it or feed it via AsyncRW. It may even be faster to buffer, because it avoids making huge state machines.

  4. In the remaining 1% of cases it's already supported! Use async channels to send data from the stream to a thread that exposes it via Read. I know that's fiddly. I hope someone made a crate or example for it, because it should be a common need.