3
我看遍了所有的地方。我曾嘗試過這個網站的一些技巧。無濟於事。SWIG無符號字符和字節[]
我有一個C++全局函數
char* squid(char* buff, int len);
我創建了一個.i文件
%module Crabby
%include "arrays_java.i"
%{
/* headers here are included in the wrapper code */
#include "sponge.h"
%}
%typemap(jtype) (const signed char *arr, size_t sz) "byte[]"
%typemap(jstype) (const signed char *arr, size_t sz) "byte[]"
%typemap(jni) (const signed char *arr, size_t sz) "jbyteArray"
%typemap(javain) (const signed char *arr, size_t sz) "$javainput"
%typemap(in) (const signed char* arr, size_t sz) {
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
const size_t sz = JCALL1(GetArrayLength, jenv, $input);
$2 = $1 + sz;
}
%typemap(freearg) (const signed char *arr, size_t sz) {
// Or use 0 instead of ABORT to keep changes if it was a copy
JCALL3(ReleaseByteArrayElements, jenv, $input, $1, JNI_ABORT);
}
%apply (const signed char* arr, size_t sz) { (const unsigned char* buff, int len) }
%apply (const signed char* arr, size_t sz) { (const unsigned char* query, int queryLen) }
%include "sponge.h"
不管我做什麼的界面總是
public static String Squid(String buff, int len)
如果刪除無符號的我在cxx包裝中得到非法轉換
這是痛飲2.0.1
有沒有辦法解決函數簽名,這樣只需要一個字符串? – soandos
@soandos是的,但問題在於如何將字符串映射到'char *',因爲'jchar'與字符不同。你想要的字節數作爲長度,或字符的數量? – Flexo
字節數 – soandos