本文整理汇总了C#中ProtoBuf.Meta.TypeModel.DeserializeWithLengthPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# TypeModel.DeserializeWithLengthPrefix方法的具体用法?C# TypeModel.DeserializeWithLengthPrefix怎么用?C# TypeModel.DeserializeWithLengthPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.Meta.TypeModel
的用法示例。
在下文中一共展示了TypeModel.DeserializeWithLengthPrefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute_WithLengthPrefix
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: RunTest
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);
}
}