在protobuf消息中定义嵌套的oneof消息

3

我尝试在Protobuf消息中定义嵌套的oneof消息。我们能在Protobuf消息中使用嵌套的oneof消息吗?

谢谢。


你尝试过这个,发生了什么事情? - Luciano
我有同样的问题。在第一个嵌套的oneof中,我收到了“缺少字段Numer”的错误。例如: - West_JR
1个回答

0

您可以使用“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;
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接