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.
We can declare a two-dimensional integer array say 'x' of size 10,20 as: int x[10][20]; Elements in two-dimensional arrays are commonly referred to by x[i][j] where i is the row number and 'j' is the column number.
Calculate the address of any element in the 2-D array: The 2-Dimensional arrays are organized as matrices which can be represented as the collection of rows and columns as array[M][N] where M is the number of rows and N is the number of columns.
Question: How two dimensional array is stroed in memory? Answer: Let a be a two dimensional m x n array. Though a is pictured as a rectangular pattern with m rows and n columns, it is represented in memory by a block of m*n sequential memory locations.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With