public void TestComplexArraySerialization() { var serializer = new BinarySerializer(); var lookup = new NetworkPacketTypeRegistry(); lookup.Register <MyPlayerAdd>(MyPlayerAdd.OpCode); var packetSerializer = new NetworkPacketSerializer(null, lookup, serializer); var packet = new NetworkPacket(); packet.Id = MyPlayerAdd.OpCode; packet.Data = new MyPlayerAdd { Health = 10, Coins = 0, Experience = 0, Level = 1, Name = "Zerratar", PlayerId = 10, Position = new Shinobytes.Ravenfall.RavenNet.Models.Vector3(1.1255f, 7.5f, 6f), Professions = new Professions(), Appearance = GenerateRandomAppearance(), Attributes = new Attributes(), InventoryItemAmount = new long[] { 1, 1, 1 }, InventoryItemId = new int[] { 1, 2, 3 } }; var data = packetSerializer.Serialize(packet); var result = packetSerializer.Deserialize(data); if (!result.TryGetValue <MyPlayerAdd>(out var resultData)) { Assert.Fail("Resulting data was not of the expected type MyPlayerAdd"); return; } //Assert.AreEqual(appearance.Length, resultData.Appearance.Length); //Assert.AreEqual(id.Length, resultData.Id.Length); //Assert.AreEqual(combatLevel.Length, resultData.Level.Length); //Assert.AreEqual(name.Length, resultData.Name.Length); }
public void SerializeDeserializeFullPacket() { var serializer = new BinarySerializer(); var lookup = new NetworkPacketTypeRegistry(); lookup.Register <Test>(1); var packetSerializer = new NetworkPacketSerializer(null, lookup, serializer); var packet = new NetworkPacket(); packet.Id = 1; packet.Data = new Test(); var data = packetSerializer.Serialize(packet); var result = packetSerializer.Deserialize(data); Assert.AreEqual(typeof(Test).FullName, result.Data.GetType().FullName); Assert.AreEqual("Hello, world!", ((Test)result.Data).Value); }