i want wrap struct containing fixed size array of unsigned char byte[] in java. interface file looks this:
%module example %include "arrays_java.i" struct mystruct { unsigned char data[1024]; int len; };
the java proxies created contain , set methods take , return short[].
is there way , if yes, easiest way can force swig generate java proxies using byte[] instead of short[]?
i don't want change struct in way. simplified example of large interface have wrap cannot change.
i aware of fact byte in java signed , doesn't cover range of unsigned char in c, passing data around more convenient dealing short[] or wrapper created using array_class defined in carrays.i offers getitem , setitem methods in turn take or return short.
so question if can force swig somehow (maybe typemap) treat unsigned char data[1024] char[1024] in maps byte[] in java.
we can force swig treat unsigned char arrays signed char arrays purpose of swig wrapping using %apply
. example using:
%module example %include "arrays_java.i" %apply signed char[any] { unsigned char[any] }; struct mystruct { unsigned char data[1024]; int len; };
will force happen unsigned char
arrays of (known) size. (think of %apply
typemap copy , paste)
you write:
%apply signed char[any] { unsigned char data[any] };
or:
%apply signed char[any] { unsigned char data[1024] };
which apply arrays of type unsigned char
of size, or size 1024 respectively.
as handy tip: figured out typemaps wanted match on %apply
calling swig '-debug-tmsearch' flag showed originally:
.... test.i:8: searching suitable 'jni' typemap for: unsigned char data[1024] looking for: unsigned char data[1024] looking for: unsigned char [1024] looking for: unsigned char data[any] looking for: unsigned char [any] using: %typemap(jni) unsigned char [any] ....
which shows typemaps apply in order of precedence every typemap used interface.
Comments
Post a Comment