mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
breaking: NetworkReader/Writer Read/WriteBytesAndSizeSegment renamed to Read/WriteArraySegmentAndSize for clarity.
This commit is contained in:
parent
e799b08303
commit
db241bb413
@ -103,10 +103,14 @@ public static byte[] ReadBytesAndSize(this NetworkReader reader)
|
|||||||
// Use checked() to force it to throw OverflowException if data is invalid
|
// Use checked() to force it to throw OverflowException if data is invalid
|
||||||
return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u)));
|
return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u)));
|
||||||
}
|
}
|
||||||
|
// DEPRECATED 2023-08-12
|
||||||
|
[Obsolete("ReadBytesAndSizeSegment was renamed to ReadArraySegmentAndSize for clarity.")]
|
||||||
|
public static ArraySegment<byte> ReadBytesAndSizeSegment(this NetworkReader reader) =>
|
||||||
|
ReadArraySegmentAndSize(reader);
|
||||||
|
|
||||||
// Reads ArraySegment and size header
|
// Reads ArraySegment and size header
|
||||||
/// <exception cref="T:OverflowException">if count is invalid</exception>
|
/// <exception cref="T:OverflowException">if count is invalid</exception>
|
||||||
public static ArraySegment<byte> ReadBytesAndSizeSegment(this NetworkReader reader)
|
public static ArraySegment<byte> ReadArraySegmentAndSize(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
// count = 0 means the array was null
|
// count = 0 means the array was null
|
||||||
// otherwise count - 1 is the length of the array
|
// otherwise count - 1 is the length of the array
|
||||||
|
@ -106,8 +106,13 @@ public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer, i
|
|||||||
writer.WriteBytes(buffer, offset, count);
|
writer.WriteBytes(buffer, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEPRECATED 2023-08-12
|
||||||
|
[Obsolete("WriteBytesAndSizeSegment was renamed to WriteArraySegmentAndSize for clarity.")]
|
||||||
|
public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment<byte> segment) =>
|
||||||
|
WriteArraySegmentAndSize(writer, segment);
|
||||||
|
|
||||||
// writes ArraySegment of byte (most common type) and size header
|
// writes ArraySegment of byte (most common type) and size header
|
||||||
public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment<byte> segment)
|
public static void WriteArraySegmentAndSize(this NetworkWriter writer, ArraySegment<byte> segment)
|
||||||
{
|
{
|
||||||
writer.WriteBytesAndSize(segment.Array, segment.Offset, segment.Count);
|
writer.WriteBytesAndSize(segment.Array, segment.Offset, segment.Count);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public void TestWritingBytesAndReadingSegment()
|
|||||||
writer.WriteBytesAndSize(data);
|
writer.WriteBytesAndSize(data);
|
||||||
|
|
||||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
ArraySegment<byte> deserialized = reader.ReadBytesAndSizeSegment();
|
ArraySegment<byte> deserialized = reader.ReadArraySegmentAndSize();
|
||||||
Assert.That(deserialized.Count, Is.EqualTo(data.Length));
|
Assert.That(deserialized.Count, Is.EqualTo(data.Length));
|
||||||
for (int i = 0; i < data.Length; ++i)
|
for (int i = 0; i < data.Length; ++i)
|
||||||
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(data[i]));
|
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(data[i]));
|
||||||
@ -172,10 +172,10 @@ public void TestWritingSegmentAndReadingSegment()
|
|||||||
// [2, 3]
|
// [2, 3]
|
||||||
ArraySegment<byte> segment = new ArraySegment<byte>(data, 1, 1);
|
ArraySegment<byte> segment = new ArraySegment<byte>(data, 1, 1);
|
||||||
NetworkWriter writer = new NetworkWriter();
|
NetworkWriter writer = new NetworkWriter();
|
||||||
writer.WriteBytesAndSizeSegment(segment);
|
writer.WriteArraySegmentAndSize(segment);
|
||||||
|
|
||||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
ArraySegment<byte> deserialized = reader.ReadBytesAndSizeSegment();
|
ArraySegment<byte> deserialized = reader.ReadArraySegmentAndSize();
|
||||||
Assert.That(deserialized.Count, Is.EqualTo(segment.Count));
|
Assert.That(deserialized.Count, Is.EqualTo(segment.Count));
|
||||||
for (int i = 0; i < segment.Count; ++i)
|
for (int i = 0; i < segment.Count; ++i)
|
||||||
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(segment.Array[segment.Offset + i]));
|
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(segment.Array[segment.Offset + i]));
|
||||||
|
Loading…
Reference in New Issue
Block a user