mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
feature: NetworkReader.Remaining for convenience
This commit is contained in:
parent
7c91707d34
commit
ccbd6185b4
@ -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);
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user