I want to use protobuf to use for the protocol over a socket connection.
My questions are regarding inheritance.
Say I have the following classes in my project:
- Animal
- Cat (inherits from Animal)
- Dog (inherits from Animal)
Let's say:
- Animal inherits from Creature which is from a class in a DLL that I cannot modify the code of (let's say it's a 3rd party library).
- Cat has 10 fields which I give the attributes ProtoMember 1 to 10 for.
- Dog as 12 fields so I give that ProtoMember 1 to 12.
- Animal has 5 fields so I give that ProtoMember 1 to 5.
So far so good.
In order to deal with the inheritance, let's say I use the following attribute on Cat:
[ProtoInclude(11, typeof(Pet))]
And on Dog I use:
[ProtoInclude(13, typeof(Pet))]
And on Animal use:
[ProtoInclude(6, typeof(Creature))]
Questions:
- Are these numbers I've used so far all valid? If not, what should they be and what's the reason for it?
- Should I be giving the numbers in ProtoInclude a gap (e.g. 111, 113 and 106) so that it allows for new fields to be added to those classes? Or do I keep the number series compact and adjust in future as and when needed?
So to deal with the inheritance of Creature (which code is not in my project), I believe I have to use Runtime Type declaration (as mentioned here: protobuf-net inheritance)
I'm not quite sure what statements I would need for this example, also where do these statements need to be placed within my project?
Any help will be greatly appreciated. Thank you.