I am wrapping a C library that has a struct with a void* data field that can be used to arbitrarily hold data. What would be the best way (if it's even possible) to wrap this in idiomatic Go?
The struct is quite simply:
typedef struct _Foo {
void * data;
} Foo;
I was hoping to do something like:
type Foo C.Foo
func (f *Foo) SetData(data interface{}) {
f.data = unsafe.Pointer(&data)
}
func (f *Foo) Data() interface{} {
return (interface{})(unsafe.Pointer(f.data))
}
This doesn't work, and is clearly the wrong approach anyways.
I have successfully set a void* data with a length field using a []byte source, but this length-less interface eludes me.