Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void TestMsgPackProtocolRecv_1()
        {
            // 수신을 확인한다.

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

            var l = new MsgPackNode();
            var p = new MsgPackProtocol(l);

            var mc = new MyClass
            {
                Age       = 99,
                FirstName = "hoge",
                LastName  = "huga",
            };

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

            serializer.Pack(stream, mc);

            p.OnReceived(stream);

            Assert.IsTrue(p.MessageCount == 1);

            var mc2 = (MyClass)l.Next();

            Assert.IsTrue(mc2 != null);
            Assert.IsTrue(mc2.FirstName == mc.FirstName);
            Assert.IsTrue(mc2.Protocol == p);
        }