Protobuf-net 跳过特定字段的反序列化 [英] Protobuf-net skip deserialization of specific fields

查看:82
本文介绍了Protobuf-net 跳过特定字段的反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经序列化了这个类:

I have serialized this class:

[ProtoContract]
public class TestClass
{
    [ProtoMember(1)] public int[] hugeArray;
    [ProtoMember(2)] public int x;
    [ProtoMember(3)] public int y;
    //lot more fields and properties to serialize here...

}

如何在反序列化过程中跳过 [ProtoMember(1)] 巨大数组,以便仅反序列化 x、y 和其他字段?

How do I skip the [ProtoMember(1)] hugeArray during deserialization, so that only x, y, and other fields get deserialized?

我的问题是有时我很快只需要获取元数据",这是其他字段和属性所描述的,但有时我需要一个完整的对象.

My problem is that sometimes I quickly need only to get the 'metadata', which is what other fields and properties describe, but sometimes I need an entire object.

推荐答案

两个选项:

  • 两个 RuntimeTypeModel 实例(一个手动构建,仅指定所需字段)
  • 两种类型;即创建一个更简单的 TestClass,它简单地省略大字段 - 即 TestClassMetadata - 并反序列化为 that;protobuf-net 根本不介意
  • two RuntimeTypeModel instances (one built manually with only the desired fields specified)
  • two types; i.e. create a simpler TestClass that simply omits the big fields - i.e. TestClassMetadata - and deserialize into that; protobuf-net won't mind at all

这篇关于Protobuf-net 跳过特定字段的反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆