コード例 #1
0
        private void ReceiveMessage(BinaryMessage msg)
        {
            var reader = msg.GetReader();

            switch (msg.Type)
            {
            case MSG_REL:
                var seq = reader.ReadUInt16();
                while (reader.HasRemaining)
                {
                    var type = reader.ReadByte();
                    int len;
                    if ((type & 0x80) != 0)                             // is not last?
                    {
                        type &= 0x7f;
                        len   = reader.ReadUInt16();
                    }
                    else
                    {
                        len = (int)reader.Remaining;
                    }
                    ReceiveSeqMessage(seq, new BinaryMessage(type, reader.ReadBytes(len)));
                    seq++;
                }
                break;

            case MSG_ACK:
                sender.ReceiveAck(reader.ReadUInt16());
                break;

            case MSG_MAPDATA:
                HandleMapData(msg.GetReader());
                break;

            case MSG_OBJDATA:
                HandleGobData(msg.GetReader());
                break;

            case MSG_CLOSE:
                Close();
                return;
            }
        }
コード例 #2
0
        public void ReadWriteTest()
        {
            var input = BinaryMessage.Make(1)
                        .String("Test")
                        .UInt16(64)
                        .String("Test2")
                        .Complete();

            var output = new BinaryMessage(1, input.GetData());

            Assert.AreEqual(output.Type, input.Type);

            using (var reader = output.GetReader())
            {
                Assert.AreEqual("Test", reader.ReadCString());
                Assert.AreEqual(64, reader.ReadUInt16());
                Assert.AreEqual("Test2", reader.ReadCString());
            }
        }