Given I have a C structure as below. I am able to read the data union values using unsafe pointers but am unable to work out how I can set the union value data?
typedef struct val {
char *var1;
type type;
union {
char *binary_val;
char *bits_val;
bool bool_val;
double decimal64_val;
char *enum_val;
char *identityref_val;
char *instanceid_val;
int8_t int8_val;
int16_t int16_val;
int32_t int32_val;
int64_t int64_val;
char *string_val;
uint8_t uint8_val;
uint16_t uint16_val;
uint32_t uint32_val;
uint64_t uint64_val;
} data;
} val_t;
Is there a way without creating helper methods in C? An example of setting string_val would be perfect? I am aware that Go represents a union as a byte array with the longest type setting the length of the byte array.