public void Can_Serialize_DeserializedDTO_To_Same_Binary_Representation(PacketCaptureTestEntry entry)
        {
            //arrange
            Console.WriteLine($"Entry Size: {entry.BinaryData.Length} OpCode: {entry.OpCode}");
            SerializerService serializer = Serializer;
            GamePacketPayload payload    = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);

            //act
            byte[] serializedBytes = serializer.Serialize(payload);

            //assert
            try
            {
                Assert.AreEqual(entry.BinaryData.Length, serializedBytes.Length, $"Mismatched length on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
            catch (AssertionException e)
            {
                Assert.Fail($"Failed: {e.Message} {PrintFailureBytes(entry.BinaryData, serializedBytes)}");
            }


            for (int i = 0; i < entry.BinaryData.Length; i++)
            {
                Assert.AreEqual(entry.BinaryData[i], serializedBytes[i], $"Mismatched byte value at Index: {i} on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
        }
        public void Can_Deserialize_Captures_To_GamePacketPayloads(PacketCaptureTestEntry entry)
        {
            Console.WriteLine($"Entry Decompressed/Real Size: {entry.BinaryData.Length} OpCode: {entry.OpCode}");

            //arrange
            SerializerService serializer = Serializer;

            GamePacketPayload payload;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            //act
            try
            {
                payload = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);
            }
            catch (Exception e)
            {
                Assert.Fail($"Critical failure. Cannot deserialize File: {entry.FileName} FileSize: {entry.BinaryData.Length} \n\n Exception: {e.Message} Stack: {e.StackTrace}");
                return;
            }
            finally
            {
                stopwatch.Stop();
            }

            Console.WriteLine($"Serialization time in ms: {stopwatch.ElapsedMilliseconds}");

            //assert
            Assert.NotNull(payload, $"Resulting capture capture deserialization attempt null for File: {entry.FileName}");
            //We should have deserialized it. We want to make sure the opcode matches
            Assert.AreEqual(entry.OpCode, payload.GetOperationCode(), $"Mismatched {nameof(NetworkOperationCode)} on packet capture File: {entry.FileName}. Expected: {entry.OpCode} Was: {payload.GetOperationCode()}");
        }
示例#3
0
        private static PacketCaptureTestEntry RebuildEntryAsUncompressed(PacketCaptureTestEntry entry)
        {
            if (entry.OpCode == NetworkOperationCode.SMSG_COMPRESSED_UPDATE_OBJECT)
            {
                //Skip the opcode
                int    decompressedSize = entry.BinaryData.Reinterpret <int>(2);
                byte[] newBytes         = new byte[decompressedSize + 2];         // +2 for opcode

                ZlibCodec stream = new ZlibCodec(CompressionMode.Decompress)
                {
                    InputBuffer       = entry.BinaryData,
                    NextIn            = 2 + 4,          //opcode + size
                    AvailableBytesIn  = entry.BinaryData.Length,
                    OutputBuffer      = newBytes,
                    NextOut           = 2,
                    AvailableBytesOut = decompressedSize
                };

                stream.InitializeInflate(true);
                stream.Inflate(FlushType.None);
                stream.Inflate(FlushType.Finish);
                stream.EndInflate();

                ((short)(NetworkOperationCode.SMSG_UPDATE_OBJECT)).Reinterpret(newBytes, 0);

                entry = new PacketCaptureTestEntry(NetworkOperationCode.SMSG_UPDATE_OBJECT, newBytes, entry.FileName);
            }

            return(entry);
        }
示例#4
0
        public void Can_Serialize_DeserializedDTO_To_Same_Binary_Representation(PacketCaptureTestEntry entry)
        {
            //arrange
            Console.WriteLine($"Entry Size: {entry.BinaryData.Length} OpCode: {entry.OpCode}");
            SerializerService serializer = Serializer;
            GamePacketPayload payload    = serializer.Read <GamePacketPayload>(new Span <byte>(entry.BinaryData), 0);

            //act
            int         offset = 0;
            Span <byte> buffer = new Span <byte>(new byte[62000]);

            try
            {
                serializer.Write(payload, buffer, ref offset);
            }
            catch (KnownIncompleteSerializationException e)
            {
                Assert.Warn($"Incomplete serialization implementation for Type: {e.Message}. Message: {e}");
                return;
            }

            //assert
            try
            {
                Assert.AreEqual(entry.BinaryData.Length, offset, $"Mismatched length on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
            catch (AssertionException e)
            {
                Assert.Fail($"Failed: {e.Message} {PrintFailureBytes(entry.BinaryData, buffer.Slice(0, offset).ToArray())}");
            }


            for (int i = 0; i < entry.BinaryData.Length; i++)
            {
                Assert.AreEqual(entry.BinaryData[i], buffer[i], $"Mismatched byte value at Index: {i} on OpCode: {entry.OpCode} Type: {payload.GetType().Name}");
            }
        }
示例#5
0
        public static void Can_Serialize_DeserializedDTO_To_Same_Binary_Representation(PacketCaptureTestEntry entry)
        {
            //arrange
            NetworkOperationCode originalOpCode = entry.OpCode;

            //TODO: Test compression another time.
            entry = RebuildEntryAsUncompressed(entry);
            Console.WriteLine($"Entry Decompressed/Real Size: {entry.BinaryData.Length} OpCode: {originalOpCode}");
            SerializerService serializer = Serializer;
            GamePacketPayload payload    = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);

            //act
            byte[] serializedBytes = serializer.Serialize(payload);

            //assert
            Assert.AreEqual(entry.BinaryData.Length, serializedBytes.Length);

            for (int i = 0; i < entry.BinaryData.Length; i++)
            {
                Assert.AreEqual(entry.BinaryData[i], serializedBytes[i]);
            }
        }