Protobuf-net .proto file generation for inheritance

前端 未结 1 363
谎友^
谎友^ 2021-01-03 11:07

I am prototyping Protobuf-net to replace some of our existing C# code which is currently using [Datacontract] to Serialize objects to Xml.

Using protobuffer we can e

相关标签:
1条回答
  • 2021-01-03 11:23

    Since inheritance is not part of the core spec, I basically represent this using encapsulation. So your [ProtoInclude] maps to:

    message ProtoAlien {
       // other fields 1 thru 6 [snip]
       optional ProtoScholar ProtoScholar = 7;
    }
    message ProtoScholar {
       optional string Subject = 1;
    }
    

    GetProto<T>() is undergoing an overhaul in v2, so it should support a few more of these scenarios.

    0 讨论(0)
提交回复
热议问题