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 %array_class
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.
My problem is that I also use wrap the unsigned char *
using: %apply char * { unsigned char * };
so that I get an array of Strings on the Java side. I don't want to wrap the unsigned char *
return value (using %apply char * { unsigned char * };
) 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 unsigned char *
(see getValueFromRowAsByteArray
)
C Functions:
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.
SWIG Interface File for Wrapping C Function Returning unsigned char * (array of char):
%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"