I have a really big problem here. I try to transfer byte [] from Java to C ++, and after conversion I get negative values. I identified a problem with unique characters in the Java [] byte, which after conversion and logging are either 0 or negative.
I tried using test byte [] for string characters, and it works fine.
Here is my code if it helps.
Java
public static native void SendMessage(byte[] message, int size);
C ++
static void SendMessage(JNIEnv *env, jclass cls, jbyteArray array, jint array_length)
{
jbyte* content_array = (env)->GetByteArrayElements(array,NULL);
LOGD("content:\n");
for (int i=0; i < array_length; i++)
{
LOGD("%d",content_array[i]);
}
SendMessage(client, (uint8_t*)content_array, array_length);
(env)->ReleaseByteArrayElements(array,content_array,0);
}
Output
content: 48
content: 23
content: 13
content: 56
content: 0 // <--- the problem starts here
content: -122
content: 0
content: 78
content: 32
content: -28
etc...
..
..
Now, using a simple test byte [] Java
String test = "ABC";
byte[] message = test.getBytes();
public static native void SendMessage(byte[] message, int size);
C ++
static void SendMessage(JNIEnv *env, jclass cls, jbyteArray array, jint array_length)
{
jbyte* content_array = (env)->GetByteArrayElements(array,NULL);
LOGD("content:\n");
for (int i=0; i < array_length; i++)
{
LOGD("%d",content_array[i]);
}
(env)->ReleaseByteArrayElements(array,content_array,0);
}
Output
content: 65 //this works perfectly
content: 66
content: 67
Thank you for your help. Very much appreciated.