如何用 Proto 定义表示 JSON 对象变量

How to represent a JSON object variable with Proto definition

我想在 gRPC 中定义一个请求消息,它应该有一个 Json 对象作为字段 例如

message UserRequest{
    string name = 1;
    string city = 2;
    string email = 3;
    metainfo = 4;//A Json Object variable which can have any number of elements
}

如何在原型定义中表示元信息 属性? 我试过使用下面的定义,但没有用。

message UserRequest{
    string name = 1;
    string city = 2;
    string email = 3;
    google.protobuf.Any metainfo = 4;
}

我想你想要一个 .google.protobuf.Struct,通过 struct.proto - 这本质上封装了一个 map<string, Value> fields,并且大致类似于你想通过 JSON 描述的内容.此外,Struct 具有自定义 JSON 处理,如文件中所述:

The JSON representation for Struct is JSON object.

所以:

    .google.protobuf.Struct metainfo = 4;