我尝试在Protobuf消息中定义嵌套的oneof消息。我们能在Protobuf消息中使用嵌套的oneof消息吗?
谢谢。
我尝试在Protobuf消息中定义嵌套的oneof消息。我们能在Protobuf消息中使用嵌套的oneof消息吗?
谢谢。
您可以使用“oneof”定义包含消息的消息。这些消息也可以包含“oneof”。
例如,如果我有一个控制硬件的API,由冷却器和注射泵组成,它们各自支持自己的操作,可能每个操作都具有不同的参数,我的API允许向单个设备发送单个命令,并强制仅使用正确的参数:
syntax="proto3";
message ChillerSetTemperature {
int32 temperature=1;
}
message ChillerGetTemperature {
bool noArg=1;
}
message Chiller {
oneof command {
ChillerSetTemperature Set = 1;
ChillerGetTemperature Get = 2;
}
}
message SyringePumpAspirate {
int32 volume = 1;
int32 speed = 2;
}
message SyringePumpDispense {
int32 volume = 1;
int32 speed = 2;
}
message SyringePumpSelectPort {
int32 position=1;
}
message Syringe {
oneof command {
SyringePumpAspirate Aspirate = 1;
SyringePumpDispense Dispense = 2;
SyringePumpSelectPort SelectPort = 3;
}
}
message Action {
oneof device {
Syringe syringe = 1;
Chiller chiller = 2;
}
}