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?
|
// was our reader pointed to anything yet?
|
||||||
if (reader.Length == 0)
|
if (reader.Capacity == 0)
|
||||||
{
|
{
|
||||||
remoteTimeStamp = 0;
|
remoteTimeStamp = 0;
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,8 +29,11 @@ public int Remaining
|
|||||||
get => buffer.Count - Position;
|
get => buffer.Count - Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Total number of bytes to read from buffer</summary>
|
[Obsolete("NetworkReader.Length was renamed to Capacity")] // 2022-09-25
|
||||||
public int Length
|
public int Length => Capacity;
|
||||||
|
|
||||||
|
/// <summary>Total buffer capacity, independent of reader position.</summary>
|
||||||
|
public int Capacity
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => buffer.Count;
|
get => buffer.Count;
|
||||||
@ -193,7 +196,7 @@ public ArraySegment<byte> ReadBytesSegment(int count)
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override string ToString() =>
|
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>
|
/// <summary>Reads any data type that mirror supports. Uses weaver populated Reader(T).read</summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -144,7 +144,7 @@ public static ArraySegment<byte> ReadBytesAndSizeSegment(this NetworkReader read
|
|||||||
public static Ray ReadRay(this NetworkReader reader) => reader.ReadBlittable<Ray>();
|
public static Ray ReadRay(this NetworkReader reader) => reader.ReadBlittable<Ray>();
|
||||||
public static Ray? ReadRayNullable(this NetworkReader reader) => reader.ReadBlittableNullable<Ray>();
|
public static Ray? ReadRayNullable(this NetworkReader reader) => reader.ReadBlittableNullable<Ray>();
|
||||||
|
|
||||||
public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader)=> reader.ReadBlittable<Matrix4x4>();
|
public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader) => reader.ReadBlittable<Matrix4x4>();
|
||||||
public static Matrix4x4? ReadMatrix4x4Nullable(this NetworkReader reader) => reader.ReadBlittableNullable<Matrix4x4>();
|
public static Matrix4x4? ReadMatrix4x4Nullable(this NetworkReader reader) => reader.ReadBlittableNullable<Matrix4x4>();
|
||||||
|
|
||||||
public static Guid ReadGuid(this NetworkReader reader)
|
public static Guid ReadGuid(this NetworkReader reader)
|
||||||
@ -261,7 +261,7 @@ public static T[] ReadArray<T>(this NetworkReader reader)
|
|||||||
// this assumes that a reader for T reads at least 1 bytes
|
// 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
|
// 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
|
// 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}");
|
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
|
// get next message, pretend we read the whole thing
|
||||||
bool result = unbatcher.GetNextMessage(out NetworkReader reader, out _);
|
bool result = unbatcher.GetNextMessage(out NetworkReader reader, out _);
|
||||||
Assert.That(result, Is.True);
|
Assert.That(result, Is.True);
|
||||||
reader.Position = reader.Length;
|
reader.Position = reader.Capacity;
|
||||||
|
|
||||||
// shouldn't get another one
|
// shouldn't get another one
|
||||||
result = unbatcher.GetNextMessage(out reader, out _);
|
result = unbatcher.GetNextMessage(out reader, out _);
|
||||||
|
Loading…
Reference in New Issue
Block a user