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

BeginDeserialize/EndDeserialize #15

Open
llint opened this issue Feb 11, 2018 · 2 comments
Open

BeginDeserialize/EndDeserialize #15

llint opened this issue Feb 11, 2018 · 2 comments

Comments

@llint
Copy link

llint commented Feb 11, 2018

Currently MsgPack.Deserialize eventually invokes Stream.Read which is blocking. It would be great if there is an asynchronous version BeginDeserialize<T>/EndDeserialize<T> that takes advantage of Stream.BeginRead / Stream.EndRead, so to make the operation asynchronous.

This is good enough for Unity3D (.NET 3.5). For higher version of the runtime (e.g. the experimental .NET 4.6), of course the TAP APIs can be added over the foundational Begin/End async API.

Currently to avoid blocking, I have to create a MemoryStream, asynchronously read (BeginRead/EndRead) from the NetworkStream, and copy the data into the MemoryStream object, and invoke MsgPack.Deserialize on the MemoryStream to make the operation fully asynchronous.

@deniszykov
Copy link
Owner

Hi @llint. Unfortunately I can not add this feature. it will require rewriting every layer of serialization/de-serialization code because stream at lowest layer.

  • User API (you are interacting with it)
  • TypeSerializer
  • Tokenizer
  • Stream

As I remember even json.NET doesn't support async serialization/de-serialization.

@deniszykov
Copy link
Owner

Currently to avoid blocking, I have to create a MemoryStream, asynchronously read (BeginRead/EndRead) from the NetworkStream, and copy the data into the MemoryStream object, and invoke.

Yep, this is only solution for this scenario if you want to avoid blocking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants