Beispiel #1
0
        public void TestMethod_PKTArrayTest2EnDecode()
        {
            var reqPacket = new PKTArrayTest2();

            reqPacket.Count = 2;
            reqPacket.ItemList.Add(new CharItem {
                ItemCode = 4, Level = 17, Exp = 201.23f
            });
            reqPacket.ItemList.Add(new CharItem {
                ItemCode = 15, Level = 11, Exp = 141.53f
            });

            var packetData = new List <byte>();

            PKTArrayTest2EnDecode.Encode(packetData, reqPacket);

            var reqPacket2 = new PKTArrayTest2();

            PKTArrayTest2EnDecode.Decode(packetData.ToArray(), ref reqPacket2);

            Assert.AreEqual(reqPacket.Count, reqPacket2.Count);
            Assert.AreEqual(reqPacket.ItemList[0].ItemCode, reqPacket2.ItemList[0].ItemCode);
            Assert.AreEqual(reqPacket.ItemList[0].Level, reqPacket2.ItemList[0].Level);
            Assert.AreEqual(reqPacket.ItemList[0].Exp, reqPacket2.ItemList[0].Exp);
            Assert.AreEqual(reqPacket.ItemList[1].ItemCode, reqPacket2.ItemList[1].ItemCode);
            Assert.AreEqual(reqPacket.ItemList[1].Level, reqPacket2.ItemList[1].Level);
            Assert.AreEqual(reqPacket.ItemList[1].Exp, reqPacket2.ItemList[1].Exp);
        }
        public static void Encode(List <byte> packetData, PKTArrayTest2 packet)
        {
            packetData.AddRange(BitConverter.GetBytes(packet.Count));

            for (int i = 0; i < packet.Count; ++i)
            {
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].ItemCode));
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].Level));
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].Exp));
            }
        }
        public static bool Decode(byte[] packetData, ref PKTArrayTest2 packet)
        {
            int readPos = 0;

            packet.Count = BitConverter.ToInt16(packetData, readPos);
            readPos     += 2;

            for (short i = 0; i < packet.Count; ++i)
            {
                var charItem = new CharItem();
                charItem.ItemCode = BitConverter.ToInt32(packetData, readPos);
                readPos          += 4;
                charItem.Level    = BitConverter.ToInt32(packetData, readPos);
                readPos          += 4;
                charItem.Exp      = BitConverter.ToSingle(packetData, readPos);
                readPos          += 4;

                packet.ItemList.Add(charItem);
            }

            return(true);
        }
Beispiel #4
0
        public void TestMethod_PKTArrayTest2EnDecode()
        {
            var reqPacket = new PKTArrayTest2();
            reqPacket.Count = 2;
            reqPacket.ItemList.Add(new CharItem { ItemCode = 4, Level = 17, Exp = 201.23f });
            reqPacket.ItemList.Add(new CharItem { ItemCode = 15, Level = 11, Exp = 141.53f });

            var packetData = new List<byte>();

            PKTArrayTest2EnDecode.Encode(packetData, reqPacket);

            var reqPacket2 = new PKTArrayTest2();
            PKTArrayTest2EnDecode.Decode(packetData.ToArray(), ref reqPacket2);

            Assert.AreEqual(reqPacket.Count, reqPacket2.Count);
            Assert.AreEqual(reqPacket.ItemList[0].ItemCode, reqPacket2.ItemList[0].ItemCode);
            Assert.AreEqual(reqPacket.ItemList[0].Level, reqPacket2.ItemList[0].Level);
            Assert.AreEqual(reqPacket.ItemList[0].Exp, reqPacket2.ItemList[0].Exp);
            Assert.AreEqual(reqPacket.ItemList[1].ItemCode, reqPacket2.ItemList[1].ItemCode);
            Assert.AreEqual(reqPacket.ItemList[1].Level, reqPacket2.ItemList[1].Level);
            Assert.AreEqual(reqPacket.ItemList[1].Exp, reqPacket2.ItemList[1].Exp);
        }
Beispiel #5
0
        public static void Encode(List<byte> packetData, PKTArrayTest2 packet)
        {
            packetData.AddRange(BitConverter.GetBytes(packet.Count));

            for (int i = 0; i < packet.Count; ++i)
            {
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].ItemCode));
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].Level));
                packetData.AddRange(BitConverter.GetBytes(packet.ItemList[i].Exp));
            }
        }
Beispiel #6
0
        public static bool Decode(byte[] packetData, ref PKTArrayTest2 packet)
        {
            int readPos = 0;

            packet.Count = BitConverter.ToInt16(packetData, readPos);
            readPos += 2;

            for (short i = 0; i < packet.Count; ++i)
            {
                var charItem = new CharItem();
                charItem.ItemCode = BitConverter.ToInt32(packetData, readPos);
                readPos += 4;
                charItem.Level = BitConverter.ToInt32(packetData, readPos);
                readPos += 4;
                charItem.Exp = BitConverter.ToSingle(packetData, readPos);
                readPos += 4;

                packet.ItemList.Add(charItem);
            }

            return true;
        }