protoduf 继承
时间: 2023-02-11 17:51:56 浏览: 67
Protobuf支持继承。您可以通过使用"extend"关键字在.proto文件中定义父类消息,然后在其他消息中使用"extensions"关键字来继承父类消息的字段。例如:
```
message Parent {
optional int32 a = 1;
}
message Child {
extend Parent {
optional int32 b = 2;
}
}
```
这样定义之后, Child 消息就继承了 Parent 消息中的 a 字段,并且新增了 b 字段。
注意,继承不能改变原有字段的类型或者 tag, 也不能重新定义父类中已经存在的字段。