如何在protobuf消息中添加一个int数组 [英] How to add a int array in protobuf message
本文介绍了如何在protobuf消息中添加一个int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须编写一个 protobuf 消息,它应该有 1 个整数变量和一个整数数组.
I have to compose a protobuf message which should have 1 integer variables and a integer array.
package protobuf;
message myProto {
optional uint32 message_id =1;
optional int update = 2;
//here I have to add a array of integers
//can I write like optional int[] array =3;
//or should I use optional repeated array;
//where array is another message with int variable
}
我的方法正确吗?请帮帮我
Is my approach correct? Please help me
谢谢
推荐答案
数组通过重复"映射:
repeated int32 data = 4;
请注意,您可能需要 sint32/uint32.还要注意,三种情况都可以使用打包数组",效率更高;
Note you might want sint32/uint32. Also note that in all three cases "packed arrays" can be used, which are more efficient;
repeated int32 data = 4 [packed=true];
这篇关于如何在protobuf消息中添加一个int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文