google protocol buffers:如何在 proto 文件中定义包含 ArrayList<ArrayList<String>> 的消息

google protocol buffers: how to define message contains ArrayList<ArrayList<String>> in proto file

ArrayList对应重复字符串:

message m1 {
    repeated string mylist = 1;
}

如何在message中定义ArrayList< ArrayList< String> >? 谢谢!

您将需要另一条消息来表示内部列表。

message M1 {
  repeated M2 mylist = 1;
}

message M2 {
  repeated string mylist = 1;
}

当然,您可以向 M2 添加任意数量的字段,并且您需要一些单独的转换逻辑以将 assemble List<M2> 转换为 ArrayList<ArrayList<String>> .

您甚至可能想要创建一个可重复使用的消息来表示字符串列表:

message M1 {
  repeated StringList mylist = 1;
}

message StringList {
  repeated string value = 1;
}