ble: move the core value types into a leaf package - #477
Merged
Conversation
The HCI protocol code must move into a subpackage, and it needs UUID, MAC
and MACAddress. A subpackage cannot import the root package, so these
types move to a leaf package that both can use.
The root package keeps its API with type aliases, so bluetooth.UUID and
ble.UUID are the same type and the generated UUID tables need no change.
Three members become exported, because an alias gives the root package the
leaf's method set and nothing more:
UUID.bytes() -> UUID.BytesLittleEndian()
MACAddress{...} -> ble.NewMACAddress(mac, random)
new -> ble.UUIDFromBytes(b), the inverse of BytesLittleEndian
A method cannot be declared on an aliased type, so two methods become free
functions: UUID.isIn -> uuidIn and UUID.shortUUID -> shortUUIDFor.
UUIDFromBytes also lets uuid_sd.go stop reaching into the unexported UUID
field with unsafe.Pointer.
This was referenced Sep 9, 2026
acouvreur
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Moves
UUID,MAC,MACAddressandAttributeProtocolErrorinto a leafpackage
tinygo.org/x/bluetooth/ble.This is the first of three stacked pull requests that move the HCI protocol
stack out of the root package. It carries no HCI logic and no behaviour change.
It is separate because the type move touches many files, and a reviewer should
be able to confirm that it is mechanical without the protocol changes in view.
Why a leaf package
A subpackage cannot import the root package, so the HCI stack cannot move out
while the core value types stay in the root.
bleholds those types andimports nothing from this repository.
Compatibility
The root package aliases all four types, so
bluetooth.UUIDandble.UUIDare the same type, and existing code keeps compiling. The generated UUID tables
needed no change.
Verification
go vetandgo testover./ ./ble, both plain and with-race, plusmake smoketest-linuxandmake smoketest-windows.The rest of the stack
hci: move the protocol stack into a subpackagehci: add unit tests, and correct what they found