feature: NetworkReader.Remaining for convenience

This commit is contained in:
vis2k 2021-06-14 17:46:12 +08:00
parent 7c91707d34
commit ccbd6185b4
2 changed files with 17 additions and 0 deletions

View File

@ -33,6 +33,9 @@ public class NetworkReader
/// <summary>Total number of bytes to read from buffer</summary>
public int Length => buffer.Count;
/// <summary>Remaining bytes that can be read, for convenience.</summary>
public int Remaining => Length - Position;
public NetworkReader(byte[] bytes)
{
buffer = new ArraySegment<byte>(bytes);

View File

@ -45,6 +45,20 @@ public void SetBuffer()
Assert.That(reader.ReadByte(), Is.EqualTo(0x42));
}
[Test]
public void Remaining()
{
byte[] bytes = {0x00, 0x01};
NetworkReader reader = new NetworkReader(bytes);
Assert.That(reader.Remaining, Is.EqualTo(2));
reader.ReadByte();
Assert.That(reader.Remaining, Is.EqualTo(1));
reader.ReadByte();
Assert.That(reader.Remaining, Is.EqualTo(0));
}
[Test]
public void ReadBytesCountTooBigTest()
{