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); }
public override void Setup() { simpleInput = new Simple(); simpleInput.Value = simpleValue; simpleInput.ShortValue = 16; simpleInput.IntValue = 17; simpleInput.LongValue = 18; simpleOutput = new Simple(); complexInput = new Complex(); complexOutput = new Complex(); complexInput.SimpleValue = simpleInput; complexInput.ListValue = new List <Simple> { simpleInput, simpleInput }; if (full) { complexInput.StringArray = Enumerable .Range(0, this.simpleValue.Length) .Select(i => this.simpleValue.Substring(i)) .ToArray(); complexInput.SetValue = complexInput.ListValue.ToHashSet(); complexInput.MapValue = new Dictionary <string, Simple> { { "a", simpleInput }, { "b", simpleInput } }; complexInput.ArrayValue = complexInput.ListValue.ToArray(); } trans = new TByteBuffer(1024); // prot = new TBinaryProtocol(trans); prot = new TCompactProtocol(trans); trans.Clear(); Proto <Simple> .Write(prot, simpleInput); }
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]); } } }