google protobuffer how to define list of lists in proto file?

Protocol buffer does not have any type of list. But the list is repeated values of string. So we can create one message which has string input and call that message with repeated keyword from another message

For example

message person{
   repeated nameList list = 1;
 }

 message nameList{
    string name = 1;
 }

  1. You can declare your own "types" in proto files called message.
  2. If you'd like to declare a list you should use repeated keyword.

Combining those two gives us:

message ListOfListsOfStrings {
    repeated ListOfStrings listOfStrings=1;
}

message ListOfStrings {
    repeated string strings=1;
}

You can then use ListOfListsOfStrings message in your proto were appropriate.


I was wondering the same thing and I learned that I can:

  1. define as a stream
  2. define as a repeated

as shown in below:

syntax = "proto3";

import "google/protobuf/empty.proto";

message Dummy {
  string foo = 1;
  string bar = 2;
}

message DummyList {
  repeated Dummy dummy = 1;
}

service DummyService {
  rpc getDummyListWithStream(google.protobuf.Empty) returns (stream Dummy) {}
  rpc getDummyListWithRepeated(google.protobuf.Empty) returns (DummyList) {}
}

so, which one?

In general, if your use case would allow the client to process the incoming messages one at a time, the stream is the better choice. If your client will just be blocking until all of the messages arrive and then processing them in aggregate, the repeated field may be appropriate, but even in this scenario the stream would work just as well, except for losing some potential compressibility.

referenceed from here: https://groups.google.com/forum/#!topic/grpc-io/F23vXwilTq0