Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 740
CodingHero Avatar asked Jan 07 '14 09:01

CodingHero


People also ask

How are two-dimensional arrays represented?

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.

How do you represent a two dimensional array is represented in memory How do I find the address of an element?

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.

How 2D array is represented in memory explain with a suitable example?

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.


1 Answers

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;
like image 150
Marc Gravell Avatar answered Sep 19 '22 15:09

Marc Gravell