协议缓冲区-存储1D,2D和3D双数组 [英] protocol buffers - store an double array, 1D, 2D and 3D

查看:85
本文介绍了协议缓冲区-存储1D,2D和3D双数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用协议缓冲区存储双精度(1D)数组? 多维(2D或3D)密集阵列又如何呢?

How can be an array of double (1D) stored using protocol buffer? What about multi-dimensional (2D or 3D) dense arrays?

推荐答案

最好通过以下方式存储double数组:

An array of double would be best stored via

repeated double foo = 5 [packed=true];

repeated使其充当列表,允许多个项目; packed避免每个项目都有标题.

repeated makes it act as a list, allowing multiple items; packed avoids a header per item.

protobuf中不直接支持矩形(或更高版本)的数组.最接近的是存储类似的内容:

There is no direct support for rectangular (or higher) arrays in protobuf. The closest is to store something like:

repeated innerType foo = 5; // note, can't be "packed"

message innerType {
    repeated double foo = 1 [packed=true];
}

这大致类似于锯齿状的数组,但是每个层之间都有一个元素.

this is broadly akin to a jagged array, but with an element between each tier.

这篇关于协议缓冲区-存储1D,2D和3D双数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆