mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
MessagePacker renamed to MessagePacking
This commit is contained in:
parent
f00aa2f8d8
commit
4bef7fc635
@ -14,7 +14,7 @@ namespace Mirror
|
||||
// using 2 bytes for shorts.
|
||||
// -> this reduces bandwidth by 10% if average message size is 20 bytes
|
||||
// (probably even shorter)
|
||||
public static class MessagePacker
|
||||
public static class MessagePacking
|
||||
{
|
||||
/// <summary>
|
||||
/// this is the minimum size of a message that mirror will accept
|
@ -324,12 +324,12 @@ internal static void RegisterSystemHandlers(bool hostMode)
|
||||
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacking.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.");
|
||||
}
|
||||
handlers[msgType] = MessagePacker.WrapHandler(handler, requireAuthentication);
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -355,8 +355,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
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
handlers[msgType] = MessagePacker.WrapHandler(handler, requireAuthentication);
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -380,7 +380,7 @@ public static bool UnregisterHandler<T>()
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
// use int to minimize collisions
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
return handlers.Remove(msgType);
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public void Send<T>(T msg, int channelId = Channels.DefaultReliable)
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
// pack message and send allocation free
|
||||
MessagePacker.Pack(msg, writer);
|
||||
MessagePacking.Pack(msg, writer);
|
||||
NetworkDiagnostics.OnSend(msg, channelId, writer.Position, 1);
|
||||
Send(writer.ToArraySegment(), channelId);
|
||||
}
|
||||
@ -187,7 +187,7 @@ internal void RemoveObservers()
|
||||
// helper function
|
||||
protected bool UnpackAndInvoke(NetworkReader reader, int channelId)
|
||||
{
|
||||
if (MessagePacker.Unpack(reader, out int msgType))
|
||||
if (MessagePacking.Unpack(reader, out int msgType))
|
||||
{
|
||||
// try to invoke the handler for that message
|
||||
if (messageHandlers.TryGetValue(msgType, out NetworkMessageDelegate msgDelegate))
|
||||
@ -216,7 +216,7 @@ protected bool UnpackAndInvoke(NetworkReader reader, int channelId)
|
||||
/// <param name="buffer">The data received.</param>
|
||||
internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
{
|
||||
if (buffer.Count < MessagePacker.HeaderSize)
|
||||
if (buffer.Count < MessagePacking.HeaderSize)
|
||||
{
|
||||
Debug.LogError($"ConnectionRecv {this} Message was too short (messages should start with message id)");
|
||||
Disconnect();
|
||||
|
@ -279,7 +279,7 @@ static void SendToObservers<T>(NetworkIdentity identity, T msg, int channelId =
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
// pack message into byte[] once
|
||||
MessagePacker.Pack(msg, writer);
|
||||
MessagePacking.Pack(msg, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
foreach (NetworkConnection conn in identity.observers.Values)
|
||||
@ -318,7 +318,7 @@ public static void SendToAll<T>(T msg, int channelId = Channels.DefaultReliable,
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
// pack message only once
|
||||
MessagePacker.Pack(msg, writer);
|
||||
MessagePacking.Pack(msg, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// filter and then send to all internet connections at once
|
||||
@ -383,7 +383,7 @@ public static void SendToReady<T>(NetworkIdentity identity, T msg, bool includeO
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
// pack message only once
|
||||
MessagePacker.Pack(msg, writer);
|
||||
MessagePacking.Pack(msg, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
int count = 0;
|
||||
@ -627,12 +627,12 @@ static void OnError(int connectionId, Exception exception)
|
||||
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacking.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] = MessagePacker.WrapHandler(handler, requireAuthentication);
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -658,8 +658,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
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
handlers[msgType] = MessagePacker.WrapHandler(handler, requireAuthentication);
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
handlers[msgType] = MessagePacking.WrapHandler(handler, requireAuthentication);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -682,7 +682,7 @@ public static void ReplaceHandler<T>(Action<T> handler, bool requireAuthenticati
|
||||
public static void UnregisterHandler<T>()
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
handlers.Remove(msgType);
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,10 @@ public void CommandMessage()
|
||||
functionHash = 0xABCDEF,
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
// deserialize the same data - do we get the same result?
|
||||
CommandMessage fresh = MessagePackerTest.UnpackFromByteArray<CommandMessage>(arr);
|
||||
CommandMessage fresh = MessagePackingTest.UnpackFromByteArray<CommandMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex));
|
||||
Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash));
|
||||
@ -35,8 +35,8 @@ public void NetworkPingMessage()
|
||||
{
|
||||
// try setting value with constructor
|
||||
NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate());
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
NetworkPingMessage fresh = MessagePackerTest.UnpackFromByteArray<NetworkPingMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
NetworkPingMessage fresh = MessagePackingTest.UnpackFromByteArray<NetworkPingMessage>(arr);
|
||||
Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ public void NetworkPongMessage()
|
||||
clientTime = DateTime.Now.ToOADate(),
|
||||
serverTime = DateTime.Now.ToOADate(),
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
NetworkPongMessage fresh = MessagePackerTest.UnpackFromByteArray<NetworkPongMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
NetworkPongMessage fresh = MessagePackingTest.UnpackFromByteArray<NetworkPongMessage>(arr);
|
||||
Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
|
||||
Assert.That(fresh.serverTime, Is.EqualTo(message.serverTime));
|
||||
}
|
||||
@ -60,10 +60,10 @@ public void NotReadyMessage()
|
||||
{
|
||||
// try setting value with constructor
|
||||
NotReadyMessage message = new NotReadyMessage();
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
NotReadyMessage fresh = MessagePackerTest.UnpackFromByteArray<NotReadyMessage>(arr);
|
||||
NotReadyMessage fresh = MessagePackingTest.UnpackFromByteArray<NotReadyMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -75,8 +75,8 @@ public void ObjectDestroyMessage()
|
||||
{
|
||||
netId = 42,
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
ObjectDestroyMessage fresh = MessagePackerTest.UnpackFromByteArray<ObjectDestroyMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
ObjectDestroyMessage fresh = MessagePackingTest.UnpackFromByteArray<ObjectDestroyMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
}
|
||||
|
||||
@ -88,8 +88,8 @@ public void ObjectHideMessage()
|
||||
{
|
||||
netId = 42,
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
ObjectHideMessage fresh = MessagePackerTest.UnpackFromByteArray<ObjectHideMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
ObjectHideMessage fresh = MessagePackingTest.UnpackFromByteArray<ObjectHideMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
}
|
||||
|
||||
@ -98,10 +98,10 @@ public void ObjectSpawnFinishedMessage()
|
||||
{
|
||||
// try setting value with constructor
|
||||
ObjectSpawnFinishedMessage message = new ObjectSpawnFinishedMessage();
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
ObjectSpawnFinishedMessage fresh = MessagePackerTest.UnpackFromByteArray<ObjectSpawnFinishedMessage>(arr);
|
||||
ObjectSpawnFinishedMessage fresh = MessagePackingTest.UnpackFromByteArray<ObjectSpawnFinishedMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -110,10 +110,10 @@ public void ObjectSpawnStartedMessage()
|
||||
{
|
||||
// try setting value with constructor
|
||||
ObjectSpawnStartedMessage message = new ObjectSpawnStartedMessage();
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
ObjectSpawnStartedMessage fresh = MessagePackerTest.UnpackFromByteArray<ObjectSpawnStartedMessage>(arr);
|
||||
ObjectSpawnStartedMessage fresh = MessagePackingTest.UnpackFromByteArray<ObjectSpawnStartedMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -122,10 +122,10 @@ public void ReadyMessage()
|
||||
{
|
||||
// try setting value with constructor
|
||||
ReadyMessage message = new ReadyMessage();
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
ReadyMessage fresh = MessagePackerTest.UnpackFromByteArray<ReadyMessage>(arr);
|
||||
ReadyMessage fresh = MessagePackingTest.UnpackFromByteArray<ReadyMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -140,8 +140,8 @@ public void RpcMessage()
|
||||
functionHash = 0xABCDEF,
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
RpcMessage fresh = MessagePackerTest.UnpackFromByteArray<RpcMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
RpcMessage fresh = MessagePackingTest.UnpackFromByteArray<RpcMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex));
|
||||
Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash));
|
||||
@ -172,8 +172,8 @@ void DoTest(ulong testSceneId)
|
||||
scale = UnityEngine.Vector3.one,
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
SpawnMessage fresh = MessagePackerTest.UnpackFromByteArray<SpawnMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
SpawnMessage fresh = MessagePackingTest.UnpackFromByteArray<SpawnMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
Assert.That(fresh.isLocalPlayer, Is.EqualTo(message.isLocalPlayer));
|
||||
Assert.That(fresh.isOwner, Is.EqualTo(message.isOwner));
|
||||
@ -199,8 +199,8 @@ public void UpdateVarsMessage()
|
||||
netId = 42,
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
UpdateVarsMessage fresh = MessagePackerTest.UnpackFromByteArray<UpdateVarsMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(message);
|
||||
UpdateVarsMessage fresh = MessagePackingTest.UnpackFromByteArray<UpdateVarsMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
|
||||
for (int i = 0; i < fresh.payload.Count; ++i)
|
||||
|
@ -46,9 +46,9 @@ public void TestCustomRW()
|
||||
quest = new MockQuest(100)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
QuestMessage unpacked = MessagePackerTest.UnpackFromByteArray<QuestMessage>(data);
|
||||
QuestMessage unpacked = MessagePackingTest.UnpackFromByteArray<QuestMessage>(data);
|
||||
|
||||
Assert.That(unpacked.quest.Id, Is.EqualTo(100));
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -39,9 +39,9 @@ public void SendsEmpty()
|
||||
collection = new int[] {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -59,9 +59,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -87,9 +87,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -103,9 +103,9 @@ public void SendsEmpty()
|
||||
collection = new string[] {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -123,9 +123,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -151,9 +151,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -167,9 +167,9 @@ public void SendsEmpty()
|
||||
collection = new Vector3[] {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -187,9 +187,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -215,9 +215,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -231,9 +231,9 @@ public void SendsEmpty()
|
||||
collection = new FloatStringStruct[] {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -251,9 +251,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -279,9 +279,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -295,9 +295,9 @@ public void SendsEmpty()
|
||||
collection = new ClassWithNoConstructor[] {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -315,9 +315,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -343,9 +343,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -366,9 +366,9 @@ public void SendsEmpty()
|
||||
collection = new ArraySegment<int>(array, 0, 0)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -393,9 +393,9 @@ public void SendsData()
|
||||
collection = new ArraySegment<int>(array, 1, 3)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -421,9 +421,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -444,9 +444,9 @@ public void SendsEmpty()
|
||||
collection = new ArraySegment<string>(array, 0, 0)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -471,9 +471,9 @@ public void SendsData()
|
||||
collection = new ArraySegment<string>(array, 1, 3)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -499,9 +499,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -522,9 +522,9 @@ public void SendsEmpty()
|
||||
collection = new ArraySegment<Vector3>(array, 0, 0)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -549,9 +549,9 @@ public void SendsData()
|
||||
collection = new ArraySegment<Vector3>(array, 1, 3)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -577,9 +577,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -600,9 +600,9 @@ public void SendsEmpty()
|
||||
collection = new ArraySegment<FloatStringStruct>(array, 0, 0)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -627,9 +627,9 @@ public void SendsData()
|
||||
collection = new ArraySegment<FloatStringStruct>(array, 1, 3)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -655,9 +655,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -678,9 +678,9 @@ public void SendsEmpty()
|
||||
collection = new ArraySegment<ClassWithNoConstructor>(array, 0, 0)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -705,9 +705,9 @@ public void SendsData()
|
||||
collection = new ArraySegment<ClassWithNoConstructor>(array, 1, 3)
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -733,9 +733,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -749,9 +749,9 @@ public void SendsEmpty()
|
||||
collection = new List<int> {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -769,9 +769,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -797,9 +797,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -813,9 +813,9 @@ public void SendsEmpty()
|
||||
collection = new List<string> {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -833,9 +833,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -861,9 +861,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -877,9 +877,9 @@ public void SendsEmpty()
|
||||
collection = new List<Vector3> {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -897,9 +897,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -925,9 +925,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -941,9 +941,9 @@ public void SendsEmpty()
|
||||
collection = new List<FloatStringStruct> {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -961,9 +961,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -989,9 +989,9 @@ public void SendsNull()
|
||||
collection = default
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -1005,9 +1005,9 @@ public void SendsEmpty()
|
||||
collection = new List<ClassWithNoConstructor> {}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -1025,9 +1025,9 @@ public void SendsData()
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePackerTest.UnpackFromByteArray<Message>(data);
|
||||
Message unpacked = MessagePackingTest.UnpackFromByteArray<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
|
@ -43,8 +43,8 @@ public class MessageBaseTests
|
||||
[Test]
|
||||
public void StructWithMethods()
|
||||
{
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(new TestMessage(1, "2", 3.3));
|
||||
TestMessage t = MessagePackerTest.UnpackFromByteArray<TestMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(new TestMessage(1, "2", 3.3));
|
||||
TestMessage t = MessagePackingTest.UnpackFromByteArray<TestMessage>(arr);
|
||||
|
||||
Assert.AreEqual(1, t.IntValue);
|
||||
}
|
||||
@ -52,8 +52,8 @@ public void StructWithMethods()
|
||||
[Test]
|
||||
public void StructWithEmptyMethods()
|
||||
{
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 });
|
||||
StructWithEmptyMethodMessage t = MessagePackerTest.UnpackFromByteArray<StructWithEmptyMethodMessage>(arr);
|
||||
byte[] arr = MessagePackingTest.PackToByteArray(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 });
|
||||
StructWithEmptyMethodMessage t = MessagePackingTest.UnpackFromByteArray<StructWithEmptyMethodMessage>(arr);
|
||||
|
||||
Assert.AreEqual(1, t.IntValue);
|
||||
Assert.AreEqual("2", t.StringValue);
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Mirror.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MessagePackerTest
|
||||
public class MessagePackingTest
|
||||
{
|
||||
public struct EmptyMessage : NetworkMessage {}
|
||||
|
||||
@ -13,7 +13,7 @@ public static byte[] PackToByteArray<T>(T message)
|
||||
{
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
MessagePacker.Pack(message, writer);
|
||||
MessagePacking.Pack(message, writer);
|
||||
return writer.ToArray();
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ public static T UnpackFromByteArray<T>(byte[] data)
|
||||
{
|
||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacking.GetId<T>();
|
||||
|
||||
int id = networkReader.ReadUInt16();
|
||||
if (id != msgType)
|
||||
@ -101,7 +101,7 @@ public void TestUnpackMessageNonGeneric()
|
||||
byte[] data = PackToByteArray(message);
|
||||
NetworkReader reader = new NetworkReader(data);
|
||||
|
||||
bool result = MessagePacker.Unpack(reader, out int msgType);
|
||||
bool result = MessagePacking.Unpack(reader, out int msgType);
|
||||
Assert.That(result, Is.EqualTo(true));
|
||||
Assert.That(msgType, Is.EqualTo(BitConverter.ToUInt16(data, 0)));
|
||||
}
|
||||
@ -111,7 +111,7 @@ public void UnpackInvalidMessage()
|
||||
{
|
||||
// try an invalid message
|
||||
NetworkReader reader2 = new NetworkReader(new byte[0]);
|
||||
bool result2 = MessagePacker.Unpack(reader2, out int msgType2);
|
||||
bool result2 = MessagePacking.Unpack(reader2, out int msgType2);
|
||||
Assert.That(result2, Is.EqualTo(false));
|
||||
Assert.That(msgType2, Is.EqualTo(0));
|
||||
}
|
||||
@ -120,11 +120,11 @@ public void UnpackInvalidMessage()
|
||||
public void MessageIdIsCorrectLength()
|
||||
{
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(new EmptyMessage(), writer);
|
||||
MessagePacking.Pack(new EmptyMessage(), writer);
|
||||
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
Assert.That(segment.Count, Is.EqualTo(MessagePacker.HeaderSize), "Empty message should have same size as HeaderSize");
|
||||
Assert.That(segment.Count, Is.EqualTo(MessagePacking.HeaderSize), "Empty message should have same size as HeaderSize");
|
||||
}
|
||||
}
|
||||
}
|
@ -608,7 +608,7 @@ public void AssignAndRemoveClientAuthority()
|
||||
owner.connectionToServer = new ULocalConnectionToServer();
|
||||
int spawnCalled = 0;
|
||||
owner.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>{
|
||||
{ MessagePacker.GetId<SpawnMessage>(), ((conn, reader, channelId) => ++spawnCalled) }
|
||||
{ MessagePacking.GetId<SpawnMessage>(), ((conn, reader, channelId) => ++spawnCalled) }
|
||||
});
|
||||
|
||||
// assigning authority should only work on server.
|
||||
@ -1267,7 +1267,7 @@ public void ServerUpdate()
|
||||
int ownerCalled = 0;
|
||||
owner.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>
|
||||
{
|
||||
{ MessagePacker.GetId<UpdateVarsMessage>(), ((conn, reader, channelId) => ++ownerCalled) }
|
||||
{ MessagePacking.GetId<UpdateVarsMessage>(), ((conn, reader, channelId) => ++ownerCalled) }
|
||||
});
|
||||
identity.connectionToClient = owner;
|
||||
|
||||
@ -1280,7 +1280,7 @@ public void ServerUpdate()
|
||||
int observerCalled = 0;
|
||||
observer.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>
|
||||
{
|
||||
{ MessagePacker.GetId<UpdateVarsMessage>(), ((conn, reader, channelId) => ++observerCalled) }
|
||||
{ MessagePacking.GetId<UpdateVarsMessage>(), ((conn, reader, channelId) => ++observerCalled) }
|
||||
});
|
||||
identity.observers[observer.connectionId] = observer;
|
||||
|
||||
|
@ -419,7 +419,7 @@ public void OnDataReceivedTest()
|
||||
// serialize a test message into an arraysegment
|
||||
TestMessage1 testMessage = new TestMessage1 { IntValue = 13, DoubleValue = 14, StringValue = "15" };
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(testMessage, writer);
|
||||
MessagePacking.Pack(testMessage, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// call transport.OnDataReceived
|
||||
@ -456,7 +456,7 @@ public void OnDataReceivedInvalidConnectionIdTest()
|
||||
// serialize a test message into an arraysegment
|
||||
TestMessage1 testMessage = new TestMessage1 { IntValue = 13, DoubleValue = 14, StringValue = "15" };
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(testMessage, writer);
|
||||
MessagePacking.Pack(testMessage, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// call transport.OnDataReceived with an invalid connectionId
|
||||
@ -523,7 +523,7 @@ public void ReadyMessageSetsClientReadyTest()
|
||||
// serialize a ready message into an arraysegment
|
||||
ReadyMessage message = new ReadyMessage();
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(message, writer);
|
||||
MessagePacking.Pack(message, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// call transport.OnDataReceived with the message
|
||||
@ -584,7 +584,7 @@ public void CommandMessageCallsCommandTest()
|
||||
payload = new ArraySegment<byte>(new byte[0])
|
||||
};
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(message, writer);
|
||||
MessagePacking.Pack(message, writer);
|
||||
ArraySegment<byte> segment = writer.ToArraySegment();
|
||||
|
||||
// call transport.OnDataReceived with the message
|
||||
@ -600,7 +600,7 @@ public void CommandMessageCallsCommandTest()
|
||||
comp0.called = 0;
|
||||
message.componentIndex = 1;
|
||||
writer = new NetworkWriter();
|
||||
MessagePacker.Pack(message, writer);
|
||||
MessagePacking.Pack(message, writer);
|
||||
segment = writer.ToArraySegment();
|
||||
Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0);
|
||||
|
||||
@ -625,7 +625,7 @@ public void CommandMessageCallsCommandTest()
|
||||
message.netId += 1;
|
||||
writer = new NetworkWriter();
|
||||
// need to serialize the message again with wrong netid
|
||||
MessagePacker.Pack(message, writer);
|
||||
MessagePacking.Pack(message, writer);
|
||||
ArraySegment<byte> segmentWrongNetId = writer.ToArraySegment();
|
||||
comp0.called = 0;
|
||||
comp1.called = 0;
|
||||
@ -689,7 +689,7 @@ public void SendToAllTest()
|
||||
int called = 0;
|
||||
connection.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>()
|
||||
{
|
||||
{ MessagePacker.GetId<TestMessage1>(), ((conn, reader, channelId) => ++called) }
|
||||
{ MessagePacking.GetId<TestMessage1>(), ((conn, reader, channelId) => ++called) }
|
||||
});
|
||||
NetworkServer.AddConnection(connection);
|
||||
|
||||
@ -728,20 +728,20 @@ public void RegisterUnregisterClearHandlerTest()
|
||||
|
||||
// serialize first message, send it to server, check if it was handled
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
MessagePacker.Pack(new TestMessage1(), writer);
|
||||
MessagePacking.Pack(new TestMessage1(), writer);
|
||||
Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0);
|
||||
Assert.That(variant1Called, Is.EqualTo(1));
|
||||
|
||||
// serialize second message, send it to server, check if it was handled
|
||||
writer = new NetworkWriter();
|
||||
MessagePacker.Pack(new TestMessage2(), writer);
|
||||
MessagePacking.Pack(new TestMessage2(), writer);
|
||||
Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0);
|
||||
Assert.That(variant2Called, Is.EqualTo(1));
|
||||
|
||||
// unregister first handler, send, should fail
|
||||
NetworkServer.UnregisterHandler<TestMessage1>();
|
||||
writer = new NetworkWriter();
|
||||
MessagePacker.Pack(new TestMessage1(), writer);
|
||||
MessagePacking.Pack(new TestMessage1(), writer);
|
||||
// log error messages are expected
|
||||
LogAssert.ignoreFailingMessages = true;
|
||||
Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0);
|
||||
@ -753,7 +753,7 @@ public void RegisterUnregisterClearHandlerTest()
|
||||
NetworkServer.ClearHandlers();
|
||||
// (only add this one to avoid disconnect error)
|
||||
writer = new NetworkWriter();
|
||||
MessagePacker.Pack(new TestMessage1(), writer);
|
||||
MessagePacking.Pack(new TestMessage1(), writer);
|
||||
// log error messages are expected
|
||||
LogAssert.ignoreFailingMessages = true;
|
||||
Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0);
|
||||
@ -777,7 +777,7 @@ public void SendToClientOfPlayer()
|
||||
int called = 0;
|
||||
connection.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>()
|
||||
{
|
||||
{ MessagePacker.GetId<TestMessage1>(), ((conn, reader, channelId) => ++called) }
|
||||
{ MessagePacking.GetId<TestMessage1>(), ((conn, reader, channelId) => ++called) }
|
||||
});
|
||||
NetworkServer.AddConnection(connection);
|
||||
|
||||
@ -853,7 +853,7 @@ public void ShowForConnection()
|
||||
int called = 0;
|
||||
connection.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>()
|
||||
{
|
||||
{ MessagePacker.GetId<SpawnMessage>(), ((conn, reader, channelId) => ++called) }
|
||||
{ MessagePacking.GetId<SpawnMessage>(), ((conn, reader, channelId) => ++called) }
|
||||
});
|
||||
NetworkServer.AddConnection(connection);
|
||||
|
||||
@ -900,7 +900,7 @@ public void HideForConnection()
|
||||
int called = 0;
|
||||
connection.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>()
|
||||
{
|
||||
{ MessagePacker.GetId<ObjectHideMessage>(), ((conn, reader, channelId) => ++called) }
|
||||
{ MessagePacking.GetId<ObjectHideMessage>(), ((conn, reader, channelId) => ++called) }
|
||||
});
|
||||
NetworkServer.AddConnection(connection);
|
||||
|
||||
|
@ -31,9 +31,9 @@ public void MethodsWithNoArgs()
|
||||
someValue = value
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(intMessage);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(intMessage);
|
||||
|
||||
NoArgMethodMessage unpacked = MessagePackerTest.UnpackFromByteArray<NoArgMethodMessage>(data);
|
||||
NoArgMethodMessage unpacked = MessagePackingTest.UnpackFromByteArray<NoArgMethodMessage>(data);
|
||||
|
||||
Assert.That(unpacked.someValue, Is.EqualTo(value));
|
||||
}
|
||||
@ -47,9 +47,9 @@ public void MethodsWithTwoArgs()
|
||||
someValue = value
|
||||
};
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(intMessage);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(intMessage);
|
||||
|
||||
TwoArgMethodMessage unpacked = MessagePackerTest.UnpackFromByteArray<TwoArgMethodMessage>(data);
|
||||
TwoArgMethodMessage unpacked = MessagePackingTest.UnpackFromByteArray<TwoArgMethodMessage>(data);
|
||||
|
||||
Assert.That(unpacked.someValue, Is.EqualTo(value));
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ public void TestWriteScriptableObject()
|
||||
|
||||
message.scriptableObject.someData = 10;
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
byte[] data = MessagePackingTest.PackToByteArray(message);
|
||||
|
||||
ScriptableObjectMessage unpacked = MessagePackerTest.UnpackFromByteArray<ScriptableObjectMessage>(data);
|
||||
ScriptableObjectMessage unpacked = MessagePackingTest.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