rpc服务需要接收一个list, 请问该怎么定义输入的protobuf

需要发送的请求参数格式如下:

[
    {
        "name": "ada",
        "age":"12"
    }
]

已经尝试过的定义有:

message DocMsg
{
   string name = 1;  
   string age = 2;   
}
message HelloRequest
{
    repeated DocMsg doc = 1;
}

message HelloRequest {
  // 嵌套消息定义
  message Docmsg {
    string name = 1;  
   string age = 2;   
  }
  // 引用嵌套的消息定义
  repeated Docmsg doc = 1;
}

实际接收的请求参数都是

{
    "doc":[
        {"name":xxx, "age":xxx},
        ...
    ]
}

有没有做过的老哥指点一下,:pray:

讨论数量: 3
  1. 基于你当前的方法设计的protobuf 可以使用
  2. 可以使用any类型来表示你的list
    message HelloRequest {
      repeated  google.protobuf.Any details = 2;
    }
2年前 评论

二维数组应该是不支持的 参考:stackoverflow.com/questions/209686...

2年前 评论

用json序列化list为byte,接收端在反序列化一下,可以吗。

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!