I have created the following helper function but I am unable to get it to generate a java interface that accepts a byte array as the input.
size_t get_p_wchar_t_bytes(wchar_t *wstr, char * bytes, size_t len)
{
size_t wlen,cpylen;
wlen = count_p_wchar_t_bytes(wstr);
cpylen = len > wlen ? wlen : len;
memcpy(bytes, wstr, cpylen);
return cpylen;
}
size_t count_p_wchar_t_bytes(wchar_t *wstr)
{
return wcslen(wstr) * sizeof(wchar_t);
}
I have the following defined in my template
%include "arrays_java.i"
%apply int[] {int *};
%include "wchar.i"
The problem with this is that the char * is being converted to a "String" instead of a byte array which isn't helpful.
public static long get_p_wchar_t_bytes(SWIGTYPE_p_wchar_t wstr, String bytes, long len)
What I want as the output from swig is this...
public static long get_p_wchar_t_bytes(SWIGTYPE_p_wchar_t wstr, byte[] bytes, long len)
So how can I do this? Ultimately I simply need a way to pass a w_char_t array to java in a format it can work with without creating any memory leaks.