如何在 protobuf 中添加一个 if 类型的条件?
How to add a if sort of condition in protobuf?
我有一个如下所示的 protobuf 定义,
message SearchRequest {
string my_id = 1;
enum MyStrategy {
MY_TEST1 = 1;
MY_TEST2 = 2;
}
MyStrategy my_strategy = 2;
}
现在我想添加一个选项,比如如果 MY_TEST2 被 selected,那么客户会被要求从另一组选项中再次 select,如果 MY_TEST1 selected 将不提供任何选项。
提示输入值的实际行为是 UI 与 protobuf 完全无关的事情; protobuf 只是描述数据交换,所以我猜(尽管请纠正我)你实际上想说的是:
As part of a search, the user needs to choose a "strategy"; each strategy has different fields that need to be provided; how can I describe the fields needed for each strategy, and encode the selection of the strategy?
如果是这样,听起来您实际上想要描述的是 oneof
,即
syntax="proto3";
message SearchRequest {
string my_id = 1;
oneof strategy {
SearchOptionsFoo foo = 2;
SearchOptionsBar bar = 3;
}
}
message SearchOptionsFoo {
// fields here ...
}
message SearchOptionsBar {
// fields here ...
}
我有一个如下所示的 protobuf 定义,
message SearchRequest {
string my_id = 1;
enum MyStrategy {
MY_TEST1 = 1;
MY_TEST2 = 2;
}
MyStrategy my_strategy = 2;
}
现在我想添加一个选项,比如如果 MY_TEST2 被 selected,那么客户会被要求从另一组选项中再次 select,如果 MY_TEST1 selected 将不提供任何选项。
提示输入值的实际行为是 UI 与 protobuf 完全无关的事情; protobuf 只是描述数据交换,所以我猜(尽管请纠正我)你实际上想说的是:
As part of a search, the user needs to choose a "strategy"; each strategy has different fields that need to be provided; how can I describe the fields needed for each strategy, and encode the selection of the strategy?
如果是这样,听起来您实际上想要描述的是 oneof
,即
syntax="proto3";
message SearchRequest {
string my_id = 1;
oneof strategy {
SearchOptionsFoo foo = 2;
SearchOptionsBar bar = 3;
}
}
message SearchOptionsFoo {
// fields here ...
}
message SearchOptionsBar {
// fields here ...
}