How to define and pass ByteBuffer using swig?(如何使用 swig 定义和传递 ByteBuffer?)
问题描述
我需要从 Java 调用 C 函数.该函数有以下API:
I need to call to C function from Java. The function has the following API:
void convert(char* pchInput, int inputSize, int convertValue, char* pchOutput, int* outputSize);
我正在使用 swig 来制作包装器.
I'm using swig in order to make the wrappers.
我读了这篇文章:ByteBuffer.allocate() 与 ByteBuffer.allocateDirect()
最好将结果 (pchOutput) 创建为 DirectByteBuffer.
And it seems best to create the result (pchOutput) as DirectByteBuffer.
- 如何将
Bytebuffer传递给代码 c(使用 swig) - c 代码如何从 ByteBuffer 读取和写入数据?
- How can I pass the
Bytebufferto the code c (using swig) - How the c code will read and write the data from the ByteBuffer ?
谢谢
推荐答案
来自 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 端是否正确生成.
a little modified sample from http://swig.10945.n7.nabble.com/Re-How-to-specify-access-to-a-java-nio-ByteBuffer-td6696.html that should work after small changes (especially %typemap(in) (char* pchOutput, int* outputSize)) as I did not compiled this, just run swig to check if java side is properly generated.
%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;
}
这篇关于如何使用 swig 定义和传递 ByteBuffer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 swig 定义和传递 ByteBuffer?
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
