Skip to content

Provide Bluetooth SIG assigned numbers as Kotlin constants#1220

Draft
twyatt wants to merge 6 commits into
mainfrom
cursor/assigned-numbers-constants-c1c4
Draft

Provide Bluetooth SIG assigned numbers as Kotlin constants#1220
twyatt wants to merge 6 commits into
mainfrom
cursor/assigned-numbers-constants-c1c4

Conversation

@twyatt

@twyatt twyatt commented Jul 16, 2026

Copy link
Copy Markdown
Member

Closes #898

Provides all Bluetooth SIG assigned numbers for services, characteristics and descriptors as Kotlin constants (with autocompletion and KDoc) in a new bluetooth-sig-assigned-numbers module, and uses the constants instead of the string-based lookups. Based on chungchungdev/kotlin-bluetoothsig-assigned-numbers (Apache-2.0, thanks @chungchungdev!), refreshed against the current Bluetooth SIG assigned numbers repository (2026-07-18, 603 constants).

Changes

  • New bluetooth-sig-assigned-numbers module (published as com.juul.kable:bluetooth-sig-assigned-numbers, optional for kable-core consumers), structured so that fully qualified constant names exactly match the IDs defined in the Bluetooth SIG assigned numbers YAML files:
    • Package is org.bluetooth with lowercase constants in top-level service, characteristic and descriptor objects (no wrapper object), e.g. org.bluetooth.service.heart_rate, org.bluetooth.characteristic.gap.device_name, org.bluetooth.descriptor.gatt.client_characteristic_configuration.

    • Constants are Int (all assigned numbers are 16-bit, so none overflow), combining directly with the existing Bluetooth.BaseUuid + Int operator:

      val heartRateServiceUuid = Bluetooth.BaseUuid + org.bluetooth.service.heart_rate
      println(heartRateServiceUuid) // Output: 0000180d-0000-1000-8000-00805f9b34fb
    • The three IDs that aren't valid Kotlin identifiers (e.g. real-time_ranging_data) are backtick-escaped.

    • Constant KDoc holds just the human-readable name (the hex value would be redundant with the constant's value).

    • Same targets as the other published modules (JVM/JS/WasmJS + Apple targets on macOS hosts); Android consumers use the JVM variant.

  • String-based lookups deprecated (WARNING level): Uuid.service(name), Uuid.characteristic(name) and Uuid.descriptor(name) now point users at the corresponding org.bluetooth object in the new artifact. The constants also cover far more assigned numbers than the Web Bluetooth-sourced maps did, and avoid runtime NoSuchElementExceptions from typo'd names.
  • Usages migrated to the constants: the characteristicOf deprecation message example in Profile.kt, the SensorTag sample's battery characteristic (sample now depends on the new artifact), and the README (setup, UUID shorthand section, I/O examples). kable-core itself has no dependency on the new module, keeping the artifact fully optional.
  • API dump generated for bluetooth-sig-assigned-numbers. (The api/android dump appears to no longer be maintained by binary-compatibility-validator since the migration to AGP's built-in Kotlin, see Kotlin/binary-compatibility-validator#312, so it is untouched.)
  • New module registered in settings.gradle.kts, Dokka aggregation, and (implicitly) binary compatibility validation.

Testing

  • ./gradlew :kable-core:jvmTest — passed
  • ./gradlew apiCheck lintKotlin — passed
  • ./gradlew :bluetooth-sig-assigned-numbers:assemble :kable-core:compileKotlinJvm :kable-core:compileKotlinJs :kable-core:compileKotlinWasmJs :kable-core:compileAndroidMain — passed
  • ./gradlew -PRELEASE_SIGNING_ENABLED=false :bluetooth-sig-assigned-numbers:publishToMavenLocal — passed
  • SensorTag sample: ./gradlew :shared:compileKotlinJvm :shared:compileAndroidMain — passed

(Native/Apple targets not compiled; only enabled on macOS hosts.)

Open in Web Open in Cursor 

cursoragent and others added 6 commits July 16, 2026 21:16
Pulls AssignedNumbers.kt (Apache-2.0) from
https://github.com/chungchungdev/kotlin-bluetoothsig-assigned-numbers
into kable-core, providing Bluetooth SIG assigned numbers for services,
characteristics and descriptors as Kotlin constants. Also adds a
Bluetooth.BaseUuid plus(UInt) operator so the constants can be combined
into full 128-bit UUIDs.

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
Deprecates the string-based Uuid.service/characteristic/descriptor
lookup functions in favor of AssignedNumbers constants, and migrates
internal usages, the SensorTag sample and README accordingly.

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
Extracts AssignedNumbers.kt from kable-core into a new (optional)
bluetooth-sig-assigned-numbers module/artifact. kable-core no longer
depends on the constants; deprecation messages now point at the new
artifact and the SensorTag sample consumes it explicitly.

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
Moves the constants to the org.bluetooth package with lowercase names
so that fully qualified names exactly match the IDs defined in the
Bluetooth SIG assigned numbers YAML files, for example:
org.bluetooth.service.heart_rate and
org.bluetooth.descriptor.gatt.client_characteristic_configuration.

Drops the AssignedNumbers wrapper object in favor of top-level
service/characteristic/descriptor objects, and removes the redundant
value lines from constant documentation. IDs that are not valid Kotlin
identifiers (e.g. real-time_ranging_data) are backtick-escaped.

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
All assigned numbers are 16-bit, so they fit in Int without overflow.
This works directly with the existing Bluetooth.BaseUuid plus(Int)
operator, so the plus(UInt) overload is no longer needed.

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
Regenerates constants from the current Bluetooth SIG assigned numbers
repository (2026-07-18), adding 42 new assigned numbers (4 services,
36 characteristics, 2 descriptors) and applying 3 SIG renames:
ieee_11073-20601_regulatory_certification_data_list (now a valid
identifier as ieee_11073_20601_regulatory_certification_data_list),
current_elapsed_time -> elapsed_time, and
medical_devices -> udi_for_medical_devices. The descriptors YAML file
was also renamed upstream (descriptor_uuids.yaml -> descriptors.yaml).

Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
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.

Use Kotlin constants to list Bluetooth SIG assigned numbers

2 participants