Swig:将Java中的字节数组传递到C

4
我正在尝试使用Swig创建Java实现,以便将byte []传递给C。
Swig:
%include "typemaps.i"
%apply(char *STRING, int LENGTH) { (char *buff, int len) }; 
%inline {
   typedef struct {
        char*         buff;        
        int           len;  
  } workit_t;
}

在我的生成的Java类(workit_t.java)中,参数buff是一个字符串,而不是一个byte[]。
public void setBuff(String value){
 ... 
}

我在我的swig定义中做错了什么?
当我写一个没有结构体的简单swig定义时,我得到了期望的参数类型。
Swig:
%include "typemaps.i"
%apply(char *STRING, int LENGTH) { (char *buff1, int *len1) };

Java:
public static void Mathit(byte[] buff1, byte[] buff2) {
...
}
1个回答

3

Well, I have been able to get it right.

Before:

%include "typemaps.i"
%apply(char *STRING, int LENGTH) { (char *buff, int len) }; 
%inline {
   typedef struct {
        char*         buff;        
        int           len;  
  } workit_t;
}

现在:

%include various.i                    
%apply char *BYTE { char *buff };  //map a Java byte[] array to a C char array
%inline {
   typedef struct {
        char*         buff;        
        int           len;  
   } workit_t;
}

或者:

%include various.i                    
%apply char *NIOBUFFER { char *buff }; //map Java nio buffers to C char array
%inline {
   typedef struct {
        char*         buff;        
        int           len;  
   } workit_t;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接