I am new to Google Protocol buffers and trying to model a primitive int[] array in java via a protobuf message.
Currently i am using this proto file:
syntax = "proto3";
package protobuf;
message primitiveArrayMsg {
repeated int32 data = 1;
}
Which compiles to a java class with an List<Integer> data structure instead of an array of primitive int.
/**
* <code>repeated int32 data = 1;</code>
*/
java.util.List<java.lang.Integer> getDataList();
My application must hold millions of int values and for saving memory I decided to use int instead of Integer.
Is there a way to compile a protobuf message description in a java class with an int[] data structure?
Unfortunately, I found nothing in the Protocol Buffers Language Guide (proto3). A similar question was also asked in How to add a int array in protobuf message, which I tried but obviously the question author was looking for an ArrayList<Integer> and therefore the answer did not help me.
If there is no support for that, can you recommend me a more memory efficient way than boxing to Integer and using List<Integer>?
getData(int)will give you back the unboxed value. It would be inefficient if it were storing the boxed value, unboxing the value to give it back to you, only for you to have to box it again. It's possible that thegetDataList()is merely a "boxing view" of anint[], but has to give you back aList<Integer>because that's all aListcan provide.