Example #1
0
        void Execute_WithLengthPrefix(TypeModel model, string caption)
        {
            const Test original = Test.test2;
            using (MemoryStream ms = new MemoryStream())
            {
                model.SerializeWithLengthPrefix(ms, original, typeof(Test), PrefixStyle.Fixed32, 1);
                ms.Position = 0;
                Assert.AreEqual("02-00-00-00-08-01", BitConverter.ToString(ms.GetBuffer(), 0, (int)ms.Length));
                Test obj;
                obj = (Test)model.DeserializeWithLengthPrefix(ms, null, typeof(Test), PrefixStyle.Fixed32, 1);

                Assert.AreEqual(original, obj);
            }
        }
Example #2
0
        private void RunTest(TypeModel typeModel, string caption)
        {
            const PrefixStyle prefixStyle = PrefixStyle.Base128;
            const int testValue = 5;
            using (var ms = new MemoryStream())
            {

                typeModel.SerializeWithLengthPrefix(ms, new SomeMessage(new Descriptor(new SomeEvent { SomeField = testValue })), null, prefixStyle, 0);

                ms.Seek(0, SeekOrigin.Begin);

                // fails here
                var message = (SomeMessage)typeModel.DeserializeWithLengthPrefix(ms, null, typeof(Message), prefixStyle, 0);

                Assert.AreEqual(testValue, ((SomeEvent)message.Desc.EventData).SomeField, caption);
            }
        }
Example #3
0
 static public int DeserializeWithLengthPrefix(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 6)
         {
             ProtoBuf.Meta.TypeModel self = (ProtoBuf.Meta.TypeModel)checkSelf(l);
             System.IO.Stream        a1;
             checkType(l, 2, out a1);
             System.Object a2;
             checkType(l, 3, out a2);
             System.Type a3;
             checkType(l, 4, out a3);
             ProtoBuf.PrefixStyle a4;
             checkEnum(l, 5, out a4);
             System.Int32 a5;
             checkType(l, 6, out a5);
             var ret = self.DeserializeWithLengthPrefix(a1, a2, a3, a4, a5);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 7)
         {
             ProtoBuf.Meta.TypeModel self = (ProtoBuf.Meta.TypeModel)checkSelf(l);
             System.IO.Stream        a1;
             checkType(l, 2, out a1);
             System.Object a2;
             checkType(l, 3, out a2);
             System.Type a3;
             checkType(l, 4, out a3);
             ProtoBuf.PrefixStyle a4;
             checkEnum(l, 5, out a4);
             System.Int32 a5;
             checkType(l, 6, out a5);
             ProtoBuf.Serializer.TypeResolver a6;
             LuaDelegation.checkDelegate(l, 7, out a6);
             var ret = self.DeserializeWithLengthPrefix(a1, a2, a3, a4, a5, a6);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 8)
         {
             ProtoBuf.Meta.TypeModel self = (ProtoBuf.Meta.TypeModel)checkSelf(l);
             System.IO.Stream        a1;
             checkType(l, 2, out a1);
             System.Object a2;
             checkType(l, 3, out a2);
             System.Type a3;
             checkType(l, 4, out a3);
             ProtoBuf.PrefixStyle a4;
             checkEnum(l, 5, out a4);
             System.Int32 a5;
             checkType(l, 6, out a5);
             ProtoBuf.Serializer.TypeResolver a6;
             LuaDelegation.checkDelegate(l, 7, out a6);
             System.Int32 a7;
             var          ret = self.DeserializeWithLengthPrefix(a1, a2, a3, a4, a5, a6, out a7);
             pushValue(l, true);
             pushValue(l, ret);
             pushValue(l, a7);
             return(3);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }