SWIG converts the below unsigned char array (“id”) to short[]. On the C side, the id attribute of the sender_id_t_ struct is a pointer to an array that contains alphanumeric data like “TEST123-E”. I suppose you could loop over short[] (sender_id_t_.getId()) and cast each element to a char and concatenate to build a Java String. I’m wondering if their is a better and simpler way of handling this situation?
C Header File:
#define SAMPLE_ID_SIZE_V1 32
#define SAMPLE_ID_SIZE SAMPLE_ID_SIZE_V1
typedef unsigned char sample_id_v1_t[SAMPLE_ID_SIZE];
typedef sample_id_v1_t sample_id_t;
struct sample_sender_id_t_ {
sample_id_t id;
uint32_t idx;
};
typedef struct sample_sender_id_t_ sample_sender_id_t;
SWIG.i:
%rename (Sample) sender_id_t_;
struct sender_id_t_ {
unsigned char id_v1_t[32] id;
uint32_t phy_idx;
};
Exception:
[exec] test_wrap.c: In function `TestJNI_Sample_1id_1set':
[exec] test_wrap.c:826: error: cast specifies array type
[exec] test_wrap.c:829: error: incompatible types in assignment
[exec] test_wrap.c:832: error: `jarr2' undeclared (first use in this function)
It gets treated as an array of
shortbecause of theunsignedof the type, which makes the largest value too large to fit in a (signed)byteorchar. If you want to force it to be treated aStringyou can use%applyto use the normalStringtypemaps, something like:(I had to fix some syntax in your
struct, that was a bit odd).