NetworkReader.ReadBytesSegment: use .Remaining

This commit is contained in:
vis2k 2022-09-25 13:00:57 +07:00
parent 98be66ec13
commit 78fb0b57ae

View File

@ -162,8 +162,8 @@ public byte[] ReadBytes(byte[] bytes, int count)
/// <summary>Read 'count' bytes allocation-free as ArraySegment that points to the internal array.</summary>
public ArraySegment<byte> ReadBytesSegment(int count)
{
// check if within buffer limits
if (Position + count > buffer.Count)
// ensure remaining
if (Remaining < count)
{
throw new EndOfStreamException($"ReadBytesSegment can't read {count} bytes because it would read past the end of the stream. {ToString()}");
}