如何在.proto文件中将com.google.protobuf.Message定义为消息类型

时间:2017-12-25 16:21:15

标签: protocol-buffers proto3

如何在proto文件中定义通用消息。

例如:

v.xyzw

我需要遵循以下协议,而不是上述协议。

v.rgba

我需要在message GenericResponse { bool status = 1; Foo foo= 2; Bar bar = 3; Baz baz = 4; } 中设置message GenericResponse { bool status = 1; google.protobuf.Message response = 2; } FooBar值。 有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:2)

我建议oneof是你最好的选择:

message GenericResponse
{
    bool status = 1;
    oneof response {
        Foo foo= 2;
        Bar bar = 3;
        Baz baz = 4;
    }
}

你也可以使用Any,但IMO会出错,会让你更难。