Пример #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);
            }
        }
Пример #2
0
 static public int SerializeWithLengthPrefix(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);
             self.SerializeWithLengthPrefix(a1, a2, a3, a4, a5);
             pushValue(l, true);
             return(1);
         }
         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.SerializationContext a6;
             checkType(l, 7, out a6);
             self.SerializeWithLengthPrefix(a1, a2, a3, a4, a5, a6);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #3
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);
            }
        }