I have an USB device with firmware written in C language. This device will exchange data structures with Android app written in Java. Now the structures are declared in C. What is the best way to handle them in Java.
Currently, I have this in C:
// In report - data from USB device to Java
typedef struct {
uint8 Cmd;
union {
TSomeStruct Something;
uint32 Value;
};
} __packed TInReport;
// Out report - data from Java to USB device
typedef struct {
uint8 Cmd;
union {
int32 Status;
uint16 Id;
};
} __packed TOutReport;
I can rewrite these declaration in Java. Then, is there a simple way Java can decode received bytes to its native object and encode its native object to bytes (with correctly aligned members)?