Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No examples of decoding into structures. #276

Open
james-lawrence opened this issue Oct 24, 2021 · 1 comment
Open

No examples of decoding into structures. #276

james-lawrence opened this issue Oct 24, 2021 · 1 comment

Comments

@james-lawrence
Copy link

I was expecting some decoding to structs functionality when dealing with dictionaries. am I just missing it?
right now I'm getting errors dbus.Store: type mismatch: map: cannot store a value of map[string]dbus.Variant into Foo
looking at the code looks like it doesn't handle anything but map, slices, interface{}, and primitives.

type Foo struct {
    V1 string `dbus:"value1"`
    V2 bool `dbus:"value2"`
}

dbus.Store(s.Body, &foo)
@guelfey
Copy link
Member

guelfey commented Jan 5, 2022

From the error, it looks like you're not actually receiving a struct, but a map of variants (which is a way to represent "dictionaries" in D-Bus). Structs are something different in the D-Bus model, namely an ordered sequence of typed, but unnamed values. So Go structs are mapped to this and vice versa. You can still use map[string]Variant, but there's no encoding/json-like "magic" for translating this into structs, since it's not that common in D-Bus - usually the schema is known and you can just use structs. Shouldn't be too hard to roll your own reflect-based helper, and I'd also accept a PR for something like this as long as it's only an additional step for converting these dicts to structs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants