我如何夸大Protobuf扩展?

问题描述 投票:0回答:1
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;
}

考虑到这是proto文件。

在C#中创建derived2 protobuf对象时,我如何膨胀derived.a和base.cmd?

考虑到解决方案将涉及protobuf / protobuf-net库

c# protocol-buffers protobuf-net
1个回答
0
投票

protobuf-net目前没有对extend / extensions的巨大支持。它的作用是允许您访问此类类型的未知成员,只要该类型在反序列化时具有放置该信息的位置。如果你从protogen开始这应该是这样的 - 否则,最简单的选择是改变你的POCO继承Extensible。完成后,Extensible.GetValue<T>提供了一种基本机制,通过其字段编号访问未申报成员。

© www.soinside.com 2019 - 2024. All rights reserved.