I'm trying to map a c struct to a Java class. Everything works fine so far but I don't know how to map a struct which has another struct as a member.
In the Struct class javadoc there is an example of a struct containing a pointer to the same struct (using the class Reference32) but it is not what I need.
I can't find further documentation about how to achieve this.
This is a simplified example:
// c types --------------------------------
enum Enum16{VALUE1, VALUE2, VALUE3};
struct t_composite {
int number;
char text[20];
};
struct t_demo {
char _char2[2];
char _char14[14];
int _int;
float _float;
double _double;
enum Enum16 enum16;
struct t_composite _otherStruct;
};
// Java class -------------------------
public class Composite extends Struct {
public final Signed32 number = new Signed32();
public final UTF8String text = new UTF8String(20);
// ...
}
public class Demo extends Struct {
public enum EnumValues {
VALUE1, VALUE2, VALUE3
};
public final UTF8String _char2 = new UTF8String(2);
public final UTF8String _char15 = new UTF8String(14);
public final Signed32 _int = new Signed32();
public final Float32 _float = new Float32();
public final Float64 _double = new Float64();
public final Enum32<EnumValues> _enum32 = new Enum32<EnumValues>(EnumValues.values());
// public final Reference32<Composite> _otherStruct = new Reference32<Composite>(); // incorrect
public final Composite _otherStruct = new Composite(); // doesn't work
// ....
}
Variable "_otherStruct" is never filled in Java. I've tried defining the java variable as a Composite class instead of Reference32 but it didn't do the trick.
How is the right way of doing this?
Thank you in advance
UPDATE
As the main developer Jean-Marie Dautelle pointed to me, this is fully supported through the use of the inner method:
public final Composite _otherStruct = inner(new Composite());
That works perfectly