예제 #1
0
 public Nesting(
     Bonk myBonk,
     OneOfEach myOoe
 ) {
     this.MyBonk = myBonk;
     this.MyOoe = myOoe;
 }
        public void TestDeserialization()
        {
            byte[] serialized = TMemoryBuffer.Serialize(Fixtures.oneOfEach);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i < HOW_MANY; i++)
            {
                OneOfEach o = new OneOfEach();
                TProtocol proto = new TBinaryProtocol.Factory().GetProtocol(new TMemoryBuffer(serialized));
                o.Read(proto);
            }

            stopwatch.Stop();

            Console.WriteLine("Serialization test time : {0} ms", stopwatch.ElapsedMilliseconds);

        }
예제 #3
0
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
         field = iprot.ReadFieldBegin();
         if (field.Type == TType.Stop) { 
             break;
         }
         switch (field.ID)
         {
             case 1:
                 if (field.Type == TType.Struct) {
                     MyBonk = new Bonk();
                     MyBonk.Read(iprot);
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 2:
                 if (field.Type == TType.Struct) {
                     MyOoe = new OneOfEach();
                     MyOoe.Read(iprot);
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             default:
                 TProtocolUtil.Skip(iprot, field.Type);
                 break;
         }
         iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
예제 #4
0
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
         field = iprot.ReadFieldBegin();
         if (field.Type == TType.Stop) { 
             break;
         }
         switch (field.ID)
         {
             case 1:
                 if (field.Type == TType.List) {
                     {
                         Big = new List<OneOfEach>();
                         TList _list0 = iprot.ReadListBegin();
                         for(int _i1 = 0; _i1 < _list0.Count; ++_i1)
                         {
                             OneOfEach _elem2 = new OneOfEach();
                             _elem2 = new OneOfEach();
                             _elem2.Read(iprot);
                             Big.Add(_elem2);
                         }
                         iprot.ReadListEnd();
                     }
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 2:
                 if (field.Type == TType.Set) {
                     {
                         Contain = new HashSet<List<string>>();
                         TSet _set3 = iprot.ReadSetBegin();
                         for(int _i4 = 0; _i4 < _set3.Count; ++_i4)
                         {
                             List<string> _elem5 = new List<string>();
                             {
                                 _elem5 = new List<string>();
                                 TList _list6 = iprot.ReadListBegin();
                                 for(int _i7 = 0; _i7 < _list6.Count; ++_i7)
                                 {
                                     string _elem8 = null;
                                     _elem8 = iprot.ReadString();
                                     _elem5.Add(_elem8);
                                 }
                                 iprot.ReadListEnd();
                             }
                             Contain.Add(_elem5);
                         }
                         iprot.ReadSetEnd();
                     }
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 3:
                 if (field.Type == TType.Map) {
                     {
                         Bonks = new Dictionary<string, List<Bonk>>();
                         TMap _map9 = iprot.ReadMapBegin();
                         for(int _i10 = 0; _i10 < _map9.Count; ++_i10)
                         {
                             string _key11;
                             List<Bonk> _val12;
                             _key11 = iprot.ReadString();
                             {
                                 _val12 = new List<Bonk>();
                                 TList _list13 = iprot.ReadListBegin();
                                 for(int _i14 = 0; _i14 < _list13.Count; ++_i14)
                                 {
                                     Bonk _elem15 = new Bonk();
                                     _elem15 = new Bonk();
                                     _elem15.Read(iprot);
                                     _val12.Add(_elem15);
                                 }
                                 iprot.ReadListEnd();
                             }
                             Bonks[_key11] = _val12;
                         }
                         iprot.ReadMapEnd();
                     }
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             default:
                 TProtocolUtil.Skip(iprot, field.Type);
                 break;
         }
         iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
예제 #5
0
        static Fixtures() {
            oneOfEach = new OneOfEach();
            oneOfEach.ImTrue = true;
            oneOfEach.ImFalse = false;
            oneOfEach.ABite = (sbyte)0x16;
            oneOfEach.Integer16 = 27000;
            oneOfEach.Integer32 = 1 << 24;
            oneOfEach.Integer64 = (long)6000 * 1000 * 1000;
            oneOfEach.DoublePrecision =  Math.PI;
            oneOfEach.SomeCharacters = "JSON THIS! \"";
            oneOfEach.ZomgUnicode = Encoding.UTF8.GetString(kUnicodeBytes);
            oneOfEach.Base64 = Encoding.UTF8.GetBytes("base64");

            Bonk bonk = new Bonk();
            bonk.Type = 31337;
            bonk.Message = "I am a bonk... xor!";
            nesting = new Nesting(bonk, oneOfEach);

            holyMoley = new HolyMoley();
            List<OneOfEach> big = new List<OneOfEach>();
            big.Add(oneOfEach);
            big.Add(nesting.MyOoe);
            holyMoley.Big = big;
            holyMoley.Big[0].ABite = 0x22;
            holyMoley.Big[0].ABite = 0x23;

            holyMoley.Contain = new HashSet<List<string>>();
            List<string> stage1 = new List<string>(2);
            stage1.Add("and a one");
            stage1.Add("and a two");
            holyMoley.Contain.Add(stage1);
            stage1 = new List<string>(3);
            stage1.Add("then a one, two");
            stage1.Add("three!");
            stage1.Add("FOUR!!");
            holyMoley.Contain.Add(stage1);
            stage1 = new List<string>(0);
            holyMoley.Contain.Add(stage1);

            List<Bonk> stage2 = new List<Bonk>();
            holyMoley.Bonks = new Dictionary<string, List<Bonk>>();
            // one empty
            holyMoley.Bonks["zero"] = stage2;

            // one with two
            stage2 = new List<Bonk>();
            Bonk b = new Bonk();
            b.Type = 1;
            b.Message = "Wait.";
            stage2.Add(b);
            b = new Bonk();
            b.Type = 2;
            b.Message = "What?";
            stage2.Add(b);
            holyMoley.Bonks["two"] = stage2;

            // one with three
            stage2 = new List<Bonk>();
            b = new Bonk();
            b.Type = 3;
            b.Message = "quoth";
            stage2.Add(b);
            b = new Bonk();
            b.Type = 4;
            b.Message = "the raven";
            stage2.Add(b);
            b = new Bonk();
            b.Type = 5;
            b.Message = "nevermore";
            stage2.Add(b);
            holyMoley.Bonks["three"] = stage2;

            // superhuge compact proto test struct
            compactProtoTestStruct = new CompactProtoTestStruct();
            compactProtoTestStruct.ABinary = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            compactProtoTestStruct.AByte = 127;
            compactProtoTestStruct.AI16 = 32000;
            compactProtoTestStruct.AI32 = 100000000;
            compactProtoTestStruct.AI64 = 0xffffffffffL;
            compactProtoTestStruct.ADouble = 5.6789;
            compactProtoTestStruct.AString = "my string";
            compactProtoTestStruct.TrueField = true;
            compactProtoTestStruct.FalseField = false;
            compactProtoTestStruct.EmptyStructField = new Empty();
            compactProtoTestStruct.ByteList = new List<sbyte?> { -127, -1, 0, 1, 127 };
            compactProtoTestStruct.I16List = new List<short?> { -1, 0, 1, 0x7fff };
            compactProtoTestStruct.I32List = new List<int?> { -1, 0, 0xff, 0xffff, 0xffffff, 0x7fffffff };
            compactProtoTestStruct.I64List = new List<long?> { -1L, 0L, 0xffL, 0xffffL, 0xffffffL, 0xffffffffL, 0xffffffffffL, 0xffffffffffffL, 0xffffffffffffffL, 0x7fffffffffffffffL };
            compactProtoTestStruct.DoubleList = new List<double?> { 0.1, 0.2, 0.3 };
            compactProtoTestStruct.StringList = new List<string> { "first", "second", "third" };
            compactProtoTestStruct.BooleanList = new List<bool?> { true, true, true, false, false, false };
            compactProtoTestStruct.StructList = new List<Empty> { new Empty(), new Empty() };
            compactProtoTestStruct.ByteSet = new HashSet<sbyte?> { (sbyte)-127, (sbyte)-1, (sbyte)0, (sbyte)1, (sbyte)127 };
            compactProtoTestStruct.I16Set = new HashSet<short?> { (short)-1, (short)0, (short)1, (short)0x7fff };
            compactProtoTestStruct.I32Set = new HashSet<int?> { 1, 2, 3 };
            compactProtoTestStruct.I64Set = new HashSet<long?> { -1L, 0L, 0xffL, 0xffffL, 0xffffffL, 0xffffffffL, 0xffffffffffL, 0xffffffffffffL, 0xffffffffffffffL, 0x7fffffffffffffffL };
            compactProtoTestStruct.DoubleSet = new HashSet<double?> { 0.1, 0.2, 0.3 };
            compactProtoTestStruct.StringSet = new HashSet<string> { "first", "second", "third" };
            compactProtoTestStruct.BooleanSet = new HashSet<bool?> { true, false };
            compactProtoTestStruct.StructSet = new HashSet<Empty> { new Empty() };
            compactProtoTestStruct.ByteByteMap = new Dictionary<sbyte?, sbyte?> { { 1, 2 } };
            compactProtoTestStruct.I16ByteMap = new Dictionary<short?, sbyte?> { { 1, 1 }, { -11, 1 }, { 0x7fff, 1 } };
            compactProtoTestStruct.I32ByteMap = new Dictionary<int?, sbyte?> { {1, 1}, {-1, 1}, {0x7fffffff, 1} };
            compactProtoTestStruct.I64ByteMap = new Dictionary<long?, sbyte?> { {0, 1}, {1, 1}, {-1, 1}, {0x7fffffffffffffffL, 1} };
            compactProtoTestStruct.DoubleByteMap = new Dictionary<double?, sbyte?> { { -1.1, 1}, {1.1, 1} };
            compactProtoTestStruct.StringByteMap = new Dictionary<string, sbyte?> { {"first", 1}, {"second", 2}, {"third", 3}, {"", 0}};
            compactProtoTestStruct.BooleanByteMap = new Dictionary<bool?, sbyte?> { { true, 1 }, { false, 0 } };
            compactProtoTestStruct.ByteI16Map = new Dictionary<sbyte?, short?> { { 1, 1 }, { 2, -1 }, { 3, 0x7fff } };
            compactProtoTestStruct.ByteI32Map = new Dictionary<sbyte?, int?> { {1, 1}, {2, -1}, {3, 0x7fffffff} };
            compactProtoTestStruct.ByteI64Map = new Dictionary<sbyte?, long?> { { 1, 1 }, { 2, -1 }, { 3, 0x7fffffffffffffffL } };
            compactProtoTestStruct.ByteDoubleMap = new Dictionary<sbyte?, double?> { { 1, 0.1 }, { 2, -0.1 }, { 3, 1000000.1 } };
            compactProtoTestStruct.ByteStringMap = new Dictionary<sbyte?, string> { { 1, "" }, { 2, "blah" }, { 3, "loooooooooooooong string" } };
            compactProtoTestStruct.ByteBooleanMap = new Dictionary<sbyte?, bool?> { {1, true}, {2, false} };
            compactProtoTestStruct.ListByteMap = new Dictionary<List<sbyte?>, sbyte?> { {new List<sbyte?> {1, 2, 3}, 1}, {new List<sbyte?> {0, 1}, 2 }, {new List<sbyte?>(), 0}};
            compactProtoTestStruct.SetByteMap = new Dictionary<HashSet<sbyte?>, sbyte?> { { new HashSet<sbyte?> { 1, 2, 3 }, 1 }, { new HashSet<sbyte?> {0, 1}, 2}, { new HashSet<sbyte?>(), 0} };
            compactProtoTestStruct.MapByteMap = new Dictionary<Dictionary<sbyte?, sbyte?>, sbyte?> { { new Dictionary<sbyte?, sbyte?> { { 1, 1 } }, 1 }, { new Dictionary<sbyte?, sbyte?> { { 2, 2 } }, 2 }, { new Dictionary<sbyte?, sbyte?>(), 0 } };
            compactProtoTestStruct.ByteMapMap = new Dictionary<sbyte?, Dictionary<sbyte?, sbyte?>> { { 0, new Dictionary<sbyte?, sbyte?>() }, { 1, new Dictionary<sbyte?, sbyte?> { { 1, 1 } } }, { 2, new Dictionary<sbyte?, sbyte?> { { 1, 1 }, {2, 2} } } };
            compactProtoTestStruct.ByteSetMap = new Dictionary<sbyte?, HashSet<sbyte?>> { {0, new HashSet<sbyte?>() }, {1, new HashSet<sbyte?> {1}}, {2, new HashSet<sbyte?> {1, 2}} };
            compactProtoTestStruct.ByteListMap = new Dictionary<sbyte?, List<sbyte?>> { {0, new List<sbyte?>()}, {1, new List<sbyte?> { 1 }}, { 2, new List<sbyte?> {1, 2} } };
        }