diff --git a/Assets/Mirror/Core/Batching/Unbatcher.cs b/Assets/Mirror/Core/Batching/Unbatcher.cs
index 495ada90e..997b54a92 100644
--- a/Assets/Mirror/Core/Batching/Unbatcher.cs
+++ b/Assets/Mirror/Core/Batching/Unbatcher.cs
@@ -101,7 +101,7 @@ public bool GetNextMessage(out NetworkReader message, out double remoteTimeStamp
}
// was our reader pointed to anything yet?
- if (reader.Length == 0)
+ if (reader.Capacity == 0)
{
remoteTimeStamp = 0;
return false;
diff --git a/Assets/Mirror/Core/NetworkReader.cs b/Assets/Mirror/Core/NetworkReader.cs
index ab06a57f3..869f78f9a 100644
--- a/Assets/Mirror/Core/NetworkReader.cs
+++ b/Assets/Mirror/Core/NetworkReader.cs
@@ -29,8 +29,11 @@ public int Remaining
get => buffer.Count - Position;
}
- /// Total number of bytes to read from buffer
- public int Length
+ [Obsolete("NetworkReader.Length was renamed to Capacity")] // 2022-09-25
+ public int Length => Capacity;
+
+ /// Total buffer capacity, independent of reader position.
+ public int Capacity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => buffer.Count;
@@ -193,7 +196,7 @@ public ArraySegment ReadBytesSegment(int count)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() =>
- $"NetworkReader pos={Position} len={Length} buffer={BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count)}";
+ $"NetworkReader pos={Position} capacity={Capacity} buffer={BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count)}";
/// Reads any data type that mirror supports. Uses weaver populated Reader(T).read
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/Assets/Mirror/Core/NetworkReaderExtensions.cs b/Assets/Mirror/Core/NetworkReaderExtensions.cs
index fe7288f04..edbc1c4b9 100644
--- a/Assets/Mirror/Core/NetworkReaderExtensions.cs
+++ b/Assets/Mirror/Core/NetworkReaderExtensions.cs
@@ -144,7 +144,7 @@ public static ArraySegment ReadBytesAndSizeSegment(this NetworkReader read
public static Ray ReadRay(this NetworkReader reader) => reader.ReadBlittable();
public static Ray? ReadRayNullable(this NetworkReader reader) => reader.ReadBlittableNullable();
- public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader)=> reader.ReadBlittable();
+ public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader) => reader.ReadBlittable();
public static Matrix4x4? ReadMatrix4x4Nullable(this NetworkReader reader) => reader.ReadBlittableNullable();
public static Guid ReadGuid(this NetworkReader reader)
@@ -198,8 +198,8 @@ public static NetworkBehaviour ReadNetworkBehaviour(this NetworkReader reader)
NetworkIdentity identity = Utils.GetSpawnedInServerOrClient(netId);
return identity != null
- ? identity.NetworkBehaviours[componentIndex]
- : null;
+ ? identity.NetworkBehaviours[componentIndex]
+ : null;
}
public static T ReadNetworkBehaviour(this NetworkReader reader) where T : NetworkBehaviour
@@ -261,7 +261,7 @@ public static T[] ReadArray(this NetworkReader reader)
// this assumes that a reader for T reads at least 1 bytes
// we can't know the exact size of T because it could have a user created reader
// NOTE: don't add to length as it could overflow if value is int.max
- if (length > reader.Length - reader.Position)
+ if (length > reader.Capacity - reader.Position)
{
throw new EndOfStreamException($"Received array that is too large: {length}");
}
diff --git a/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs b/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs
index e4b7e02ab..1a6d54da0 100644
--- a/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs
+++ b/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs
@@ -33,7 +33,7 @@ public void GetNextMessage_True_False_False_InvalidOperationException()
// get next message, pretend we read the whole thing
bool result = unbatcher.GetNextMessage(out NetworkReader reader, out _);
Assert.That(result, Is.True);
- reader.Position = reader.Length;
+ reader.Position = reader.Capacity;
// shouldn't get another one
result = unbatcher.GetNextMessage(out reader, out _);