How can I represent a 2-dimensional array in Proto

2019-06-15 20:35发布

问题:

How can I represent a 2-dimensional array in Protocol Buffers?

I need to store int and double 2d arrays as a field on a PB message, for example:

int[][] multi = new int[5][10];

I'm using C++, Java and C#.

Thanks in advance.

回答1:

There is no direct support in the protocol for this. Your best bet is to have a repeated set of objects that have an array each - i.e.

message Foo {
    repeated int items = 1;
}
...
repeated Foo foos = 1;