mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkReader.Length renamed for Capacity (more obvious, similar to List.Capacity)
This commit is contained in:
parent
ee6bbaa8ba
commit
d3ee9e325e
@ -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;
|
||||
|
@ -29,8 +29,11 @@ public int Remaining
|
||||
get => buffer.Count - Position;
|
||||
}
|
||||
|
||||
/// <summary>Total number of bytes to read from buffer</summary>
|
||||
public int Length
|
||||
[Obsolete("NetworkReader.Length was renamed to Capacity")] // 2022-09-25
|
||||
public int Length => Capacity;
|
||||
|
||||
/// <summary>Total buffer capacity, independent of reader position.</summary>
|
||||
public int Capacity
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => buffer.Count;
|
||||
@ -193,7 +196,7 @@ public ArraySegment<byte> 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)}";
|
||||
|
||||
/// <summary>Reads any data type that mirror supports. Uses weaver populated Reader(T).read</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -261,7 +261,7 @@ public static T[] ReadArray<T>(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}");
|
||||
}
|
||||
|
@ -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 _);
|
||||
|
Loading…
Reference in New Issue
Block a user