Skip to content

Commit

Permalink
ReadStreamToArraySegment use BufferListStream directly when available (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach authored Mar 25, 2021
1 parent 6cf719b commit db10ffc
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,17 @@ private static ArraySegment<byte> ReadStreamToArraySegment(Stream stream)
return new ArraySegment<byte>();
}

using var memStream = new MemoryStream(StreamBufferSizeInBytes);
stream.CopyTo(memStream, StreamBufferSizeInBytes);

return new ArraySegment<byte>(memStream.ToArray());
switch (stream)
{
case BufferListStream bufferListStream:
return bufferListStream.ReadBytes((int)stream.Length);
default:
{
using var memStream = new MemoryStream(StreamBufferSizeInBytes);
stream.CopyTo(memStream, StreamBufferSizeInBytes);
return new ArraySegment<byte>(memStream.ToArray());
}
}
}

public static AmqpMessage SBMessageToAmqpMessage(SBMessage sbMessage)
Expand Down

0 comments on commit db10ffc

Please sign in to comment.