src.bluetooth_sig.gatt.characteristics.pipeline.encode_pipeline

Encode pipeline for GATT characteristic values.

Orchestrates the multi-stage encoding process: type validation → range validation → value encoding → length validation.

Classes

Name

Description

EncodePipeline

Multi-stage encode pipeline for characteristic values.

Module Contents

class src.bluetooth_sig.gatt.characteristics.pipeline.encode_pipeline.EncodePipeline(char: Any, validator: src.bluetooth_sig.gatt.characteristics.pipeline.validation.CharacteristicValidator)

Multi-stage encode pipeline for characteristic values.

Stages:
  1. Type validation

  2. Range validation (numeric types only)

  3. Value encoding (via template or subclass _encode_value)

  4. Length validation (post-encode)

Uses a back-reference to the owning characteristic for: - _encode_value() dispatch (Template Method pattern) - Metadata access (name, uuid, _template, _spec) - Special value resolver

encode_special(value_type: Any) bytearray

Encode a special value type to bytes (reverse lookup).

Parameters:

value_typeSpecialValueType enum member.

Returns:

Encoded bytes for the special value.

Raises:

ValueError – If no raw value of that type is defined.

encode_special_by_meaning(meaning: str) bytearray

Encode a special value by a partial meaning string match.

Parameters:

meaning – Partial meaning string to match.

Returns:

Encoded bytes for the matching special value.

Raises:

ValueError – If no matching special value is found.

run(data: Any, validate: bool = True) bytearray

Execute the full encode pipeline.

Parameters:
  • data – Value to encode (type T) or SpecialValueResult.

  • validate – Enable validation (type, range, length checks). Special values bypass validation.

Returns:

Encoded bytes ready for BLE write.

Raises:

CharacteristicEncodeError – If encoding or validation fails.