-
Notifications
You must be signed in to change notification settings - Fork 174
Buffering causes async unpacking to fail #321
Copy link
Copy link
Closed
Labels
bugDetected as bugDetected as bug
Description
In the following method, each time UnpackAsync() is called it will create a new BufferedStream to wrap the existing stream. This causes data in the stream to be discarded because reading from a BufferedStream can consume more data from the underlying stream than necessary. The documentation does state "it is preferred that you should wrap with System.IO.BufferedStream yourself", but I do not believe this is the intended behavior.
public static async Task TestAsyncBuffering()
{
var context = new SerializationContext();
var serializer = context.GetSerializer<string>();
using (var stream = new MyMemoryStream()) // could also be a NetworkStream or PipeStream
{
await serializer.PackAsync(stream, "hello");
await serializer.PackAsync(stream, "world");
stream.Position = 0;
await serializer.UnpackAsync(stream);
await serializer.UnpackAsync(stream); // throws MsgPack.InvalidMessagePackStreamException
}
}
class MyMemoryStream : MemoryStream
{
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugDetected as bugDetected as bug