src.bluetooth_sig.advertising.service_data_parser

Service data parser for BLE advertisements.

Parses service data payloads using registered GATT characteristic classes, enabling automatic interpretation of SIG-standard and custom characteristics from advertisement service data.

This bridges the advertising and GATT layers: - Advertisement Service Data (UUID → raw bytes) is extracted by AdvertisingPDUParser - This module maps UUIDs to characteristic classes via CharacteristicRegistry - Characteristic classes decode bytes using their standard parse_value() method

Classes

Name

Description

ServiceDataParser

Parser for service data from BLE advertisements.

Module Contents

class src.bluetooth_sig.advertising.service_data_parser.ServiceDataParser

Parser for service data from BLE advertisements.

Uses registered GATT characteristic classes to decode service data payloads. Both SIG-standard and custom-registered characteristics are supported via the unified CharacteristicRegistry.

Example

parser = ServiceDataParser()

# Parse all service data from an advertisement service_data = {BluetoothUUID(“2A6E”): b’xE8x03’} # Temperature results = parser.parse(service_data) # results = {BluetoothUUID(“2A6E”): 10.0} # Parsed temperature in °C

# Parse with context ctx = ServiceDataParser.build_context(

device_name=”MySensor”, device_address=”AA:BB:CC:DD:EE:FF”,

) results = parser.parse(service_data, ctx)

static build_context(device_name: str = '', device_address: str = '', manufacturer_data: dict[int, bytes] | None = None, service_uuids: list[bluetooth_sig.types.uuid.BluetoothUUID] | None = None, advertisement: bytes = b'', validate: bool = True) bluetooth_sig.types.context.CharacteristicContext

Build a CharacteristicContext from advertisement information.

Parameters:
  • device_name – Device local name from advertisement

  • device_address – Device MAC address

  • manufacturer_data – Manufacturer data from advertisement

  • service_uuids – Service UUIDs from advertisement

  • advertisement – Raw advertisement bytes

  • validate – Whether to perform validation during parsing

Returns:

CharacteristicContext populated with device info

classmethod clear_cache() None

Clear the characteristic instance cache (for testing).

classmethod get_characteristic(uuid: bluetooth_sig.types.uuid.BluetoothUUID) bluetooth_sig.gatt.characteristics.base.BaseCharacteristic[Any] | None

Get a cached characteristic instance for the given UUID.

Parameters:

uuid – The characteristic UUID to look up

Returns:

Characteristic instance if UUID is registered, None otherwise

parse(service_data: dict[bluetooth_sig.types.uuid.BluetoothUUID, bytes], ctx: bluetooth_sig.types.context.CharacteristicContext | None = None) dict[bluetooth_sig.types.uuid.BluetoothUUID, Any]

Parse service data using registered characteristic classes.

Iterates through service data entries, looking up each UUID in the CharacteristicRegistry. For recognised UUIDs, calls parse_value() to decode the payload. Unrecognised UUIDs are skipped.

Use ctx.validate=False to suppress validation exceptions.

Parameters:
  • service_data – Mapping of service UUID to raw payload bytes

  • ctx – Optional context for parsing

Returns:

Mapping of UUID to parsed values (only includes recognised UUIDs)

Raises: