Java Strings via SWIG in Android NDK have strange characters in place of null bytes -


I am using SWIG to generate the interface to a CD which I have compiled as an Android NDK library . My C code NDK library uses a structure, MY_STRUCT consists of four * elements that pass data in these two directions and the SWIG generated JNI works properly, i.e. I can read the wire in the C code Required and reads results in Java code.

However, I have a problem in it that if I pass the null bytes in the Java string then "\ 300 \ 200"

Example, if I make a string in Java as follows I:

  MY_STRUCT myStruct = new MY_STRUCT (); Byte [] myBytes = new byte [21]; String Maestring = New String (Maybits); MyStruct.setName (myString);   

Then the field named after myStruct is set to 21 faucet bytes, and it is visible in Java debugger, but string as shown in the NDK C debugger The NDK has passed the library code as follows:

  "300 300 200 200 200 200 200 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 \ 300 \ 200 "  

My SWIG .i file contains the following relevant parts :

 % contains different. I% cpointer.i% pointer_functions (int, intp); % Include ../../../mydir/myheader.h   

The following relevant portion is in myheader.h:

  typedef struct {. Four names; ...} * P_MY_STRUCT, MY_STRUCT;   

C code debugs fine and I can read and write all the strings indicated by elements such as MY_STRUCT, only one issue is the change of empty elements of string input SWIG JNI code NDK In the library there was a strange "\ 300 \ 200" element in the C code.

Edit:

Considering an option: I have several functions that arrays for a byte c-function instead of a string * and it is in myModule.i file Received as follows:

  bool myFunc (P_MY_STRUCT, char * BYTE, int32_t);   

Is there any way of SWIG to achieve the equivalent of BYTE functionality for members of the structure? I tried to use the same BYTE trick in myModule.i, but it does not work:

  typedef struct {... char * BYTE; ...} * P_MY_STRUCT, MY_STRUCT;   

Thanks again,

This is known by java as crazy behavior And is answered in response to this question:



Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -