Multi-dimensional arrays are usually defined in terms of both their dimensions (i.e. "width" and "height") and their contents (the entire list of individual items which should be broken up into constituent "rows" or "columns"). However, if the constituent arrays might have different lengths then you may need another approach entirely.
Your task is to decide how you want to serialize this data so that your client can deserialize it and to emphasize any critical aspects of this transmission (e.g. data size, performance, ease of interoperability, etc).
Here are some possible solutions:
Matrix dimensions and contents. If your data will always have a consistent "width" and "height" then you could use a raw encoding to serialize two
uint16s (or other appropriate size) representing those values and then a sequence of the raw bytes. To deserialize, the client would just need to read two integers to know the dimensions of the matrix and could then populate the rest of the data accordingly. An example message might look like this (as hexadecimal bytes):
0002 0002 6869 6869
Length and contents. If each sub-array could have a different length then you could simply raw encode a sequence of tuples of "length" (e.g. as
uint32) and raw byte contents, e.g. (as hexadecimal bytes):
0000 0002 6869 0000 0002 6869
JSON and Base64. If interoperability and ease of integration are more important (and large data sizes are not a major concern) then you could simply serialize your data as a JSON array of strings, each of which is a Base64 encoded byte array. This way, the client need only deserialize the JSON array and Base64 decode each element. This solution also easily allows for varying size sub-arrays. An example message might look like this (as a JSON string):
Ultimately, go has many builtin
encoding packages that you can use to serialize this data. There is no single "right" answer, so your implementation choice should be driven by your business needs.