SWIG c++ -> java 转换byte[] 的关键代码
来源:互联网 发布:windows快速打开程序 编辑:程序博客网 时间:2024/06/03 17:02
/*
* char *BYTE typemaps.
* These are input typemaps for mapping a Java byte[] array to a C char array.
* Note that as a Java array is used and thus passeed by reference, the C routine
* can return data to Java via the parameter.
*
* Example usage wrapping:
* void foo(char *array);
*
* Java usage:
* byte b[] = new byte[20];
* modulename.foo(b);
*/
%typemap(jni) char *BYTE "jbyteArray"
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) char *BYTE ""
/*
* unsigned char *NIOBUFFER typemaps.
* This is for mapping Java nio buffers to C char arrays.
* It is useful for performance critical code as it reduces the memory copy an marshaling overhead.
* Note: The Java buffer has to be allocated with allocateDirect.
*
* Example usage wrapping:
* %apply unsigned char *NIOBUFFER { unsigned char *buf };
* void foo(unsigned char *buf);
*
* Java usage:
* java.nio.ByteBuffer b = ByteBuffer.allocateDirect(20);
* modulename.foo(b);
*/
%typemap(jni) unsigned char *NIOBUFFER "jobject"
%typemap(jtype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
%typemap(jstype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
%typemap(javain,
pre=" assert $javainput.isDirect() : \"Buffer must be allocated direct.\";") unsigned char *NIOBUFFER "$javainput"
%typemap(javaout) unsigned char *NIOBUFFER {
return $jnicall;
}
%typemap(in) unsigned char *NIOBUFFER {
$1 = (unsigned char *) JCALL1(GetDirectBufferAddress, jenv, $input);
if ($1 == NULL) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unable to get address of a java.nio.ByteBuffer direct byte buffer. Buffer must be a direct buffer and not a non-direct buffer.");
}
}
%typemap(memberin) unsigned char *NIOBUFFER {
if ($input) {
$1 = $input;
} else {
$1 = 0;
}
}
%typemap(freearg) unsigned char *NIOBUFFER ""
%apply char *BYTE { char *buf };
%apply char *BYTE { char *data };
%apply unsigned char *NIOBUFFER { unsigned char *data};
* char *BYTE typemaps.
* These are input typemaps for mapping a Java byte[] array to a C char array.
* Note that as a Java array is used and thus passeed by reference, the C routine
* can return data to Java via the parameter.
*
* Example usage wrapping:
* void foo(char *array);
*
* Java usage:
* byte b[] = new byte[20];
* modulename.foo(b);
*/
%typemap(jni) char *BYTE "jbyteArray"
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) char *BYTE ""
/*
* unsigned char *NIOBUFFER typemaps.
* This is for mapping Java nio buffers to C char arrays.
* It is useful for performance critical code as it reduces the memory copy an marshaling overhead.
* Note: The Java buffer has to be allocated with allocateDirect.
*
* Example usage wrapping:
* %apply unsigned char *NIOBUFFER { unsigned char *buf };
* void foo(unsigned char *buf);
*
* Java usage:
* java.nio.ByteBuffer b = ByteBuffer.allocateDirect(20);
* modulename.foo(b);
*/
%typemap(jni) unsigned char *NIOBUFFER "jobject"
%typemap(jtype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
%typemap(jstype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
%typemap(javain,
pre=" assert $javainput.isDirect() : \"Buffer must be allocated direct.\";") unsigned char *NIOBUFFER "$javainput"
%typemap(javaout) unsigned char *NIOBUFFER {
return $jnicall;
}
%typemap(in) unsigned char *NIOBUFFER {
$1 = (unsigned char *) JCALL1(GetDirectBufferAddress, jenv, $input);
if ($1 == NULL) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unable to get address of a java.nio.ByteBuffer direct byte buffer. Buffer must be a direct buffer and not a non-direct buffer.");
}
}
%typemap(memberin) unsigned char *NIOBUFFER {
if ($input) {
$1 = $input;
} else {
$1 = 0;
}
}
%typemap(freearg) unsigned char *NIOBUFFER ""
%apply char *BYTE { char *buf };
%apply char *BYTE { char *data };
%apply unsigned char *NIOBUFFER { unsigned char *data};
阅读全文
0 0
- SWIG c++ -> java 转换byte[] 的关键代码
- java/android 使用swig编译c/c++ 代码类型转换
- 用Swig将c/c++程序转为java代码(使用swig实现java调用c、c++的方法)
- SWIG封装C代码
- java byte转换代码块
- 利用 SWIG 转换 C/C++ 接口到 Java 接口
- Swig编译C代码供java调用实例
- java中byte(byte []), int的转换
- 我使用过的Linux命令之swig - 把C/C++的代码嵌入Java等语言的开发工具
- string和byte[]的转换 (C#)
- string和byte[]的转换 (C#)
- (C#) string和byte[]的转换
- string和byte[]的转换 (C#)
- string和byte[]的转换 (C#)
- string和byte[]的转换 (C#)
- (转) string和byte[]的转换 (C#)
- string和byte[]的转换 (C#)
- string和byte[]的转换 (C#)
- POJ 2031.Building a Space Station
- 解决centos6上python升级混乱导致yum报错 -bash: /usr/bin/yum: /usr/bin/python
- 几大内部排序算法
- SparkSQL根据条件合并多条数据(测试)
- centos6.5-oracle_11R安装
- SWIG c++ -> java 转换byte[] 的关键代码
- Java练习题24 猜数字
- ASP 数据库,连接数据库,连接池
- quartus ii 的研究报告
- 解決 java.security.cert.CertificateException: Certificates does not conform to algorithm constraints
- JavaScript学习-封装基础库1
- 【MyBatis】关于模糊查询的两种处理方法
- 2017年12月12日
- 理解设计模式之命令模式