From cf0b884c1f572d7970740671b9c6cf315180f89c Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 25 Sep 2022 12:11:57 +0700 Subject: [PATCH] MessagePacking renamed to NetworkMessages (it contains more network message code than just packing) --- Assets/Mirror/Core/NetworkClient.cs | 15 +- Assets/Mirror/Core/NetworkConnection.cs | 2 +- .../{MessagePacking.cs => NetworkMessages.cs} | 23 +- ...acking.cs.meta => NetworkMessages.cs.meta} | 0 Assets/Mirror/Core/NetworkServer.cs | 24 +- Assets/Mirror/Tests/Editor/CustomRWTest.cs | 9 +- .../Generated/CollectionWriterTests.gen.cs | 553 ++++++------------ .../Tests/Editor/NetworkMessageTests.cs | 12 +- ...ePackingTest.cs => NetworkMessagesTest.cs} | 38 +- ...st.cs.meta => NetworkMessagesTest.cs.meta} | 0 .../Mirror/Tests/Editor/NetworkServerTest.cs | 10 +- .../Mirror/Tests/Editor/OverloadMethodTest.cs | 18 +- .../Editor/ScriptableObjectWriterTest.cs | 12 +- 13 files changed, 244 insertions(+), 472 deletions(-) rename Assets/Mirror/Core/{MessagePacking.cs => NetworkMessages.cs} (82%) rename Assets/Mirror/Core/{MessagePacking.cs.meta => NetworkMessages.cs.meta} (100%) rename Assets/Mirror/Tests/Editor/{MessagePackingTest.cs => NetworkMessagesTest.cs} (75%) rename Assets/Mirror/Tests/Editor/{MessagePackingTest.cs.meta => NetworkMessagesTest.cs.meta} (100%) diff --git a/Assets/Mirror/Core/NetworkClient.cs b/Assets/Mirror/Core/NetworkClient.cs index 2ea738f1b..37efd1de9 100644 --- a/Assets/Mirror/Core/NetworkClient.cs +++ b/Assets/Mirror/Core/NetworkClient.cs @@ -280,7 +280,7 @@ static void OnTransportConnected() // helper function static bool UnpackAndInvoke(NetworkReader reader, int channelId) { - if (MessagePacking.UnpackId(reader, out ushort msgType)) + if (NetworkMessages.UnpackId(reader, out ushort msgType)) { // try to invoke the handler for that message if (handlers.TryGetValue(msgType, out NetworkMessageDelegate handler)) @@ -347,7 +347,7 @@ internal static void OnTransportData(ArraySegment data, int channelId) unbatcher.GetNextMessage(out NetworkReader reader, out double remoteTimestamp)) { // enough to read at least header size? - if (reader.Remaining >= MessagePacking.IdSize) + if (reader.Remaining >= NetworkMessages.IdSize) { // make remoteTimeStamp available to the user connection.remoteTimeStamp = remoteTimestamp; @@ -462,16 +462,17 @@ public static void Send(T message, int channelId = Channels.Reliable) public static void RegisterHandler(Action handler, bool requireAuthentication = true) where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); + ushort msgType = NetworkMessages.GetId(); if (handlers.ContainsKey(msgType)) { Debug.LogWarning($"NetworkClient.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning."); } + // we use the same WrapHandler function for server and client. // so let's wrap it to ignore the NetworkConnection parameter. // it's not needed on client. it's always NetworkClient.connection. void HandlerWrapped(NetworkConnection _, T value) => handler(value); - handlers[msgType] = MessagePacking.WrapHandler((Action) HandlerWrapped, requireAuthentication); + handlers[msgType] = NetworkMessages.WrapHandler((Action)HandlerWrapped, requireAuthentication); } /// Replace a handler for a particular message type. Should require authentication by default. @@ -480,8 +481,8 @@ public static void RegisterHandler(Action handler, bool requireAuthenticat public static void ReplaceHandler(Action handler, bool requireAuthentication = true) where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); - handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication); + ushort msgType = NetworkMessages.GetId(); + handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication); } /// Replace a handler for a particular message type. Should require authentication by default. @@ -498,7 +499,7 @@ public static bool UnregisterHandler() where T : struct, NetworkMessage { // use int to minimize collisions - ushort msgType = MessagePacking.GetId(); + ushort msgType = NetworkMessages.GetId(); return handlers.Remove(msgType); } diff --git a/Assets/Mirror/Core/NetworkConnection.cs b/Assets/Mirror/Core/NetworkConnection.cs index 92b78d1dc..9c9a514cc 100644 --- a/Assets/Mirror/Core/NetworkConnection.cs +++ b/Assets/Mirror/Core/NetworkConnection.cs @@ -134,7 +134,7 @@ public void Send(T message, int channelId = Channels.Reliable) using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { // pack message and send allocation free - MessagePacking.Pack(message, writer); + NetworkMessages.Pack(message, writer); NetworkDiagnostics.OnSend(message, channelId, writer.Position, 1); Send(writer.ToArraySegment(), channelId); } diff --git a/Assets/Mirror/Core/MessagePacking.cs b/Assets/Mirror/Core/NetworkMessages.cs similarity index 82% rename from Assets/Mirror/Core/MessagePacking.cs rename to Assets/Mirror/Core/NetworkMessages.cs index 08d065b12..7539c2e05 100644 --- a/Assets/Mirror/Core/MessagePacking.cs +++ b/Assets/Mirror/Core/NetworkMessages.cs @@ -4,12 +4,33 @@ namespace Mirror { + [Obsolete("MessagePacking.* was renamed to NetworkMessages.*")] // 2022-09-25 + public static class MessagePacking + { + public static int HeaderSize => IdSize; + public static int IdSize => NetworkMessages.IdSize; + public static int MaxContentSize => NetworkMessages.MaxContentSize; + public static ushort GetId() where T : struct, NetworkMessage => NetworkMessages.GetId(); + public static void Pack(T message, NetworkWriter writer) + where T : struct, NetworkMessage => + NetworkMessages.Pack(message, writer); + public static bool Unpack(NetworkReader reader, out ushort messageId) => NetworkMessages.UnpackId(reader, out messageId); + public static bool UnpackId(NetworkReader reader, out ushort messageId) => NetworkMessages.UnpackId(reader, out messageId); + internal static NetworkMessageDelegate WrapHandler(Action handler, bool requireAuthentication) + where T : struct, NetworkMessage + where C : NetworkConnection + => (conn, reader, channelId) => NetworkMessages.WrapHandler(handler, requireAuthentication); + internal static NetworkMessageDelegate WrapHandler(Action handler, bool requireAuthentication) + where T : struct, NetworkMessage + where C : NetworkConnection => NetworkMessages.WrapHandler(handler, requireAuthentication); + } + // message packing all in one place, instead of constructing headers in all // kinds of different places // // MsgType (2 bytes) // Content (ContentSize bytes) - public static class MessagePacking + public static class NetworkMessages { [Obsolete("HeaderSize was renamed to IdSize")] // 2022-09-25 public static int HeaderSize => IdSize; diff --git a/Assets/Mirror/Core/MessagePacking.cs.meta b/Assets/Mirror/Core/NetworkMessages.cs.meta similarity index 100% rename from Assets/Mirror/Core/MessagePacking.cs.meta rename to Assets/Mirror/Core/NetworkMessages.cs.meta diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index e6777f5a1..a6d90b80e 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -295,7 +295,7 @@ public static void SendToAll(T message, int channelId = Channels.Reliable, bo using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { // pack message only once - MessagePacking.Pack(message, writer); + NetworkMessages.Pack(message, writer); ArraySegment segment = writer.ToArraySegment(); // filter and then send to all internet connections at once @@ -341,7 +341,7 @@ static void SendToObservers(NetworkIdentity identity, T message, int channelI using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { // pack message into byte[] once - MessagePacking.Pack(message, writer); + NetworkMessages.Pack(message, writer); ArraySegment segment = writer.ToArraySegment(); foreach (NetworkConnectionToClient conn in identity.observers.Values) @@ -365,7 +365,7 @@ public static void SendToReadyObservers(NetworkIdentity identity, T message, using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { // pack message only once - MessagePacking.Pack(message, writer); + NetworkMessages.Pack(message, writer); ArraySegment segment = writer.ToArraySegment(); int count = 0; @@ -445,7 +445,7 @@ internal static void OnConnected(NetworkConnectionToClient conn) static bool UnpackAndInvoke(NetworkConnectionToClient connection, NetworkReader reader, int channelId) { - if (MessagePacking.UnpackId(reader, out ushort msgType)) + if (NetworkMessages.UnpackId(reader, out ushort msgType)) { // try to invoke the handler for that message if (handlers.TryGetValue(msgType, out NetworkMessageDelegate handler)) @@ -507,7 +507,7 @@ internal static void OnTransportData(int connectionId, ArraySegment data, connection.unbatcher.GetNextMessage(out NetworkReader reader, out double remoteTimestamp)) { // enough to read at least header size? - if (reader.Remaining >= MessagePacking.IdSize) + if (reader.Remaining >= NetworkMessages.IdSize) { // make remoteTimeStamp available to the user connection.remoteTimeStamp = remoteTimestamp; @@ -608,12 +608,12 @@ static void OnTransportError(int connectionId, TransportError error, string reas public static void RegisterHandler(Action handler, bool requireAuthentication = true) where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); + ushort msgType = NetworkMessages.GetId(); if (handlers.ContainsKey(msgType)) { Debug.LogWarning($"NetworkServer.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning."); } - handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication); + handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication); } /// Register a handler for message type T. Most should require authentication. @@ -621,20 +621,20 @@ public static void RegisterHandler(Action handl public static void RegisterHandler(Action handler, bool requireAuthentication = true) where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); + ushort msgType = NetworkMessages.GetId(); if (handlers.ContainsKey(msgType)) { Debug.LogWarning($"NetworkServer.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning."); } - handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication); + handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication); } /// Replace a handler for message type T. Most should require authentication. public static void ReplaceHandler(Action handler, bool requireAuthentication = true) where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); - handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication); + ushort msgType = NetworkMessages.GetId(); + handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication); } /// Replace a handler for message type T. Most should require authentication. @@ -648,7 +648,7 @@ public static void ReplaceHandler(Action handler, bool requireAuthenticati public static void UnregisterHandler() where T : struct, NetworkMessage { - ushort msgType = MessagePacking.GetId(); + ushort msgType = NetworkMessages.GetId(); handlers.Remove(msgType); } diff --git a/Assets/Mirror/Tests/Editor/CustomRWTest.cs b/Assets/Mirror/Tests/Editor/CustomRWTest.cs index 3b015b383..900f7a3dc 100644 --- a/Assets/Mirror/Tests/Editor/CustomRWTest.cs +++ b/Assets/Mirror/Tests/Editor/CustomRWTest.cs @@ -40,13 +40,10 @@ public struct QuestMessage : NetworkMessage [Test] public void TestCustomRW() { - QuestMessage message = new QuestMessage - { - quest = new MockQuest(100) - }; + QuestMessage message = new QuestMessage {quest = new MockQuest(100)}; - byte[] data = MessagePackingTest.PackToByteArray(message); - QuestMessage unpacked = MessagePackingTest.UnpackFromByteArray(data); + byte[] data = NetworkMessagesTest.PackToByteArray(message); + QuestMessage unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Assert.That(unpacked.quest.Id, Is.EqualTo(100)); } } diff --git a/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs b/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs index 081b7f4c0..047a87913 100644 --- a/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs +++ b/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs @@ -8,7 +8,7 @@ namespace Mirror.Tests.Generated.CollectionWriters { public struct FloatStringStruct { - public float value; + public float value; public string anotherValue; } @@ -27,14 +27,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); int[] unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -43,14 +40,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new int[] {} - }; + Message message = new Message {collection = new int[] {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); int[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -60,17 +54,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new int[] - { - 3, 4, 5 - } - }; + Message message = new Message {collection = new int[] {3, 4, 5}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); int[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -91,14 +79,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); string[] unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -107,14 +92,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new string[] {} - }; + Message message = new Message {collection = new string[] {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); string[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -124,17 +106,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new string[] - { - "Some", "String", "Value" - } - }; + Message message = new Message {collection = new string[] {"Some", "String", "Value"}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); string[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -155,14 +131,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Vector3[] unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -171,14 +144,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new Vector3[] {} - }; + Message message = new Message {collection = new Vector3[] {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Vector3[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -188,17 +158,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new Vector3[] - { - new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9) - } - }; + Message message = new Message {collection = new Vector3[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Vector3[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -219,14 +183,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); FloatStringStruct[] unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -235,14 +196,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new FloatStringStruct[] {} - }; + Message message = new Message {collection = new FloatStringStruct[] {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); FloatStringStruct[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -252,24 +210,18 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new FloatStringStruct[] - { - new FloatStringStruct { value = 3, anotherValue = "Some" }, new FloatStringStruct { value = 4, anotherValue = "String" }, new FloatStringStruct { value = 5, anotherValue = "Values" } - } - }; + Message message = new Message {collection = new FloatStringStruct[] {new FloatStringStruct {value = 3, anotherValue = "Some"}, new FloatStringStruct {value = 4, anotherValue = "String"}, new FloatStringStruct {value = 5, anotherValue = "Values"}}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); FloatStringStruct[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); Assert.IsNotEmpty(unpackedCollection); - Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct { value = 3, anotherValue = "Some" })); - Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct { value = 4, anotherValue = "String" })); - Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct { value = 5, anotherValue = "Values" })); + Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct {value = 3, anotherValue = "Some"})); + Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct {value = 4, anotherValue = "String"})); + Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct {value = 5, anotherValue = "Values"})); } } @@ -283,14 +235,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ClassWithNoConstructor[] unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -299,14 +248,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new ClassWithNoConstructor[] {} - }; + Message message = new Message {collection = new ClassWithNoConstructor[] {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ClassWithNoConstructor[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -316,24 +262,18 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new ClassWithNoConstructor[] - { - new ClassWithNoConstructor { a = 3 }, new ClassWithNoConstructor { a = 4 }, new ClassWithNoConstructor { a = 5 } - } - }; + Message message = new Message {collection = new ClassWithNoConstructor[] {new ClassWithNoConstructor {a = 3}, new ClassWithNoConstructor {a = 4}, new ClassWithNoConstructor {a = 5}}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ClassWithNoConstructor[] unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); Assert.IsNotEmpty(unpackedCollection); - Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor { a = 3 }.a)); - Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor { a = 4 }.a)); - Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor { a = 5 }.a)); + Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor {a = 3}.a)); + Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor {a = 4}.a)); + Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor {a = 5}.a)); } } @@ -347,14 +287,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.That(unpackedCollection.Array, Is.Null.Or.Empty); @@ -363,21 +300,13 @@ public void SendsNull() [Test] public void SendsEmpty() { - int[] array = new int[] - { - default, - default, - default, - }; + int[] array = new int[] {default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 0, 0) - }; + Message message = new Message {collection = new ArraySegment(array, 0, 0)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -387,24 +316,14 @@ public void SendsEmpty() [Test] public void SendsData() { - int[] array = new int[] - { - default, - 3, 4, 5, - default, - default, - default, - }; + int[] array = new int[] {default, 3, 4, 5, default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 1, 3) - }; + Message message = new Message {collection = new ArraySegment(array, 1, 3)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -425,14 +344,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.That(unpackedCollection.Array, Is.Null.Or.Empty); @@ -441,21 +357,13 @@ public void SendsNull() [Test] public void SendsEmpty() { - string[] array = new string[] - { - default, - default, - default, - }; + string[] array = new string[] {default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 0, 0) - }; + Message message = new Message {collection = new ArraySegment(array, 0, 0)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -465,24 +373,14 @@ public void SendsEmpty() [Test] public void SendsData() { - string[] array = new string[] - { - default, - "Some", "String", "Value", - default, - default, - default, - }; + string[] array = new string[] {default, "Some", "String", "Value", default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 1, 3) - }; + Message message = new Message {collection = new ArraySegment(array, 1, 3)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -503,14 +401,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.That(unpackedCollection.Array, Is.Null.Or.Empty); @@ -519,21 +414,13 @@ public void SendsNull() [Test] public void SendsEmpty() { - Vector3[] array = new Vector3[] - { - default, - default, - default, - }; + Vector3[] array = new Vector3[] {default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 0, 0) - }; + Message message = new Message {collection = new ArraySegment(array, 0, 0)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -543,24 +430,14 @@ public void SendsEmpty() [Test] public void SendsData() { - Vector3[] array = new Vector3[] - { - default, - new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9), - default, - default, - default, - }; + Vector3[] array = new Vector3[] {default, new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9), default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 1, 3) - }; + Message message = new Message {collection = new ArraySegment(array, 1, 3)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -581,14 +458,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.That(unpackedCollection.Array, Is.Null.Or.Empty); @@ -597,21 +471,13 @@ public void SendsNull() [Test] public void SendsEmpty() { - FloatStringStruct[] array = new FloatStringStruct[] - { - default, - default, - default, - }; + FloatStringStruct[] array = new FloatStringStruct[] {default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 0, 0) - }; + Message message = new Message {collection = new ArraySegment(array, 0, 0)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -621,31 +487,21 @@ public void SendsEmpty() [Test] public void SendsData() { - FloatStringStruct[] array = new FloatStringStruct[] - { - default, - new FloatStringStruct { value = 3, anotherValue = "Some" }, new FloatStringStruct { value = 4, anotherValue = "String" }, new FloatStringStruct { value = 5, anotherValue = "Values" }, - default, - default, - default, - }; + FloatStringStruct[] array = new FloatStringStruct[] {default, new FloatStringStruct {value = 3, anotherValue = "Some"}, new FloatStringStruct {value = 4, anotherValue = "String"}, new FloatStringStruct {value = 5, anotherValue = "Values"}, default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 1, 3) - }; + Message message = new Message {collection = new ArraySegment(array, 1, 3)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); Assert.IsNotEmpty(unpackedCollection.Array); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 0], Is.EqualTo(new FloatStringStruct { value = 3, anotherValue = "Some" })); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 1], Is.EqualTo(new FloatStringStruct { value = 4, anotherValue = "String" })); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 2], Is.EqualTo(new FloatStringStruct { value = 5, anotherValue = "Values" })); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 0], Is.EqualTo(new FloatStringStruct {value = 3, anotherValue = "Some"})); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 1], Is.EqualTo(new FloatStringStruct {value = 4, anotherValue = "String"})); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 2], Is.EqualTo(new FloatStringStruct {value = 5, anotherValue = "Values"})); } } @@ -659,14 +515,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.That(unpackedCollection.Array, Is.Null.Or.Empty); @@ -675,21 +528,13 @@ public void SendsNull() [Test] public void SendsEmpty() { - ClassWithNoConstructor[] array = new ClassWithNoConstructor[] - { - default, - default, - default, - }; + ClassWithNoConstructor[] array = new ClassWithNoConstructor[] {default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 0, 0) - }; + Message message = new Message {collection = new ArraySegment(array, 0, 0)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); @@ -699,31 +544,21 @@ public void SendsEmpty() [Test] public void SendsData() { - ClassWithNoConstructor[] array = new ClassWithNoConstructor[] - { - default, - new ClassWithNoConstructor { a = 3 }, new ClassWithNoConstructor { a = 4 }, new ClassWithNoConstructor { a = 5 }, - default, - default, - default, - }; + ClassWithNoConstructor[] array = new ClassWithNoConstructor[] {default, new ClassWithNoConstructor {a = 3}, new ClassWithNoConstructor {a = 4}, new ClassWithNoConstructor {a = 5}, default, default, default,}; - Message message = new Message - { - collection = new ArraySegment(array, 1, 3) - }; + Message message = new Message {collection = new ArraySegment(array, 1, 3)}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); ArraySegment unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection.Array); Assert.IsNotEmpty(unpackedCollection.Array); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 0].a, Is.EqualTo(new ClassWithNoConstructor { a = 3 }.a)); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 1].a, Is.EqualTo(new ClassWithNoConstructor { a = 4 }.a)); - Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 2].a, Is.EqualTo(new ClassWithNoConstructor { a = 5 }.a)); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 0].a, Is.EqualTo(new ClassWithNoConstructor {a = 3}.a)); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 1].a, Is.EqualTo(new ClassWithNoConstructor {a = 4}.a)); + Assert.That(unpackedCollection.Array[unpackedCollection.Offset + 2].a, Is.EqualTo(new ClassWithNoConstructor {a = 5}.a)); } } @@ -737,14 +572,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -753,14 +585,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new List {} - }; + Message message = new Message {collection = new List {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -770,17 +599,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new List - { - 3, 4, 5 - } - }; + Message message = new Message {collection = new List {3, 4, 5}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -801,14 +624,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -817,14 +637,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new List {} - }; + Message message = new Message {collection = new List {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -834,17 +651,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new List - { - "Some", "String", "Value" - } - }; + Message message = new Message {collection = new List {"Some", "String", "Value"}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -865,14 +676,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -881,14 +689,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new List {} - }; + Message message = new Message {collection = new List {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -898,17 +703,11 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new List - { - new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9) - } - }; + Message message = new Message {collection = new List {new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -929,14 +728,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -945,14 +741,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new List {} - }; + Message message = new Message {collection = new List {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -962,24 +755,18 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new List - { - new FloatStringStruct { value = 3, anotherValue = "Some" }, new FloatStringStruct { value = 4, anotherValue = "String" }, new FloatStringStruct { value = 5, anotherValue = "Values" } - } - }; + Message message = new Message {collection = new List {new FloatStringStruct {value = 3, anotherValue = "Some"}, new FloatStringStruct {value = 4, anotherValue = "String"}, new FloatStringStruct {value = 5, anotherValue = "Values"}}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); Assert.IsNotEmpty(unpackedCollection); - Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct { value = 3, anotherValue = "Some" })); - Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct { value = 4, anotherValue = "String" })); - Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct { value = 5, anotherValue = "Values" })); + Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct {value = 3, anotherValue = "Some"})); + Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct {value = 4, anotherValue = "String"})); + Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct {value = 5, anotherValue = "Values"})); } } @@ -993,14 +780,11 @@ public struct Message : NetworkMessage [Test] public void SendsNull() { - Message message = new Message - { - collection = default - }; + Message message = new Message {collection = default}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.That(unpackedCollection, Is.Null.Or.Empty); @@ -1009,14 +793,11 @@ public void SendsNull() [Test] public void SendsEmpty() { - Message message = new Message - { - collection = new List {} - }; + Message message = new Message {collection = new List {}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); @@ -1026,24 +807,18 @@ public void SendsEmpty() [Test] public void SendsData() { - Message message = new Message - { - collection = new List - { - new ClassWithNoConstructor { a = 3 }, new ClassWithNoConstructor { a = 4 }, new ClassWithNoConstructor { a = 5 } - } - }; + Message message = new Message {collection = new List {new ClassWithNoConstructor {a = 3}, new ClassWithNoConstructor {a = 4}, new ClassWithNoConstructor {a = 5}}}; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - Message unpacked = MessagePackingTest.UnpackFromByteArray(data); + Message unpacked = NetworkMessagesTest.UnpackFromByteArray(data); List unpackedCollection = unpacked.collection; Assert.IsNotNull(unpackedCollection); Assert.IsNotEmpty(unpackedCollection); - Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor { a = 3 }.a)); - Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor { a = 4 }.a)); - Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor { a = 5 }.a)); + Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor {a = 3}.a)); + Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor {a = 4}.a)); + Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor {a = 5}.a)); } } } diff --git a/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs b/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs index 50e6cea19..ed287686b 100644 --- a/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs @@ -4,7 +4,7 @@ namespace Mirror.Tests.MessageTests { struct TestMessage : NetworkMessage { - public int IntValue; + public int IntValue; public string StringValue; public double DoubleValue; @@ -32,7 +32,7 @@ public void Serialize(NetworkWriter writer) struct StructWithEmptyMethodMessage : NetworkMessage { - public int IntValue; + public int IntValue; public string StringValue; public double DoubleValue; } @@ -44,8 +44,8 @@ public class NetworkMessageTests [Test] public void StructWithMethods() { - byte[] bytes = MessagePackingTest.PackToByteArray(new TestMessage(1, "2", 3.3)); - TestMessage message = MessagePackingTest.UnpackFromByteArray(bytes); + byte[] bytes = NetworkMessagesTest.PackToByteArray(new TestMessage(1, "2", 3.3)); + TestMessage message = NetworkMessagesTest.UnpackFromByteArray(bytes); Assert.AreEqual(1, message.IntValue); } @@ -54,8 +54,8 @@ public void StructWithMethods() [Test] public void StructWithEmptyMethods() { - byte[] bytes = MessagePackingTest.PackToByteArray(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 }); - StructWithEmptyMethodMessage message = MessagePackingTest.UnpackFromByteArray(bytes); + byte[] bytes = NetworkMessagesTest.PackToByteArray(new StructWithEmptyMethodMessage {IntValue = 1, StringValue = "2", DoubleValue = 3.3}); + StructWithEmptyMethodMessage message = NetworkMessagesTest.UnpackFromByteArray(bytes); Assert.AreEqual(1, message.IntValue); Assert.AreEqual("2", message.StringValue); diff --git a/Assets/Mirror/Tests/Editor/MessagePackingTest.cs b/Assets/Mirror/Tests/Editor/NetworkMessagesTest.cs similarity index 75% rename from Assets/Mirror/Tests/Editor/MessagePackingTest.cs rename to Assets/Mirror/Tests/Editor/NetworkMessagesTest.cs index 52ad7d738..ac3b638db 100644 --- a/Assets/Mirror/Tests/Editor/MessagePackingTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkMessagesTest.cs @@ -6,9 +6,11 @@ namespace Mirror.Tests { [TestFixture] - public class MessagePackingTest + public class NetworkMessagesTest { - public struct EmptyMessage : NetworkMessage {} + public struct EmptyMessage : NetworkMessage + { + } // helper function to pack message into a simple byte[] public static byte[] PackToByteArray(T message) @@ -16,7 +18,7 @@ public static byte[] PackToByteArray(T message) { using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { - MessagePacking.Pack(message, writer); + NetworkMessages.Pack(message, writer); return writer.ToArray(); } } @@ -27,7 +29,7 @@ public static T UnpackFromByteArray(byte[] data) { using (NetworkReaderPooled networkReader = NetworkReaderPool.Get(data)) { - int msgType = MessagePacking.GetId(); + int msgType = NetworkMessages.GetId(); int id = networkReader.ReadUShort(); if (id != msgType) @@ -44,17 +46,13 @@ public void GetId() { // "Mirror.Tests.MessageTests.TestMessage" Debug.Log(typeof(TestMessage).FullName); - Assert.That(MessagePacking.GetId(), Is.EqualTo(0x8706)); + Assert.That(NetworkMessages.GetId(), Is.EqualTo(0x8706)); } [Test] public void TestPacking() { - TestMessage message = new TestMessage() - { - IntValue = 42, - StringValue = "Hello world" - }; + TestMessage message = new TestMessage() {IntValue = 42, StringValue = "Hello world"}; byte[] data = PackToByteArray(message); @@ -83,11 +81,7 @@ public void TestUnpackIdMismatch() // Unpack has a id != msgType case that throws a FormatException. // let's try to trigger it. - TestMessage message = new TestMessage() - { - IntValue = 42, - StringValue = "Hello world" - }; + TestMessage message = new TestMessage() {IntValue = 42, StringValue = "Hello world"}; byte[] data = PackToByteArray(message); @@ -105,16 +99,12 @@ public void TestUnpackIdMismatch() public void TestUnpackMessageNonGeneric() { // try a regular message - TestMessage message = new TestMessage() - { - IntValue = 42, - StringValue = "Hello world" - }; + TestMessage message = new TestMessage() {IntValue = 42, StringValue = "Hello world"}; byte[] data = PackToByteArray(message); NetworkReader reader = new NetworkReader(data); - bool result = MessagePacking.Unpack(reader, out ushort msgType); + bool result = NetworkMessages.UnpackId(reader, out ushort msgType); Assert.That(result, Is.EqualTo(true)); Assert.That(msgType, Is.EqualTo(BitConverter.ToUInt16(data, 0))); } @@ -124,7 +114,7 @@ public void UnpackInvalidMessage() { // try an invalid message NetworkReader reader2 = new NetworkReader(new byte[0]); - bool result2 = MessagePacking.Unpack(reader2, out ushort msgType2); + bool result2 = NetworkMessages.UnpackId(reader2, out ushort msgType2); Assert.That(result2, Is.EqualTo(false)); Assert.That(msgType2, Is.EqualTo(0)); } @@ -133,11 +123,11 @@ public void UnpackInvalidMessage() public void MessageIdIsCorrectLength() { NetworkWriter writer = new NetworkWriter(); - MessagePacking.Pack(new EmptyMessage(), writer); + NetworkMessages.Pack(new EmptyMessage(), writer); ArraySegment segment = writer.ToArraySegment(); - Assert.That(segment.Count, Is.EqualTo(MessagePacking.HeaderSize), "Empty message should have same size as HeaderSize"); + Assert.That(segment.Count, Is.EqualTo(NetworkMessages.IdSize), "Empty message should have same size as HeaderSize"); } } } diff --git a/Assets/Mirror/Tests/Editor/MessagePackingTest.cs.meta b/Assets/Mirror/Tests/Editor/NetworkMessagesTest.cs.meta similarity index 100% rename from Assets/Mirror/Tests/Editor/MessagePackingTest.cs.meta rename to Assets/Mirror/Tests/Editor/NetworkMessagesTest.cs.meta diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 83119a976..ed82a0369 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -398,7 +398,7 @@ public void Send_ClientToServerMessage_MaxMessageSize() ConnectClientBlocking(out _); // send message & process - int max = MessagePacking.MaxContentSize; + int max = NetworkMessages.MaxContentSize; NetworkClient.Send(new VariableSizedMessage(max)); ProcessMessages(); @@ -419,7 +419,7 @@ public void Send_ServerToClientMessage_MaxMessageSize() ConnectClientBlocking(out NetworkConnectionToClient connectionToClient); // send message & process - int max = MessagePacking.MaxContentSize; + int max = NetworkMessages.MaxContentSize; connectionToClient.Send(new VariableSizedMessage(max)); ProcessMessages(); @@ -443,7 +443,7 @@ public void Send_ClientToServerMessage_LargerThanMaxMessageSize() // send message & process int transportMax = transport.GetMaxPacketSize(Channels.Reliable); - int messageMax = MessagePacking.MaxContentSize; + int messageMax = NetworkMessages.MaxContentSize; LogAssert.Expect(LogType.Error, $"NetworkConnection.ValidatePacketSize: cannot send packet larger than {transportMax} bytes, was {transportMax + 1} bytes"); NetworkClient.Send(new VariableSizedMessage(messageMax + 1)); ProcessMessages(); @@ -466,7 +466,7 @@ public void Send_ServerToClientMessage_LargerThanMaxMessageSize() // send message & process int transportMax = transport.GetMaxPacketSize(Channels.Reliable); - int messageMax = MessagePacking.MaxContentSize; + int messageMax = NetworkMessages.MaxContentSize; LogAssert.Expect(LogType.Error, $"NetworkConnection.ValidatePacketSize: cannot send packet larger than {transportMax} bytes, was {transportMax + 1} bytes"); connectionToClient.Send(new VariableSizedMessage(messageMax + 1)); ProcessMessages(); @@ -712,7 +712,7 @@ public void OnDataReceivedInvalidConnectionId() NetworkServer.Listen(1); // serialize a test message into an arraysegment - byte[] message = MessagePackingTest.PackToByteArray(new TestMessage1()); + byte[] message = NetworkMessagesTest.PackToByteArray(new TestMessage1()); // call transport.OnDataReceived with an invalid connectionId // an error log is expected. diff --git a/Assets/Mirror/Tests/Editor/OverloadMethodTest.cs b/Assets/Mirror/Tests/Editor/OverloadMethodTest.cs index 56313714d..76476590c 100644 --- a/Assets/Mirror/Tests/Editor/OverloadMethodTest.cs +++ b/Assets/Mirror/Tests/Editor/OverloadMethodTest.cs @@ -26,13 +26,10 @@ public class OverloadMethodTest public void MethodsWithNoArgs() { const int value = 10; - NoArgMethodMessage intMessage = new NoArgMethodMessage - { - someValue = value - }; + NoArgMethodMessage intMessage = new NoArgMethodMessage {someValue = value}; - byte[] data = MessagePackingTest.PackToByteArray(intMessage); - NoArgMethodMessage unpacked = MessagePackingTest.UnpackFromByteArray(data); + byte[] data = NetworkMessagesTest.PackToByteArray(intMessage); + NoArgMethodMessage unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Assert.That(unpacked.someValue, Is.EqualTo(value)); } @@ -40,13 +37,10 @@ public void MethodsWithNoArgs() public void MethodsWithTwoArgs() { const int value = 10; - TwoArgMethodMessage intMessage = new TwoArgMethodMessage - { - someValue = value - }; + TwoArgMethodMessage intMessage = new TwoArgMethodMessage {someValue = value}; - byte[] data = MessagePackingTest.PackToByteArray(intMessage); - TwoArgMethodMessage unpacked = MessagePackingTest.UnpackFromByteArray(data); + byte[] data = NetworkMessagesTest.PackToByteArray(intMessage); + TwoArgMethodMessage unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Assert.That(unpacked.someValue, Is.EqualTo(value)); } } diff --git a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs index b5b83b9e8..2cbbb0ae1 100644 --- a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs +++ b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs @@ -11,11 +11,9 @@ public class MyScriptableObject : ScriptableObject [TestFixture] public class ScriptableObjectWriterTest { - // ArraySegment is a special case, optimized for no copy and no allocation // other types are generated by the weaver - public struct ScriptableObjectMessage : NetworkMessage { public MyScriptableObject scriptableObject; @@ -24,20 +22,16 @@ public struct ScriptableObjectMessage : NetworkMessage [Test] public void TestWriteScriptableObject() { - ScriptableObjectMessage message = new ScriptableObjectMessage - { - scriptableObject = ScriptableObject.CreateInstance() - }; + ScriptableObjectMessage message = new ScriptableObjectMessage {scriptableObject = ScriptableObject.CreateInstance()}; message.scriptableObject.someData = 10; - byte[] data = MessagePackingTest.PackToByteArray(message); + byte[] data = NetworkMessagesTest.PackToByteArray(message); - ScriptableObjectMessage unpacked = MessagePackingTest.UnpackFromByteArray(data); + ScriptableObjectMessage unpacked = NetworkMessagesTest.UnpackFromByteArray(data); Assert.That(unpacked.scriptableObject, Is.Not.Null); Assert.That(unpacked.scriptableObject.someData, Is.EqualTo(10)); } - } }