diff --git a/Assets/Mirror/Core/NetworkReaderExtensions.cs b/Assets/Mirror/Core/NetworkReaderExtensions.cs index bb6ca31b2..51a8ed90f 100644 --- a/Assets/Mirror/Core/NetworkReaderExtensions.cs +++ b/Assets/Mirror/Core/NetworkReaderExtensions.cs @@ -78,16 +78,6 @@ public static string ReadString(this NetworkReader reader) return reader.encoding.GetString(data.Array, data.Offset, data.Count); } - /// if count is invalid - public static byte[] ReadBytesAndSize(this NetworkReader reader) - { - // count = 0 means the array was null - // otherwise count -1 is the length of the array - uint count = reader.ReadUInt(); - // Use checked() to force it to throw OverflowException if data is invalid - return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u))); - } - public static byte[] ReadBytes(this NetworkReader reader, int count) { // prevent allocation attacks with a reasonable limit. @@ -104,6 +94,17 @@ public static byte[] ReadBytes(this NetworkReader reader, int count) return bytes; } + /// if count is invalid + public static byte[] ReadBytesAndSize(this NetworkReader reader) + { + // count = 0 means the array was null + // otherwise count -1 is the length of the array + uint count = reader.ReadUInt(); + // Use checked() to force it to throw OverflowException if data is invalid + return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u))); + } + + // Reads ArraySegment and size header /// if count is invalid public static ArraySegment ReadBytesAndSizeSegment(this NetworkReader reader) { diff --git a/Assets/Mirror/Core/NetworkWriterExtensions.cs b/Assets/Mirror/Core/NetworkWriterExtensions.cs index c4de17cf9..3a1fd78f0 100644 --- a/Assets/Mirror/Core/NetworkWriterExtensions.cs +++ b/Assets/Mirror/Core/NetworkWriterExtensions.cs @@ -82,11 +82,6 @@ public static void WriteString(this NetworkWriter writer, string value) writer.Position += written; } - public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment buffer) - { - writer.WriteBytesAndSize(buffer.Array, buffer.Offset, buffer.Count); - } - // Weaver needs a write function with just one byte[] parameter // (we don't name it .Write(byte[]) because it's really a WriteBytesAndSize since we write size / null info too) @@ -113,6 +108,13 @@ public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer, i writer.WriteBytes(buffer, offset, count); } + // writes ArraySegment and size header + public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment buffer) + { + writer.WriteBytesAndSize(buffer.Array, buffer.Offset, buffer.Count); + } + + // writes ArraySegment and size header public static void WriteArraySegment(this NetworkWriter writer, ArraySegment segment) { int length = segment.Count;