Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf.net inheritance - using ImplicitFields = ImplicitFields.AllFields

i have a base class which decorated with [ProtoContract(ImplicitFields = ImplicitFields.AllFields)]

in order to be able to serialize a derived class , do i only need to add ProtoInclude? as the derived class fields are not being serialize - does the inheritance works only with Protomember?

like image 944
li-raz Avatar asked May 28 '26 15:05

li-raz


1 Answers

Protobuf doesn't fully support inheritance you need to do a little decoration in your base class.

[
ProtoContract(),
ProtoInclude(100, typeof(Peer)),
ProtoInclude(101, typeof(Instruction))
]
class Base {...}

[ProtoContract()]
class Peer: Base
{ ... }

[ProtoContract()]
class Instruction: Base
{ ... }

for derived classes that only provide properties via the Base class.

like image 86
Paul Farry Avatar answered May 30 '26 03:05

Paul Farry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!