문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top