darkhz / bluetuith

A TUI bluetooth manager for Linux.
MIT License
850 stars 21 forks source link

Property type run-time assertion #42

Closed darkhz closed 8 months ago

darkhz commented 8 months ago

When querying properties for a path in the Bluez DBus, most properties that are returned are of the type dbus.Variant. A Variant type can contain single/multiple values, and multiple values are mostly of the form map[string]dbus.Variant or similarly nested maps.

Asserting types for multiple variants/properties can become quite lengthy, and as such, it would be convenient to loop through the map of variants, assert the type and place it in a data structure. This is tedious to do as well, even if we know the signature for each property, since we need to keep a separate structure to store the signatures, and if any properties are added, said structure needs to be updated as well.

The better way is to provide the data structure, get the type of each struct member and update it from the map of variants, with as little reflect usage as possible. Hence, the DecodeVariantMap function encodes/decodes data using functions provided by go-codec.

darkhz commented 8 months ago

@ddelazerda thank you for reviewing and testing this. This PR will not be merged directly, I will have to make a few cosmetic changes to the code before commiting it.