diff --git a/Assets/Mirror/Runtime/NetworkReader.cs b/Assets/Mirror/Runtime/NetworkReader.cs
index 003775218..0a83663bc 100644
--- a/Assets/Mirror/Runtime/NetworkReader.cs
+++ b/Assets/Mirror/Runtime/NetworkReader.cs
@@ -33,6 +33,9 @@ public class NetworkReader
/// Total number of bytes to read from buffer
public int Length => buffer.Count;
+ /// Remaining bytes that can be read, for convenience.
+ public int Remaining => Length - Position;
+
public NetworkReader(byte[] bytes)
{
buffer = new ArraySegment(bytes);
diff --git a/Assets/Mirror/Tests/Editor/NetworkReaderTest.cs b/Assets/Mirror/Tests/Editor/NetworkReaderTest.cs
index a53b3369c..49bf1bd48 100644
--- a/Assets/Mirror/Tests/Editor/NetworkReaderTest.cs
+++ b/Assets/Mirror/Tests/Editor/NetworkReaderTest.cs
@@ -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()
{