breaking: NetworkReader/Writer Read/WriteBytesAndSizeSegment renamed to Read/WriteArraySegmentAndSize for clarity.

This commit is contained in:
mischa 2023-08-12 19:13:15 +04:00
parent e799b08303
commit db241bb413
3 changed files with 14 additions and 5 deletions

View File

@ -103,10 +103,14 @@ public static byte[] ReadBytesAndSize(this NetworkReader reader)
// Use checked() to force it to throw OverflowException if data is invalid
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
/// <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
// otherwise count - 1 is the length of the array

View File

@ -106,8 +106,13 @@ public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer, i
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
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);
}

View File

@ -158,7 +158,7 @@ public void TestWritingBytesAndReadingSegment()
writer.WriteBytesAndSize(data);
NetworkReader reader = new NetworkReader(writer.ToArray());
ArraySegment<byte> deserialized = reader.ReadBytesAndSizeSegment();
ArraySegment<byte> deserialized = reader.ReadArraySegmentAndSize();
Assert.That(deserialized.Count, Is.EqualTo(data.Length));
for (int i = 0; i < data.Length; ++i)
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(data[i]));
@ -172,10 +172,10 @@ public void TestWritingSegmentAndReadingSegment()
// [2, 3]
ArraySegment<byte> segment = new ArraySegment<byte>(data, 1, 1);
NetworkWriter writer = new NetworkWriter();
writer.WriteBytesAndSizeSegment(segment);
writer.WriteArraySegmentAndSize(segment);
NetworkReader reader = new NetworkReader(writer.ToArray());
ArraySegment<byte> deserialized = reader.ReadBytesAndSizeSegment();
ArraySegment<byte> deserialized = reader.ReadArraySegmentAndSize();
Assert.That(deserialized.Count, Is.EqualTo(segment.Count));
for (int i = 0; i < segment.Count; ++i)
Assert.That(deserialized.Array[deserialized.Offset + i], Is.EqualTo(segment.Array[segment.Offset + i]));