bluetooth
bluetooth copied to clipboard
Device property changes
Hello, is there a reason why not to use util.MapToStruct() here:
// gap_linux.go -> line 171
case "org.freedesktop.DBus.Properties.PropertiesChanged":
interfaceName := sig.Body[0].(string)
if interfaceName != "org.bluez.Device1" {
continue
}
changes := sig.Body[1].(map[string]dbus.Variant)
props := devices[sig.Path]
// This is the part I added
err := util.MapToStruct(props, changes)
if err != nil {
panic(err)
}
// instead of this
// for field, val := range changes {
// switch field {
// case "RSSI":
// props.RSSI = val.Value().(int16)
// case "Name":
// props.Name = val.Value().(string)
// case "UUIDs":
// props.UUIDs = val.Value().([]string)
// }
// }
callback(a, makeScanResult(props))
}
I added some fields to AdvertisementFields struct and they did not update, so I fixed it like this. But I was just wondering if there is a reason why I should't do this?
Thanks.