Skip to content

ble: move the core value types into a leaf package - #477

Merged
deadprogram merged 1 commit into
devfrom
ble-package
Sep 9, 2026
Merged

ble: move the core value types into a leaf package#477
deadprogram merged 1 commit into
devfrom
ble-package

Conversation

@deadprogram

@deadprogram deadprogram commented Sep 9, 2026

Copy link
Copy Markdown
Member

Moves UUID, MAC, MACAddress and AttributeProtocolError into a leaf
package 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. ble holds those types and
imports nothing from this repository.

Compatibility

The root package aliases all four types, so bluetooth.UUID and ble.UUID
are the same type, and existing code keeps compiling. The generated UUID tables
needed no change.

Verification

go vet and go test over ./ ./ble, both plain and with -race, plus
make smoketest-linux and make smoketest-windows.

The rest of the stack

  1. hci: move the protocol stack into a subpackage #478 hci: move the protocol stack into a subpackage
  2. hci: add unit tests, and correct what they found #476 hci: add unit tests, and correct what they found

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.
@deadprogram
deadprogram merged commit 0efa345 into dev Sep 9, 2026
4 checks passed
@deadprogram
deadprogram deleted the ble-package branch September 9, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants