我正在尝试将类型为signed char * 的结构的成员转换为Java 中的字节数组。我有以下结构:
typedef struct {
signed char * content;
int contentLength;
} Foo;
我试过这个:
%typemap(jni) signed char *content [ANY] "jbyteArray"
%typemap(jtype) signed char *content [ANY] "byte[]"
%typemap(jstype) signed char *content [ANY] "byte[]"
%typemap(javaout) signed char *content [ANY] {
return $jnicall;
}
%typemap(memberin) int contentLength [ANY] {
int length=0;
$1 = &length;
}
%typemap(out) signed char * content [ANY] {
$result = JCALL1(NewByteArray, jenv, length);
JCALL4(SetByteArrayRegion, jenv, $result, 0, length, $1);
}
但是没有结果。Foo 的方法 getContent 具有以下签名:
SWIGTYPE_p_signed_char getContent();
我希望这个方法返回字节 []。有解决办法吗?