protobuf-net – Not specify sub types of a base class-Collection of common programming errors
I have an inheritance chain such as this:
[ProtoContract]
public abstract class Message
{
[ProtoMember(1, OverwriteList = true)]
public List Headers {get; set;}
}
[ProtoContract]
public class EventMessage : Message
{
[ProtoMember(2)]
public T Event {get; set;}
}
The inheritance chain is very straight forward (my . In order to get the Headers to be included in the serialization, I need to do:
RuntimeTypeModel.Default[typeof(Packet)].AddSubType(3, typeof(Message));
I know this sort of answer (the line above) has been documented on quite a few StackOverflow posts. However, I don’t like this design because then I need to declare all my subtypes ahead of time and it’s also implying a limited, small number of subtypes.
I’m attempting to code a message bus in my application, using protobuf-net for the serialization/deserialization. The message bus needs to send out ‘events’ and respond to request/replies. Since I have many (easily > 100) events in my system, I don’t want to declare a subtype for every closed generic type in the RuntimeTypeModel.
Does protobuf-net have the ability to infer subtypes/classes? Or ideally, I’d like something like:
RuntimeTypeModel.Default[typeof(Packet)].AddSubType(3, typeof(Message));
(Which I tried and it doesn’t work).