guelfey / go.dbus

Native Go bindings for D-Bus
BSD 2-Clause "Simplified" License
124 stars 42 forks source link

Enabling the support of interface{} in type signature #26

Closed acasas closed 11 years ago

acasas commented 11 years ago

There are some types, such as com.ubuntu.Upstart0_6.Instance.processes (http://upstart.ubuntu.com/wiki/DBusInterface) that don't have a direct mapping and are considered as interface{} by the library. This fix allows to consider those as string, to be able to access the data in it. Current behavior is panicking with an InvalidTypeError.

guelfey commented 11 years ago

No.

The type you mentioned contains a D-Bus struct. While Go has a notion of structs, it is not possible to provide a seamless conversion between Go structs and D-Bus structs. D-Bus structs are more like tuples in other languages, so Go structs can easily be represented as D-Bus structs, but it's not possible to take a D-Bus struct and return it as a Go struct as you basically would have to create a struct type at runtime. It is, however, possible, to take a pointer to a Go struct and try to save a D-Bus struct in it.

Because of this, the library represents incoming structs as slices of (empty) interfaces. If you want to access them as Go structs, you have the Store function on package level or the method of (*Object) of the same name. Thus, you can interact with D-Bus structs without having to support encoding of interface{}