Question

message base
{
    required int32 cmd = 1;
    extensions 1000 to max;  
} 

message derived
{
    extend   base{ required derived test = 1001; }
    required int32 a = 1;

    extensions 1000 to 3000;  
}

message derived2
{
    extend   derived{ required derived2 b = 1001; 
    required int32 b = 1;
}

considering that this is the proto file.

How would i inflate derived.a and base.cmd while creating a derived2 protobuf object in C#?

considering the solution would be involving either protobuf / protobuf-net library

Was it helpful?

Solution

protobuf-net currently does not have huge support for extend / extensions. What it does to is let you access unknown members of such types, as long as the type had somewhere to put that information when deserializing. If you started from protogen this should already be the case - otherwise, the simplest option is to change your POCO to inherit Extensible. With that done, Extensible.GetValue<T> offers a basic mechanism to access undeclared members via their field number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top