#ifndef JNATEST_LIBRARY_H
#define JNATEST_LIBRARY_H
#pragma pack(1)
struct JNATest {
char user[32];
char password[32];
struct Station {
long long status;
char smsCommand[64]; // UTF-16BE
} station;
};
#endif
import com.sun.jna.Structure;
import java.util.Arrays;
import java.util.List;
public class JNATest extends Structure {
/**
* C type : char[32]
*/
public byte[] user = new byte[32];
/**
* C type : char[32]
*/
public byte[] password = new byte[32];
/**
* C type : Station
*/
public Station station;
/**
* <i>native declaration : line 14</i>
*/
public static class Station extends Structure {
public long status;
/**
* UTF-16BE<br>
* C type : char[64]
*/
public byte[] smsCommand = new byte[64];
public Station() {
super(ALIGN_NONE, JNATestMain.tm);
}
protected List<String> getFieldOrder() {
return Arrays.asList("status", "smsCommand");
}
public static class ByReference extends Station implements Structure.ByReference {
}
public static class ByValue extends Station implements Structure.ByValue {
}
}
public JNATest() {
super(ALIGN_NONE, JNATestMain.tm);
}
protected List<String> getFieldOrder() {
return Arrays.asList("user", "password", "station");
}
public static class ByReference extends JNATest implements Structure.ByReference {
}
public static class ByValue extends JNATest implements Structure.ByValue {
}
}
My question is to make user field a String which is originally in C represented by char user[32] by using TypeMapper.
TypeMapper is necessary for specifying encoding for java String (probably by using custom Java annotation detected
by TypeMapper on structure field user).
JNATestMain.tm is such TypeMapper by please provide me a TypeMapper to make such conversion from and to native
C struct. FromNative must extract 32 bytes of structure to Java String and ToNative will convert existing String
to char user[32] bytes.