Make services
direct references and match properties for I/O
#238
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by #128.
Previously, all I/O operations would lazily search for the first match when looking up characteristics or descriptors. This was problematic if duplicate UUIDs existed. Discovered GATT profile items (services, characteristics and descriptors) as provided via
Peripheral.services
now hold direct references to underlying platform types. This means they no longer trigger lookups for I/O operations and specific GATT profile items can be manually sought after and used.When using
characteristicOf
(which is still a lazy lookup), the properties of the characteristic are now taken into account when searching for the underlying platform object (this will allow support for duplicate UUIDs assuming they differ by the appropriate properties). For example, when performing a read, only a characteristic with a matching UUID andread
property will be considered a match.This PR implements a "more correct" behavior for characteristic lookups (when using
characteristicOf
) but is a potentially breaking change (at runtime) for some users. If a library consumer has a peripheral with characteristics with incorrect (or missing) properties, then they may have been relying oncharacteristicOf
to match the first one found with the same UUID, but this PR may make it so that when lazily looking up the characteristic, it is no longer found if the peripheral's characteristic is not setup with the appropriate properties. In this case, these users should either update the firmware on the peripheral to have correct properties, or manually traverse thePeripheral.services
in order to perform I/O on the characteristic they were using before.Updated documentation can be read here.
Closes #127
Closes #93