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

Commit

Permalink
Merge pull request #2 from opendoor-labs/handle-recurse-on-variant
Browse files Browse the repository at this point in the history
Recursively call store if src type is dbus.Variant
  • Loading branch information
Zackery Field authored Oct 15, 2019
2 parents dc1f8d8 + 0a788db commit 0c4657d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ func setDest(dest, src reflect.Value) error {
}
if isVariant(src.Type()) && !isVariant(dest.Type()) {
src = getVariantValue(src)
// not quite ready to directly convert,
// since we're dealing with a variant value
// which may have a complex type
return store(dest, src)
}

if !src.Type().ConvertibleTo(dest.Type()) {
return fmt.Errorf(
"dbus.Store: type mismatch: cannot convert %s to %s",
"dbus.Store: base type mismatch: cannot convert %s to %s",
src.Type(), dest.Type())
}
dest.Set(src.Convert(dest.Type()))
Expand Down
23 changes: 23 additions & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,26 @@ func TestStoreNested(t *testing.T) {
dest, src)
}
}

type testStruct1 struct {
V0 uint32
V1 bool
}

func TestStoreVariantStruct(t *testing.T) {
src := MakeVariantWithSignature([]interface{}{1, true}, Signature{"(ub)"})
dest := testStruct1{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(dest.V0, uint32(1)) {
t.Errorf("not equal: got '%v', want '%v'",
dest.V0, 1)
}
if !reflect.DeepEqual(dest.V1, true) {
t.Errorf("not equal: got '%v', want '%v'",
dest.V1, true)
}

}

0 comments on commit 0c4657d

Please sign in to comment.