gap: Introduce AdvertisementPayload.ServiceUUIDs()
This adds a new method that returns all of the Service Class UUIDs found in the advertisement payload. This may require allocating a new slice of UUIDs, hence using HasServiceUUID where possible is still preferred.
Fixes https://github.com/tinygo-org/bluetooth/issues/363
I have no idea what I'm doing, so please review the rawAdvertisementPayload implementation harder; I'm just adapting the HasServiceUUID code. I assume since go.mod claims go1.20 using the conversion in NewUUID is okay.
Please let me know if you'd like me to make changes; if you feel like making the directly that's fine too.
Hello @mook thank you for looking into this.
If you could please add some tests for the new functions into https://github.com/tinygo-org/bluetooth/blob/dev/gap_test.go that would be greatly appreciated!
Thanks! Tests added. That raises some questions, though:
NewUUIDtakes bytes in the reverse order ofUnmarshalBinary(andBytes); when should each be used?- When implementing
rawAdvertisementPayload#ServiceUUIDs, should I actually combine0x03and0x02(complete and incomplete lists of 16-bit UUIDs), instead of preferring the first? Similarly for0x07vs0x06(complete and incomplete list of 128-bit UUIDs). How about0x05/0x04(32-bit UUIDs)? CurrentlyrawAdvertisementPayload#HasServiceUUIDjust ignores it. - Can I assume that the advertisement payload will not have multiple of the same EIR data type? Or should I actually just enumerate all EIR data instead? (Apologies if I have the terminology incorrect, I have no idea what I'm doing with respect to Bluetooth.)
Rebased; the relevant files had no changes, so there were no merge conflicts.
While the tests pass, it's probably still best if https://github.com/tinygo-org/bluetooth/pull/364#issuecomment-2973423909 gets resolved before merging.
Thanks! Tests added. That raises some questions, though:
The Bluetooth spec tell us that this array is always little-endian.
- When implementing
rawAdvertisementPayload#ServiceUUIDs, should I actually combine0x03and0x02(complete and incomplete lists of 16-bit UUIDs), instead of preferring the first? Similarly for0x07vs0x06(complete and incomplete list of 128-bit UUIDs). How about0x05/0x04(32-bit UUIDs)? CurrentlyrawAdvertisementPayload#HasServiceUUIDjust ignores it.
That might be a kind of bug? Let us address that as a future PR.
- Can I assume that the advertisement payload will not have multiple of the same EIR data type? Or should I actually just enumerate all EIR data instead? (Apologies if I have the terminology incorrect, I have no idea what I'm doing with respect to Bluetooth.)
Given how small the size of data is, we can probably assume no duplication in this packet.
Now merging, thanks for working on this @mook