I´m trying to create some types that will be used with node-ffi, but I have some doubts about how to use Union and Struct type nested.
Should I define first the nested fields as new types, or can I does directly like this:
var ref = require('ref');
var Struct = require('ref-struct');
var Union = require('ref-union');
var ffi = require('ffi');
// typedefs
var int = ref.types.int;
var double = ref.types.double;
var long = ref.types.long;
var char = ref.types.char;
var string = ref.types.CString;
/*
struct px_val {
char isnull;
int type;
union {
long lval;
double dval;
struct {
char *val;
int len;
} str;
} value;
};
*/
var px_val = Struct({
isnull: char,
type: int,
value: Union({
lval: long,
dval: double,
str: Struct({
val: string,
len: int
})
})
});
I´m trying to create some types that will be used with node-ffi, but I have some doubts about how to use Union and Struct type nested. Should I define first the nested fields as new types, or can I does directly like this: