mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
MessagePacking renamed to NetworkMessages (it contains more network message code than just packing)
This commit is contained in:
parent
8249508fa7
commit
cf0b884c1f
@ -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<byte> 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>(T message, int channelId = Channels.Reliable)
|
||||
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
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<NetworkConnection, T>) HandlerWrapped, requireAuthentication);
|
||||
handlers[msgType] = NetworkMessages.WrapHandler((Action<NetworkConnection, T>)HandlerWrapped, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>Replace a handler for a particular message type. Should require authentication by default.</summary>
|
||||
@ -480,8 +481,8 @@ public static void RegisterHandler<T>(Action<T> handler, bool requireAuthenticat
|
||||
public static void ReplaceHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>Replace a handler for a particular message type. Should require authentication by default.</summary>
|
||||
@ -498,7 +499,7 @@ public static bool UnregisterHandler<T>()
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
// use int to minimize collisions
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
return handlers.Remove(msgType);
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ public void Send<T>(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);
|
||||
}
|
||||
|
@ -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<T>() where T : struct, NetworkMessage => NetworkMessages.GetId<T>();
|
||||
public static void Pack<T>(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<T, C>(Action<C, T, int> handler, bool requireAuthentication)
|
||||
where T : struct, NetworkMessage
|
||||
where C : NetworkConnection
|
||||
=> (conn, reader, channelId) => NetworkMessages.WrapHandler(handler, requireAuthentication);
|
||||
internal static NetworkMessageDelegate WrapHandler<T, C>(Action<C, T> 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;
|
@ -295,7 +295,7 @@ public static void SendToAll<T>(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<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// filter and then send to all internet connections at once
|
||||
@ -341,7 +341,7 @@ static void SendToObservers<T>(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<byte> segment = writer.ToArraySegment();
|
||||
|
||||
foreach (NetworkConnectionToClient conn in identity.observers.Values)
|
||||
@ -365,7 +365,7 @@ public static void SendToReadyObservers<T>(NetworkIdentity identity, T message,
|
||||
using (NetworkWriterPooled writer = NetworkWriterPool.Get())
|
||||
{
|
||||
// pack message only once
|
||||
MessagePacking.Pack(message, writer);
|
||||
NetworkMessages.Pack(message, writer);
|
||||
ArraySegment<byte> 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<byte> 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<T>(Action<NetworkConnectionToClient, T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>Register a handler for message type T. Most should require authentication.</summary>
|
||||
@ -621,20 +621,20 @@ public static void RegisterHandler<T>(Action<NetworkConnectionToClient, T> handl
|
||||
public static void RegisterHandler<T>(Action<NetworkConnectionToClient, T, int> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>Replace a handler for message type T. Most should require authentication.</summary>
|
||||
public static void ReplaceHandler<T>(Action<NetworkConnectionToClient, T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
handlers[msgType] = NetworkMessages.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>Replace a handler for message type T. Most should require authentication.</summary>
|
||||
@ -648,7 +648,7 @@ public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthenticati
|
||||
public static void UnregisterHandler<T>()
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
ushort msgType = MessagePacking.GetId<T>();
|
||||
ushort msgType = NetworkMessages.GetId<T>();
|
||||
handlers.Remove(msgType);
|
||||
}
|
||||
|
||||
|
@ -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<QuestMessage>(data);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
QuestMessage unpacked = NetworkMessagesTest.UnpackFromByteArray<QuestMessage>(data);
|
||||
Assert.That(unpacked.quest.Id, Is.EqualTo(100));
|
||||
}
|
||||
}
|
||||
|
@ -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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> 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<int>(array, 0, 0)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<int>(array, 0, 0)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> 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<int>(array, 1, 3)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<int>(array, 1, 3)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> 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<string>(array, 0, 0)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<string>(array, 0, 0)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> 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<string>(array, 1, 3)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<string>(array, 1, 3)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> 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<Vector3>(array, 0, 0)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<Vector3>(array, 0, 0)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> 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<Vector3>(array, 1, 3)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<Vector3>(array, 1, 3)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> 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<FloatStringStruct>(array, 0, 0)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<FloatStringStruct>(array, 0, 0)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> 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<FloatStringStruct>(array, 1, 3)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<FloatStringStruct>(array, 1, 3)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> 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<ClassWithNoConstructor>(array, 0, 0)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<ClassWithNoConstructor>(array, 0, 0)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> 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<ClassWithNoConstructor>(array, 1, 3)
|
||||
};
|
||||
Message message = new Message {collection = new ArraySegment<ClassWithNoConstructor>(array, 1, 3)};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> 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<int> {}
|
||||
};
|
||||
Message message = new Message {collection = new List<int> {}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -770,17 +599,11 @@ public void SendsEmpty()
|
||||
[Test]
|
||||
public void SendsData()
|
||||
{
|
||||
Message message = new Message
|
||||
{
|
||||
collection = new List<int>
|
||||
{
|
||||
3, 4, 5
|
||||
}
|
||||
};
|
||||
Message message = new Message {collection = new List<int> {3, 4, 5}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> 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<string> {}
|
||||
};
|
||||
Message message = new Message {collection = new List<string> {}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -834,17 +651,11 @@ public void SendsEmpty()
|
||||
[Test]
|
||||
public void SendsData()
|
||||
{
|
||||
Message message = new Message
|
||||
{
|
||||
collection = new List<string>
|
||||
{
|
||||
"Some", "String", "Value"
|
||||
}
|
||||
};
|
||||
Message message = new Message {collection = new List<string> {"Some", "String", "Value"}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> 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<Vector3> {}
|
||||
};
|
||||
Message message = new Message {collection = new List<Vector3> {}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -898,17 +703,11 @@ public void SendsEmpty()
|
||||
[Test]
|
||||
public void SendsData()
|
||||
{
|
||||
Message message = new Message
|
||||
{
|
||||
collection = new List<Vector3>
|
||||
{
|
||||
new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)
|
||||
}
|
||||
};
|
||||
Message message = new Message {collection = new List<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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> 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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<FloatStringStruct> 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<FloatStringStruct> {}
|
||||
};
|
||||
Message message = new Message {collection = new List<FloatStringStruct> {}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -962,24 +755,18 @@ public void SendsEmpty()
|
||||
[Test]
|
||||
public void SendsData()
|
||||
{
|
||||
Message message = new Message
|
||||
{
|
||||
collection = new List<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 List<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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<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"}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<ClassWithNoConstructor> 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<ClassWithNoConstructor> {}
|
||||
};
|
||||
Message message = new Message {collection = new List<ClassWithNoConstructor> {}};
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -1026,24 +807,18 @@ public void SendsEmpty()
|
||||
[Test]
|
||||
public void SendsData()
|
||||
{
|
||||
Message message = new Message
|
||||
{
|
||||
collection = new List<ClassWithNoConstructor>
|
||||
{
|
||||
new ClassWithNoConstructor { a = 3 }, new ClassWithNoConstructor { a = 4 }, new ClassWithNoConstructor { a = 5 }
|
||||
}
|
||||
};
|
||||
Message message = new Message {collection = new List<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<Message>(data);
|
||||
Message unpacked = NetworkMessagesTest.UnpackFromByteArray<Message>(data);
|
||||
List<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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<TestMessage>(bytes);
|
||||
byte[] bytes = NetworkMessagesTest.PackToByteArray(new TestMessage(1, "2", 3.3));
|
||||
TestMessage message = NetworkMessagesTest.UnpackFromByteArray<TestMessage>(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<StructWithEmptyMethodMessage>(bytes);
|
||||
byte[] bytes = NetworkMessagesTest.PackToByteArray(new StructWithEmptyMethodMessage {IntValue = 1, StringValue = "2", DoubleValue = 3.3});
|
||||
StructWithEmptyMethodMessage message = NetworkMessagesTest.UnpackFromByteArray<StructWithEmptyMethodMessage>(bytes);
|
||||
|
||||
Assert.AreEqual(1, message.IntValue);
|
||||
Assert.AreEqual("2", message.StringValue);
|
||||
|
@ -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>(T message)
|
||||
@ -16,7 +18,7 @@ public static byte[] PackToByteArray<T>(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<T>(byte[] data)
|
||||
{
|
||||
using (NetworkReaderPooled networkReader = NetworkReaderPool.Get(data))
|
||||
{
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
int msgType = NetworkMessages.GetId<T>();
|
||||
|
||||
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<TestMessage>(), Is.EqualTo(0x8706));
|
||||
Assert.That(NetworkMessages.GetId<TestMessage>(), 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<T> 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<byte> 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -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<NoArgMethodMessage>(data);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(intMessage);
|
||||
NoArgMethodMessage unpacked = NetworkMessagesTest.UnpackFromByteArray<NoArgMethodMessage>(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<TwoArgMethodMessage>(data);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(intMessage);
|
||||
TwoArgMethodMessage unpacked = NetworkMessagesTest.UnpackFromByteArray<TwoArgMethodMessage>(data);
|
||||
Assert.That(unpacked.someValue, Is.EqualTo(value));
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,9 @@ public class MyScriptableObject : ScriptableObject
|
||||
[TestFixture]
|
||||
public class ScriptableObjectWriterTest
|
||||
{
|
||||
|
||||
// ArraySegment<byte> 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<MyScriptableObject>()
|
||||
};
|
||||
ScriptableObjectMessage message = new ScriptableObjectMessage {scriptableObject = ScriptableObject.CreateInstance<MyScriptableObject>()};
|
||||
|
||||
message.scriptableObject.someData = 10;
|
||||
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
byte[] data = NetworkMessagesTest.PackToByteArray(message);
|
||||
|
||||
ScriptableObjectMessage unpacked = MessagePackingTest.UnpackFromByteArray<ScriptableObjectMessage>(data);
|
||||
ScriptableObjectMessage unpacked = NetworkMessagesTest.UnpackFromByteArray<ScriptableObjectMessage>(data);
|
||||
|
||||
Assert.That(unpacked.scriptableObject, Is.Not.Null);
|
||||
Assert.That(unpacked.scriptableObject.someData, Is.EqualTo(10));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user