Protocol buffers in Java: can we efficiently handle primitive arrays?

I work with messages that contain several attributes and an array of thousands of floating point values ​​(double []). When messages are serialized with protocol buffers, thanks to the "packed = true" directive, double values ​​are aligned and stored compactly in messages.

But by default, the Java classes generated for this post are a double array as a list of arrays (!), Primitive double box values ​​into objects scattering those objects in memory, while in the end I need a double [] representation for further aggregations ...

Is it possible to generate classes that handle repeating primitive values ​​as primitive Java arrays?

+5
source share
2 answers

After discussing this topic in several places, the answer will not be clear.

With protocol buffers, an effective binary representation for number vectors. But at the moment, the Java implementation does not allow you to effectively deserialize these vectors (instead of primitive arrays you get boxed number collections ...)

0
source

As explained here , you need versions of ArrayList that store unboxed values. Since java generics only works with objects (boxed), an implementation must be needed for each primitive type. This way you can use the one provided by Apache Commons primitives.

0
source

Source: https://habr.com/ru/post/1241840/


All Articles