将多个字段设置为Oneof的一个元素
我想定义一条消息,该消息可以具有2个字段(字段A和字段B)XOR另一个字段(仅字段C)。我看到我可以使用关键字oneof
设置XOR,但仅在两个字段之间。 我该如何表达我的需求?
理想情况下,我想要类似( 工作)之类的东西
syntax = "proto3";
message M {
oneof name {
{
string a = 1;
string b = 2;
}
string c = 3;
}
}
I want to define a message that can have 2 fields (field A AND field B) XOR one other field (field C alone). I saw I can use the keyword oneof
to set the XOR, but only between two fields.
how can I express my needs?
Ideally I want something like (not working)
syntax = "proto3";
message M {
oneof name {
{
string a = 1;
string b = 2;
}
string c = 3;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道的唯一方法是将两个字段
A
和b
放入单独的订阅中,然后您可以将其放入Oneof
中:另外可以将所有字段放入
m
的情况下,而无需Oneof
。在评论中描述逻辑,并在应用程序代码中手动检查。Only way I know of is to put the two fields
a
andb
into separate submessage, which you can then put inside theoneof
:Alternatively you can put all fields into
M
withoutoneof
. Describe the logic in the comments and check it manually in application code.