Coverage for src / bluetooth_sig / gatt / characteristics / object_size.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
1"""Object Size characteristic implementation."""
3from __future__ import annotations
5import msgspec
7from ...types.gatt_enums import CharacteristicRole
8from ..context import CharacteristicContext
9from .base import BaseCharacteristic
10from .utils import DataParser
13class ObjectSizeData(msgspec.Struct, frozen=True, kw_only=True):
14 """Parsed data from Object Size characteristic.
16 Attributes:
17 current_size: Current size of the object in bytes.
18 allocated_size: Allocated size for the object in bytes.
20 """
22 current_size: int
23 allocated_size: int
26class ObjectSizeCharacteristic(BaseCharacteristic[ObjectSizeData]):
27 """Object Size characteristic (0x2AC0).
29 org.bluetooth.characteristic.object_size
31 Two uint32 fields representing the current size and allocated size
32 of an object in the Object Transfer Service (OTS).
33 """
35 _manual_role = CharacteristicRole.INFO
36 expected_length: int = 8 # uint32 + uint32
37 min_length: int = 8
39 def _decode_value(
40 self,
41 data: bytearray,
42 ctx: CharacteristicContext | None = None,
43 *,
44 validate: bool = True,
45 ) -> ObjectSizeData:
46 """Parse object size (two uint32 fields).
48 Args:
49 data: Raw bytes (8 bytes).
50 ctx: Optional CharacteristicContext.
51 validate: Whether to validate ranges (default True).
53 Returns:
54 ObjectSizeData with current_size and allocated_size.
56 """
57 current_size = DataParser.parse_int32(data, 0, signed=False)
58 allocated_size = DataParser.parse_int32(data, 4, signed=False)
59 return ObjectSizeData(current_size=current_size, allocated_size=allocated_size)
61 def _encode_value(self, data: ObjectSizeData) -> bytearray:
62 """Encode object size to bytes.
64 Args:
65 data: ObjectSizeData to encode.
67 Returns:
68 Encoded bytes (8 bytes).
70 """
71 result = DataParser.encode_int32(data.current_size, signed=False)
72 result.extend(DataParser.encode_int32(data.allocated_size, signed=False))
73 return result