Example #1
0
        public void TestSimpleJson()
        {
            Simple simple1 = Simple.Create();
            string json1   = Proto <Simple> .ToJson(simple1);

            Simple simple2 = Proto <Simple> .FromJson(json1);

            string json2 = Proto <Simple> .ToJson(simple2);
        }
Example #2
0
        public void TestComplexJson()
        {
            Complex complex1 = Complex.Create();
            string  json1    = Proto <Complex> .ToJson(complex1);

            Complex complex2 = Proto <Complex> .FromJson(json1);

            string json2 = Proto <Complex> .ToJson(complex2);

            Assert.Equal(json1, json2);
        }
Example #3
0
        static void Dump(string url, CookieCollection cookies)
        {
            List <PCookie> list = new List <PCookie>();

            foreach (System.Net.Cookie cookie in cookies)
            {
                PCookie c = new PCookie
                {
                    Name       = cookie.Name,
                    Value      = cookie.Value,
                    Version    = cookie.Version,
                    Comment    = cookie.Comment,
                    CommentUri = cookie.CommentUri?.AbsolutePath,
                    Domain     = cookie.Domain,
                    Port       = cookie.Port,
                    Path       = cookie.Path,
                    Expired    = cookie.Expired,
                    Expires    = cookie.Expires,
                    HttpOnly   = cookie.HttpOnly,
                    Secure     = cookie.Secure,
                    Timestamp  = cookie.TimeStamp
                };
                list.Add(c);
            }

            PCookies cc = new PCookies
            {
                Cookies = new Dictionary <string, List <PCookie> >
                {
                    { url, list }
                },
            };

            string json = Proto <PCookies> .ToJson(cc);

            Console.WriteLine(json);
            Console.WriteLine();
            Console.WriteLine(Proto <PCookies> .ToJson(Proto <PCookies> .FromJson(json)));
            Console.WriteLine();
            string xml = Proto <PCookies> .ToXml(cc);

            Console.WriteLine(xml);
            Console.WriteLine(Proto <PCookies> .ToXml(Proto <PCookies> .FromXml(xml)));
            Console.WriteLine();
            Console.WriteLine();
        }
Example #4
0
        public override void ComplexTest()
        {
            trans.Clear();
            Proto <Complex> .Write(prot, complexInput);

            PrintBuf();
            trans.Seek(0, SeekOrigin.Begin);
            complexOutput = Proto <Complex> .Read(prot, complexOutput);

            if (this.xml)
            {
                string xml1 = Proto <Complex> .ToXml(complexOutput);

                WriteLine(xml1);
                complexOutput = Proto <Complex> .FromXml(xml1);

                string xml2 = Proto <Complex> .ToXml(complexOutput);

                CommonUtils.ThrowIfFalse(xml1 == xml2);
            }

            if (this.json)
            {
                string json1 = Proto <Complex> .ToJson(complexOutput);

                WriteLine(json1);
                complexOutput = Proto <Complex> .FromJson(json1);

                string json2 = Proto <Complex> .ToJson(complexOutput);

                WriteLine(json2);
                CommonUtils.ThrowIfFalse(json1 == json2);
            }

            WriteLine("simple:{0},{1},{2},{3}",
                      complexOutput.SimpleValue.Value,
                      complexOutput.SimpleValue.ShortValue,
                      complexOutput.SimpleValue.IntValue,
                      complexOutput.SimpleValue.LongValue);

            if (complexOutput.ListValue != null)
            {
                for (int i = 0; i < complexOutput.ListValue.Count; i++)
                {
                    WriteLine("list:{0},{1},{2},{3}",
                              complexOutput.ListValue[i].Value,
                              complexOutput.ListValue[i].ShortValue,
                              complexOutput.ListValue[i].IntValue,
                              complexOutput.ListValue[i].LongValue);
                }
            }

            if (complexOutput.SetValue != null)
            {
                foreach (Simple simple in complexOutput.SetValue)
                {
                    WriteLine("set:{0},{1},{2},{3}",
                              simple.Value,
                              simple.ShortValue,
                              simple.IntValue,
                              simple.LongValue);
                }
            }

            if (complexOutput.MapValue != null)
            {
                foreach (string key in complexOutput.MapValue.Keys)
                {
                    WriteLine("map[{0}]:{1},{2},{3},{4}",
                              key,
                              complexOutput.MapValue[key].Value,
                              complexOutput.MapValue[key].ShortValue,
                              complexOutput.MapValue[key].IntValue,
                              complexOutput.MapValue[key].LongValue);
                }
            }

            if (complexOutput.ArrayValue != null)
            {
                for (int i = 0; i < complexOutput.ArrayValue.Length; i++)
                {
                    WriteLine("array:{0},{1},{2},{3}",
                              complexOutput.ArrayValue[i].Value,
                              complexOutput.ArrayValue[i].ShortValue,
                              complexOutput.ArrayValue[i].IntValue,
                              complexOutput.ArrayValue[i].LongValue);
                }
            }

            if (complexOutput.StringArray != null)
            {
                for (int i = 0; i < complexOutput.StringArray.Length; i++)
                {
                    WriteLine("strarr:{0}", complexOutput.StringArray[i]);
                }
            }
        }