For example we have the following structure:
typedef struct Foo
{
unsigned char * data;
} Foo;
I want to set the data member with a Java byte array (byte[]). I only want set method not get. I've read the getting of a member of type char * to byte array, but I can't do the setting. Can anybody help me?
UPDATED:
I've created some type maps and I have a success:
%typemap(jni) unsigned char * data "jbyteArray"
%typemap(jtype) unsigned char * data "byte[]"
%typemap(jstype) unsigned char * data "byte[]"
%typemap(javaout) unsigned char * data {
return $jnicall;
}
%typemap(out) signed char * data {
$result = JCALL1(NewByteArray, jenv, arg1->contentLength);
JCALL4(SetByteArrayRegion, jenv, $result, 0, arg1->contentLength, $1);
}
%typemap(in) unsigned char *data {
$1 = (unsigned char *)JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(javain) unsigned char *data "$javainput"
Do I have some memory leaks? Have I made it wrong or is there more reliable way?
RelaseByteArrayElementsever. I think you probably want to do something usingmemcpyto copy the contents.