Exemplo n.º 1
0
        public void TestMsgSerializerFactory()
        {
            var mc = new MyClass
            {
                Age       = 99,
                FirstName = "hoge",
                LastName  = "huga",
            };

            MsgSerializerFactory.Instance().Set(1, typeof(MyClass));

            var stream     = new MemoryStream();
            var serializer = MsgSerializerFactory.Instance().Get(1);

            serializer.Pack(stream, mc);

            uint msgPackLen = (uint)stream.Position;

            stream.Position = 0;

            uint msgLen = 0;

            MsgSerializer.ReadUInt32(stream, out msgLen);
            Assert.IsTrue(msgPackLen == msgLen);

            uint msgType = 0;

            MsgSerializer.ReadUInt32(stream, out msgType);
            Assert.IsTrue(msgType == 1);

            var mc2 = (MyClass)serializer.Unpack(stream);

            Assert.IsTrue(mc2.LastName == mc.LastName);
        }
Exemplo n.º 2
0
        public void TestMsgSerializer()
        {
            var mc = new MyClass
            {
                Age       = 99,
                FirstName = "hoge",
                LastName  = "huga",
            };

            var stream     = new MemoryStream();
            var serializer = new MsgSerializer(typeof(MyClass), 1);

            serializer.Pack(stream, mc);

            stream.Position = 0;

            uint msgLen = 0;

            MsgSerializer.ReadUInt32(stream, out msgLen);

            uint msgType = 0;

            MsgSerializer.ReadUInt32(stream, out msgType);
            Assert.IsTrue(msgType == 1);

            var mc2 = (MyClass)serializer.Unpack(stream);

            Assert.IsTrue(mc2.LastName == mc.LastName);
        }
Exemplo n.º 3
0
        public ClientMsgInputs(byte[] buffer, int offset)
        {
            MsgSerializer.ValidateHeader(buffer, MsgId, ref offset);

            Frame     = MsgSerializer.ReadUInt32(buffer, ref offset);
            InputMask = MsgSerializer.ReadUInt64(buffer, ref offset);
        }
Exemplo n.º 4
0
        public ClientMsgFinished(byte[] buffer, int offset)
        {
            MsgSerializer.ValidateHeader(buffer, MsgId, ref offset);

            Frame     = MsgSerializer.ReadUInt32(buffer, ref offset);
            StateHash = MsgSerializer.ReadInt32(buffer, ref offset);
        }
Exemplo n.º 5
0
        public ServerMsgInput(byte[] buffer, int offset)
        {
            MsgSerializer.ValidateHeader(buffer, MsgId, ref offset);

            Frame       = MsgSerializer.ReadUInt32(buffer, ref offset);
            InputMask   = MsgSerializer.ReadUInt64(buffer, ref offset);
            PlayerIndex = MsgSerializer.ReadByte(buffer, ref offset);
        }
        public void ShouldSerializeAndDeserializeUInt32(uint value)
        {
            var written = MsgSerializer.WriteUInt32(value, _buffer, 0);

            Assert.True(written == sizeof(uint), $"Bad write size: {written}");

            var offset       = 0;
            var deserialized = MsgSerializer.ReadUInt32(_buffer, ref offset);

            Assert.True(offset == sizeof(uint), $"Bad read size: {offset}");

            Assert.True(value == deserialized, $"Bad result: {deserialized}");
        }