如何使用swig定义和传递ByteBuffer?

use*_*129 3 c java java-native-interface swig

我需要从Java调用C函数.该函数具有以下API:

void convert(char* pchInput, int inputSize, int convertValue, char* pchOutput, int* outputSize);
Run Code Online (Sandbox Code Playgroud)

我正在使用swig来制作包装器.

我读了帖子: ByteBuffer.allocate()与ByteBuffer.allocateDirect()

最好将结果创建(pchOutput)DirectByteBuffer.

  1. 如何Bytebuffer将代码传递给代码c(使用swig)
  2. c代码如何从ByteBuffer读取和写入数据?

谢谢

V-m*_*ter 5

来自http://swig.10945.n7.nabble.com/Re-How-to-specify-access-to-a-java-nio-ByteBuffer-td6696.html的一些修改过的样本应该在小的变化之后起作用(特别是%typemap(in) (char* pchOutput, int* outputSize))因为我没有编译这个,只需运行swig来检查java端是否正确生成.

%typemap(in)        (char* pchInput, int inputSize) {
  $1 = JCALL1(GetDirectBufferAddress, jenv, $input); 
  $2 = (int)JCALL1(GetDirectBufferCapacity, jenv, $input); 
} 
%typemap(in)        (char* pchOutput, int* outputSize) {
  $1 = JCALL1(GetDirectBufferAddress, jenv, $input); 
  $2 = &((int)JCALL1(GetDirectBufferCapacity, jenv, $input)); 
} 

/* These 3 typemaps tell SWIG what JNI and Java types to use */ 
%typemap(jni)       (char* pchInput, int inputSize), (char* pchOutput, int* outputSize) "jobject" 
%typemap(jtype)     (char* pchInput, int inputSize), (char* pchOutput, int* outputSize) "java.nio.ByteBuffer" 
%typemap(jstype)    (char* pchInput, int inputSize), (char* pchOutput, int* outputSize) "java.nio.ByteBuffer" 
%typemap(javain)    (char* pchInput, int inputSize), (char* pchOutput, int* outputSize) "$javainput" 
%typemap(javaout)   (char* pchInput, int inputSize), (char* pchOutput, int* outputSize) { 
    return $jnicall; 
} 
Run Code Online (Sandbox Code Playgroud)