src.bluetooth_sig.gatt.characteristics.templates.base¶
Base coding template abstract class and shared constants.
All coding templates MUST inherit from CodingTemplate defined here.
Attributes¶
Name | Description |
|---|---|
Classes¶
Name | Description |
|---|---|
Abstract base class for coding templates. |
Module Contents¶
- class src.bluetooth_sig.gatt.characteristics.templates.base.CodingTemplate¶
-
Abstract base class for coding templates.
Templates are pure coding utilities that don’t inherit from BaseCharacteristic. They provide coding strategies that can be injected into characteristics. All templates MUST inherit from this base class and implement the required methods.
Generic over T_co, the type of value produced by _decode_value. Concrete templates specify their return type, e.g., CodingTemplate[int].
- Pipeline Integration:
Simple templates (single-field) expose extractor and translator properties for the decode/encode pipeline. Complex templates return None for these properties.
- abstractmethod decode_value(data: bytearray, offset: int = 0, ctx: src.bluetooth_sig.gatt.context.CharacteristicContext | None = None, *, validate: bool = True) T_co¶
Decode raw bytes to typed value.
- Parameters:
data – Raw bytes to parse
offset – Byte offset to start parsing from
ctx – Optional context for parsing
validate – Whether to validate ranges (default True)
- Returns:
Parsed value of type T_co
- abstractmethod encode_value(value: T_co, *, validate: bool = True) bytearray¶
Encode typed value to raw bytes.
- Parameters:
value – Typed value to encode
validate – Whether to validate ranges (default True)
- Returns:
Raw bytes representing the value
- classmethod resolve_python_type() type | None¶
Resolve the decoded Python type from the template’s generic parameter.
Walks the MRO to find the concrete type argument bound to
CodingTemplate[T_co]. ReturnsNonewhen the parameter is still an unboundTypeVar(e.g.EnumTemplate[T]before instantiation with a concrete enum).The result is cached per-class in
_resolved_python_typeto avoid repeated MRO introspection.
- property extractor: src.bluetooth_sig.gatt.characteristics.utils.extractors.RawExtractor | None¶
Get the raw byte extractor for pipeline access.
Returns None for complex templates where extraction isn’t separable.
- property translator: src.bluetooth_sig.gatt.characteristics.utils.translators.ValueTranslator[Any] | None¶
Get the value translator for pipeline access.
Returns None for complex templates where translation isn’t separable.
- src.bluetooth_sig.gatt.characteristics.templates.base.T_co¶