我有许多不同的模式,但是每个模式都包含一组字段。我想知道是否有一种方法可以让不同的模式扩展父模式并继承其字段。例如,这就是我想要的:
message Parent {
required string common1 = 0;
optional string common2 = 1;
}
message Child1 { // can we extend the Parent?
// I want common1, common2 to be fields here
required int c1 = 2;
required string c2 = 3;
}
message Child2 { // can we extend Parent?
// I want common1, common2 to be fields here
repeated int c3 = 2;
repeated string c4 = 3;
}
这样 Child1 和 Child2 还包含来自 Parent 的字段 common1 和 common2(以及可能更多)。
这可能吗?如果可能的话怎么办?
这不是您问题的确切答案,但我们可以这样做来共享通用参数。
message Child1 {
required int c1 = 2;
required string c2 = 3;
}
message Child2 {
required int c1 = 2;
required string c2 = 3;
}
message Request {
required string common1 = 0;
optional string common2 = 1;
oneof msg { Child1 c1 = 2; Child2 c2 = 3; }
}
其他选项是使用extend keyword
message Parent {
required string common1 = 0;
optional string common2 = 1;
}
message Child1 {
extend Parent
{
optional Child1 c1 = 100;
}
required int c1 = 2;
required string c2 = 3;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)