使用protobuf网,如何(德)序列化一个多维数组?多维、数组、序列化、protobuf

2023-09-03 01:00:19 作者:我向来孤僻却念你好深

由于protobuf网不支持串行化/反序列化的多维数组,我将如何去管理我的阵列?

Since ProtoBuf-Net does not support serializing/deserializing multi-dimensional arrays, how would I go about managing my arrays?

推荐答案

这是本质上是底层的protobuf传输格式的限制;它只支持单维数组。

This is essentially a limitation of the underlying protobuf wire format; it only supports single-dimension arrays.

两个选项飞跃头脑;首先,发送它作为一个线性阵列,并分别发送的尺寸。

Two options leap to mind; firstly, send it as a linear array, and send the dimensions separately.

您也可以重新present它作为对象的列表,每个已的阵列 - 基本上交错数组,但与中间步骤

You could also represent it as a list of objects that each has an array - essentially a jagged array, but with an intermediate step.

在这两个,第一是既简单,更有效。

Of the two, the first is both simpler and more efficient.

无论哪种方式,如果您要发送类似intergers,你应该看看压缩编码(可通过选项属性) - 这可以进一步减少有效载荷阵列等

Either way, if you are sending something like intergers, you should look at "packed" encoding (available via the options property) - this can further reduce the payload for arrays etc.