Note that there are some explanatory texts on larger screens.

plurals
  1. POwrapping byte array data with SWIG array_class
    primarykey
    data
    text
    <p>I have a C function that returns an unsigned char * that can either be a pointer to a byte array (binary data representing a File..etc) or a pointer to an array of characters. I'm currently using the SWIG <code>%array_class</code> that wraps all C functions that return an unsigned char pointer and creates a Java array utility (SampleArrayUtil.java) to handle the population and retrieval on the Java side. </p> <p>My problem is that I also use wrap the <code>unsigned char *</code> using: <code>%apply char * { unsigned char * };</code> so that I get an array of Strings on the Java side. I don't want to wrap the <code>unsigned char *</code> return value (using <code>%apply char * { unsigned char * };</code>) when I get binary data back, I want to just have the byte array on the Java side. I was thinking of creating another C function to handle the binary data, but I'm unsure how to wrap this new function as it will also return an <code>unsigned char *</code> (see <code>getValueFromRowAsByteArray</code>)</p> <p><strong>C Functions:</strong></p> <pre><code>unsigned char * getValueFromRowAsStringArray(struct result_row *row, attribute_type type, int32_t *len) unsigned char * getValueFromRowAsByteArray(struct result_row *row, attribute_type type, int32_t *len) //*row* input param with data results, *type* input enum type for the data type being requested and *len* is an output param that contains the length of the data being returned. </code></pre> <p><strong>SWIG Interface File for Wrapping C Function Returning unsigned char * (array of char):</strong></p> <pre><code>%module Sample %include "typemaps.i" %include "stdint.i" %include "arrays_java.i" %include "carrays.i" %array_class(unsigned char, SampleArrayUtil); %{ #include "C_API.h" %} %apply char * { unsigned char * }; %include "C_API.h" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload