src.bluetooth_sig.gatt.characteristics.utils.extractors¶
Raw byte extractors for the BLE encoding/decoding pipeline.
This module provides the extraction layer that ONLY converts bytes to raw integers (and back). Extractors have a single responsibility: byte layout interpretation.
- The extraction layer is the first stage of the decode pipeline:
bytes → [Extractor] → raw_int → [Translator] → typed_value
Per Bluetooth SIG specifications, all multi-byte values use little-endian encoding unless explicitly stated otherwise.
Attributes¶
Classes¶
Name | Description |
|---|---|
Extract/pack IEEE-754 32-bit floats. |
|
Protocol for raw byte extraction. |
|
Extract/pack signed 16-bit integers (-32768 to 32767). |
|
Extract/pack signed 24-bit integers (-8388608 to 8388607). |
|
Extract/pack signed 32-bit integers (-2147483648 to 2147483647). |
|
Extract/pack signed 8-bit integers (-128 to 127). |
|
Extract/pack unsigned 16-bit integers (0 to 65535). |
|
Extract/pack unsigned 24-bit integers (0 to 16777215). |
|
Extract/pack unsigned 32-bit integers (0 to 4294967295). |
|
Extract/pack unsigned 8-bit integers (0 to 255). |
Functions¶
Name | Description |
|---|---|
|
Get extractor for a GSS type string. |
Module Contents¶
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Float32Extractor¶
Bases:
RawExtractorExtract/pack IEEE-754 32-bit floats.
Unlike integer extractors, this returns the raw bits as an integer to enable special value detection (NaN patterns, etc.) before translation to float.
- extract(data: bytes | bytearray, offset: int = 0) int¶
Extract float32 as raw bits for special value checking.
Returns the raw 32-bit integer representation of the float, which allows special value detection (NaN patterns, etc.).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.RawExtractor¶
Bases:
abc.ABCProtocol for raw byte extraction.
Extractors handle ONLY byte layout: extracting raw integers from bytes and packing raw integers back to bytes. They do not apply scaling, handle special values, or perform validation beyond bounds checking.
The separation enables: - Interception of raw values for special value handling - Composition with translators for scaling - Reuse across templates and characteristics
- abstractmethod extract(data: bytes | bytearray, offset: int = 0) int¶
Extract raw integer from bytes.
- Parameters:
data – Source bytes to extract from.
offset – Byte offset to start reading from.
- Returns:
Raw integer value (not scaled or interpreted).
- Raises:
InsufficientDataError – If data is too short for extraction.
- abstractmethod pack(raw: int) bytearray¶
Pack raw integer to bytes.
- Parameters:
raw – Raw integer value to encode.
- Returns:
Packed bytes in little-endian format.
- Raises:
ValueRangeError – If raw value exceeds type bounds.
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Sint16Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack signed 16-bit integers (-32768 to 32767).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Sint24Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack signed 24-bit integers (-8388608 to 8388607).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Sint32Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack signed 32-bit integers (-2147483648 to 2147483647).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Sint8Extractor¶
Bases:
RawExtractorExtract/pack signed 8-bit integers (-128 to 127).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Uint16Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack unsigned 16-bit integers (0 to 65535).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Uint24Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack unsigned 24-bit integers (0 to 16777215).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Uint32Extractor(endian: Literal['little', 'big'] = 'little')¶
Bases:
RawExtractorExtract/pack unsigned 32-bit integers (0 to 4294967295).
- class src.bluetooth_sig.gatt.characteristics.utils.extractors.Uint8Extractor¶
Bases:
RawExtractorExtract/pack unsigned 8-bit integers (0 to 255).
- src.bluetooth_sig.gatt.characteristics.utils.extractors.get_extractor(type_name: str) RawExtractor | None¶
Get extractor for a GSS type string.
- Parameters:
type_name – Type string from GSS FieldSpec.type (e.g., “sint16”, “uint8”).
- Returns:
Matching RawExtractor singleton, or None if type is not recognized.
Examples
>>> extractor = get_extractor("sint16") >>> raw = extractor.extract(data, offset=0)
- src.bluetooth_sig.gatt.characteristics.utils.extractors.FLOAT32¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.SINT16¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.SINT24¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.SINT32¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.SINT8¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.UINT16¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.UINT24¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.UINT32¶
- src.bluetooth_sig.gatt.characteristics.utils.extractors.UINT8¶