Ejemplo n.º 1
0
        public void TestDataReading()
        {
            var data = new List<byte>();
            data.Add(byte.MaxValue);
            data.AddRange(BitConverter.GetBytes(short.MaxValue));
            data.AddRange(BitConverter.GetBytes(int.MaxValue));
            data.AddRange(BitConverter.GetBytes(float.MaxValue));
            data.AddRange(BitConverter.GetBytes(ulong.MaxValue));
            data.AddRange(Encoding.UTF8.GetBytes("test string"));
            data.Add(0x00); // String terminate

            var reader = new PacketReader(data.ToArray());

            Assert.That(reader.ReadByte(), Is.EqualTo(byte.MaxValue));
            Assert.That(reader.ReadShort(), Is.EqualTo(short.MaxValue));
            Assert.That(reader.ReadLong(), Is.EqualTo(int.MaxValue));
            Assert.That(reader.ReadFloat(), Is.EqualTo(float.MaxValue));
            Assert.That(reader.ReadLongLong(), Is.EqualTo(ulong.MaxValue));
            Assert.That(reader.ReadUTFString(), Is.EqualTo("test string"));
        }
Ejemplo n.º 2
0
        private TCPPacket Parse(byte[] data)
        {
            var result = new TCPPacket();
            var packetReader = new PacketReader(data);
            result.Size = packetReader.ReadLong();
            result.Id = packetReader.ReadLong();
            result.Type = packetReader.ReadLong();
            result.Body = packetReader.ReadASCIIString();
            result.EmptyString = packetReader.ReadASCIIString();

            return result;
        }