Protobuf-net skip deserialization of specific fields

蹲街弑〆低调 提交于 2019-12-24 00:57:33

问题


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...

}

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.


回答1:


Two options:

  • 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


来源:https://stackoverflow.com/questions/28444460/protobuf-net-skip-deserialization-of-specific-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!