我必须编写一个 protobuf 消息,它应该有 1 个整数变量和一个整数数组。
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
}
我的方法正确吗?
最佳答案
数组是通过“重复”映射的:
repeated int32 data = 4;
请注意,您可能需要 sint32/uint32。另请注意,在所有三种情况下都可以使用“打包数组”,这样效率更高;
repeated int32 data = 4 [packed=true];
关于java - 如何在 protobuf 消息中添加一个 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7408203/