使用ProtoBuf-Net,如何对多维数组进行(反)序列化?
由于 ProtoBuf-Net 不支持序列化/反序列化多维数组,我将如何管理我的数组?
Since ProtoBuf-Net does not support serializing/deserializing multi-dimensional arrays, how would I go about managing my arrays?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这本质上是底层 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.
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.
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.