문제

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.

도움이 되었습니까?

해결책

I was able to solve this problem by changing my template to the following which is a solution I found at http://swig.10945.n7.nabble.com/Converting-char-to-byte-String-in-Java-td276.html

// knows about things like int *OUTPUT:
%include "typemaps.i"
// knows about int32_t
%include "stdint.i"
%include "arrays_java.i"
%apply int[] {int *};

// convert char * to byte array
%apply signed char[] {char* pchar}; 

%include "wchar.i"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top