Example #1
0
        public override void SimpleTest()
        {
            trans.Clear();
            Proto <Simple> .Write(prot, simpleInput);

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

            WriteLine("{0}:{1},{2},{3},{4}",
                      trans.Length,
                      simpleOutput.Value,
                      simpleOutput.ShortValue,
                      simpleOutput.IntValue,
                      simpleOutput.LongValue);
        }
Example #2
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]);
                }
            }
        }