mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
MessagePacker.Unpack<T> moved to MessagePackerTests because it's only used for tests
This commit is contained in:
parent
8d06b8737b
commit
f59af28ccb
@ -42,22 +42,6 @@ public static void Pack<T>(T message, NetworkWriter writer)
|
||||
writer.Write(message);
|
||||
}
|
||||
|
||||
// unpack a message we received
|
||||
public static T Unpack<T>(byte[] data)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
|
||||
{
|
||||
int msgType = GetId<T>();
|
||||
|
||||
int id = networkReader.ReadUInt16();
|
||||
if (id != msgType)
|
||||
throw new FormatException("Invalid message, could not unpack " + typeof(T).FullName);
|
||||
|
||||
return networkReader.Read<T>();
|
||||
}
|
||||
}
|
||||
|
||||
// unpack message after receiving
|
||||
// -> pass NetworkReader so it's less strange if we create it in here
|
||||
// and pass it upwards.
|
||||
|
@ -20,7 +20,7 @@ public void CommandMessage()
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
// deserialize the same data - do we get the same result?
|
||||
CommandMessage fresh = MessagePacker.Unpack<CommandMessage>(arr);
|
||||
CommandMessage fresh = MessagePackerTest.Unpack<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));
|
||||
@ -38,7 +38,7 @@ public void ConnectMessage()
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
MessagePacker.Unpack<ConnectMessage>(arr);
|
||||
MessagePackerTest.Unpack<ConnectMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public void DisconnectMessage()
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
MessagePacker.Unpack<DisconnectMessage>(arr);
|
||||
MessagePackerTest.Unpack<DisconnectMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public void ErrorMessage()
|
||||
// try setting value with constructor
|
||||
ErrorMessage message = new ErrorMessage(42);
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
ErrorMessage fresh = MessagePacker.Unpack<ErrorMessage>(arr);
|
||||
ErrorMessage fresh = MessagePackerTest.Unpack<ErrorMessage>(arr);
|
||||
Assert.That(fresh.value, Is.EqualTo(message.value));
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public void NetworkPingMessage()
|
||||
// try setting value with constructor
|
||||
NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate());
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
NetworkPingMessage fresh = MessagePacker.Unpack<NetworkPingMessage>(arr);
|
||||
NetworkPingMessage fresh = MessagePackerTest.Unpack<NetworkPingMessage>(arr);
|
||||
Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public void NetworkPongMessage()
|
||||
serverTime = DateTime.Now.ToOADate(),
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
NetworkPongMessage fresh = MessagePacker.Unpack<NetworkPongMessage>(arr);
|
||||
NetworkPongMessage fresh = MessagePackerTest.Unpack<NetworkPongMessage>(arr);
|
||||
Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
|
||||
Assert.That(fresh.serverTime, Is.EqualTo(message.serverTime));
|
||||
}
|
||||
@ -97,7 +97,7 @@ public void NotReadyMessage()
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
NotReadyMessage fresh = MessagePacker.Unpack<NotReadyMessage>(arr);
|
||||
NotReadyMessage fresh = MessagePackerTest.Unpack<NotReadyMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public void ObjectDestroyMessage()
|
||||
netId = 42,
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
ObjectDestroyMessage fresh = MessagePacker.Unpack<ObjectDestroyMessage>(arr);
|
||||
ObjectDestroyMessage fresh = MessagePackerTest.Unpack<ObjectDestroyMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public void ObjectHideMessage()
|
||||
netId = 42,
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
ObjectHideMessage fresh = MessagePacker.Unpack<ObjectHideMessage>(arr);
|
||||
ObjectHideMessage fresh = MessagePackerTest.Unpack<ObjectHideMessage>(arr);
|
||||
Assert.That(fresh.netId, Is.EqualTo(message.netId));
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public void ReadyMessage()
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
ReadyMessage fresh = MessagePacker.Unpack<ReadyMessage>(arr);
|
||||
ReadyMessage fresh = MessagePackerTest.Unpack<ReadyMessage>(arr);
|
||||
});
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ public void RpcMessage()
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
RpcMessage fresh = MessagePacker.Unpack<RpcMessage>(arr);
|
||||
RpcMessage fresh = MessagePackerTest.Unpack<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));
|
||||
@ -183,7 +183,7 @@ void DoTest(ulong testSceneId)
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
SpawnMessage fresh = MessagePacker.Unpack<SpawnMessage>(arr);
|
||||
SpawnMessage fresh = MessagePackerTest.Unpack<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));
|
||||
@ -210,7 +210,7 @@ public void UpdateVarsMessage()
|
||||
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
|
||||
};
|
||||
byte[] arr = MessagePackerTest.PackToByteArray(message);
|
||||
UpdateVarsMessage fresh = MessagePacker.Unpack<UpdateVarsMessage>(arr);
|
||||
UpdateVarsMessage fresh = MessagePackerTest.Unpack<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)
|
||||
|
@ -48,7 +48,7 @@ public void TestCustomRW()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
QuestMessage unpacked = MessagePacker.Unpack<QuestMessage>(data);
|
||||
QuestMessage unpacked = MessagePackerTest.Unpack<QuestMessage>(data);
|
||||
|
||||
Assert.That(unpacked.quest.Id, Is.EqualTo(100));
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -41,7 +41,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -61,7 +61,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
int[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -89,7 +89,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -105,7 +105,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -125,7 +125,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
string[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -153,7 +153,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -169,7 +169,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -189,7 +189,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
Vector3[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -217,7 +217,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -233,7 +233,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -253,7 +253,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
FloatStringStruct[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -281,7 +281,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -297,7 +297,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -317,7 +317,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ClassWithNoConstructor[] unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -345,7 +345,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -368,7 +368,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -395,7 +395,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -423,7 +423,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -446,7 +446,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -473,7 +473,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -501,7 +501,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -524,7 +524,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -551,7 +551,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -579,7 +579,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -602,7 +602,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -629,7 +629,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -657,7 +657,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
|
||||
@ -680,7 +680,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -707,7 +707,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
ArraySegment<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection.Array);
|
||||
@ -735,7 +735,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -751,7 +751,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -771,7 +771,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<int> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -799,7 +799,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -815,7 +815,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -835,7 +835,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<string> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -863,7 +863,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -879,7 +879,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -899,7 +899,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<Vector3> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -927,7 +927,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -943,7 +943,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -963,7 +963,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<FloatStringStruct> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -991,7 +991,7 @@ public void SendsNull()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.That(unpackedCollection, Is.Null.Or.Empty);
|
||||
@ -1007,7 +1007,7 @@ public void SendsEmpty()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
@ -1027,7 +1027,7 @@ public void SendsData()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
Message unpacked = MessagePacker.Unpack<Message>(data);
|
||||
Message unpacked = MessagePackerTest.Unpack<Message>(data);
|
||||
List<ClassWithNoConstructor> unpackedCollection = unpacked.collection;
|
||||
|
||||
Assert.IsNotNull(unpackedCollection);
|
||||
|
@ -23,6 +23,22 @@ public static byte[] PackToByteArray<T>(T message) where T : struct, NetworkMess
|
||||
}
|
||||
}
|
||||
|
||||
// this was previously in MessagePacker, but we only need it for tests
|
||||
public static T Unpack<T>(byte[] data)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
|
||||
int id = networkReader.ReadUInt16();
|
||||
if (id != msgType)
|
||||
throw new FormatException("Invalid message, could not unpack " + typeof(T).FullName);
|
||||
|
||||
return networkReader.Read<T>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPacking()
|
||||
{
|
||||
@ -34,7 +50,7 @@ public void TestPacking()
|
||||
|
||||
byte[] data = PackToByteArray(message);
|
||||
|
||||
TestMessage unpacked = MessagePacker.Unpack<TestMessage>(data);
|
||||
TestMessage unpacked = Unpack<TestMessage>(data);
|
||||
|
||||
Assert.That(unpacked.sceneName, Is.EqualTo("Hello world"));
|
||||
Assert.That(unpacked.sceneOperation, Is.EqualTo(SceneOperation.LoadAdditive));
|
||||
@ -49,7 +65,7 @@ public void UnpackWrongMessage()
|
||||
|
||||
Assert.Throws<FormatException>(() =>
|
||||
{
|
||||
DisconnectMessage unpacked = MessagePacker.Unpack<DisconnectMessage>(data);
|
||||
DisconnectMessage unpacked = Unpack<DisconnectMessage>(data);
|
||||
});
|
||||
}
|
||||
|
||||
@ -73,7 +89,7 @@ public void TestUnpackIdMismatch()
|
||||
|
||||
Assert.Throws<FormatException>(() =>
|
||||
{
|
||||
TestMessage unpacked = MessagePacker.Unpack<TestMessage>(data);
|
||||
TestMessage unpacked = Unpack<TestMessage>(data);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public void TestWriteScriptableObject()
|
||||
|
||||
byte[] data = MessagePackerTest.PackToByteArray(message);
|
||||
|
||||
ScriptableObjectMessage unpacked = MessagePacker.Unpack<ScriptableObjectMessage>(data);
|
||||
ScriptableObjectMessage unpacked = MessagePackerTest.Unpack<ScriptableObjectMessage>(data);
|
||||
|
||||
Assert.That(unpacked.scriptableObject, Is.Not.Null);
|
||||
Assert.That(unpacked.scriptableObject.someData, Is.EqualTo(10));
|
||||
|
@ -2,6 +2,17 @@
|
||||
"m_Name": "Settings",
|
||||
"m_Path": "ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json",
|
||||
"m_Dictionary": {
|
||||
"m_DictionaryValues": []
|
||||
"m_DictionaryValues": [
|
||||
{
|
||||
"type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "Path",
|
||||
"value": "{\"m_Value\":\"/Users/qwerty/x/dev/project_Mirror/Repository\"}"
|
||||
},
|
||||
{
|
||||
"type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "HistoryPath",
|
||||
"value": "{\"m_Value\":\"/Users/qwerty/x/dev/project_Mirror/Repository\"}"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user