Skip to content
This repository was archived by the owner on Mar 3, 2022. It is now read-only.

Commit 0c4657d

Browse files
author
Zackery Field
authored
Merge pull request #2 from opendoor-labs/handle-recurse-on-variant
Recursively call store if src type is dbus.Variant
2 parents dc1f8d8 + 0a788db commit 0c4657d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

dbus.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ func setDest(dest, src reflect.Value) error {
8787
}
8888
if isVariant(src.Type()) && !isVariant(dest.Type()) {
8989
src = getVariantValue(src)
90+
// not quite ready to directly convert,
91+
// since we're dealing with a variant value
92+
// which may have a complex type
93+
return store(dest, src)
9094
}
95+
9196
if !src.Type().ConvertibleTo(dest.Type()) {
9297
return fmt.Errorf(
93-
"dbus.Store: type mismatch: cannot convert %s to %s",
98+
"dbus.Store: base type mismatch: cannot convert %s to %s",
9499
src.Type(), dest.Type())
95100
}
96101
dest.Set(src.Convert(dest.Type()))

store_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,26 @@ func TestStoreNested(t *testing.T) {
9797
dest, src)
9898
}
9999
}
100+
101+
type testStruct1 struct {
102+
V0 uint32
103+
V1 bool
104+
}
105+
106+
func TestStoreVariantStruct(t *testing.T) {
107+
src := MakeVariantWithSignature([]interface{}{1, true}, Signature{"(ub)"})
108+
dest := testStruct1{}
109+
err := Store([]interface{}{src}, &dest)
110+
if err != nil {
111+
t.Fatal(err)
112+
}
113+
if !reflect.DeepEqual(dest.V0, uint32(1)) {
114+
t.Errorf("not equal: got '%v', want '%v'",
115+
dest.V0, 1)
116+
}
117+
if !reflect.DeepEqual(dest.V1, true) {
118+
t.Errorf("not equal: got '%v', want '%v'",
119+
dest.V1, true)
120+
}
121+
122+
}

0 commit comments

Comments
 (0)