Reputation: 1537
I need to call the native function int getSize(uint_64& out)
through JNI. There are obviously a few problems here that I intend to solve by passing byte[]
to the JNI code, populating it with the value of uint64_t &out
, and then creating a BigInteger out of the result. So, from Java I call getSize(byte[] size)
, in JNI C code I pass a new uint64_t to getSize(uint64_t& out)
and then copy the value from it back to the byte array, and finally I create a BigInteger out of this byte array. My question is how do I copy the uint64_t
value into the byte array? I know that on the Java side the value has to be in big-endian order but how do I figure out what the byte order is of the uint64_t
?
Upvotes: 0
Views: 1010
Reputation: 310869
The byte order of the uint64_t
is the native byte order, of course, but you don't need to deal with endianness-ness at all here. Just return a jlong
from your native method. It will arrive in big-endian order in the Java code, where the Java code can deal with it any way you like.
Upvotes: 3