Esempio n. 1
0
        public void Glue_SerializeDeserialize_WithHeadersWithChineseText()
        {
            var hdr = "<a><remote name='久有归天愿'/></a>";

            var frm1 = new WireFrame(123, false, FID.Generate(), hdr);


            var utfLen = WireFrame.HEADERS_ENCODING.GetByteCount(hdr);

            Aver.IsTrue(utfLen > hdr.Length);
            Console.WriteLine("{0} has {1} byte len and {2} char len".Args(hdr, utfLen, hdr.Length));

            Aver.AreEqual(WireFrame.FRAME_LENGTH + utfLen, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH + utfLen, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsFalse(frm2.OneWay);

            Aver.AreEqual("久有归天愿", frm2.Headers["remote"].AttrByName("name").Value);
        }
Esempio n. 2
0
        public void HeartBeat_SerializeDeserialize()
        {
            var frm1 = new WireFrame(FrameType.Heartbeat, 123, false, FID.Generate());

            Aver.IsTrue(frm1.OneWay);
            Aver.AreEqual(WireFrame.FRAME_LENGTH, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsTrue(frm2.OneWay);
        }
Esempio n. 3
0
        public void Glue_SerializeDeserialize_WithHeadersWithLatinText()
        {
            var hdr = "<a><remote name='zzz'/></a>";//Latin only chars

            var frm1 = new WireFrame(123, false, FID.Generate(), hdr);


            var utfLen = WireFrame.HEADERS_ENCODING.GetByteCount(hdr);

            Aver.IsTrue(utfLen == hdr.Length);

            Aver.AreEqual(WireFrame.FRAME_LENGTH + hdr.Length, frm1.Length);

            var ms = new MemoryStream();

            Aver.AreEqual(WireFrame.FRAME_LENGTH + hdr.Length, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Aver.IsTrue(frm1.Type == frm2.Type);
            Aver.AreEqual(frm1.RequestID, frm2.RequestID);
            Aver.AreEqual(frm1.OneWay, frm2.OneWay);

            Aver.AreEqual(frm1.Length, frm2.Length);
            Aver.AreEqual(frm1.Format, frm2.Format);
            Aver.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Aver.IsFalse(frm2.OneWay);

            Aver.AreEqual("zzz", frm2.Headers["remote"].AttrByName("name").Value);
        }
Esempio n. 4
0
        public void Echo_SerializeDeserialize()
        {
            var frm1 = new WireFrame(FrameType.Echo, 123, true, FID.Generate());

            Assert.IsFalse(frm1.OneWay);
            Assert.AreEqual(WireFrame.FRAME_LENGTH, frm1.Length);

            var ms = new MemoryStream();

            Assert.AreEqual(WireFrame.FRAME_LENGTH, frm1.Serialize(ms));

            ms.Position = 0;

            var frm2 = new WireFrame(ms);

            Assert.AreEqual(frm1.Type, frm2.Type);
            Assert.AreEqual(frm1.RequestID, frm2.RequestID);
            Assert.AreEqual(frm1.OneWay, frm2.OneWay);

            Assert.AreEqual(frm1.Length, frm2.Length);
            Assert.AreEqual(frm1.Format, frm2.Format);
            Assert.AreEqual(frm1.HeadersContent, frm2.HeadersContent);

            Assert.IsFalse(frm2.OneWay);
        }