From 37cbcd5110a8e7522091895ad333721d969006ca Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 21 Jul 2025 12:55:05 -1000 Subject: [PATCH] preen --- esphome/components/api/api_pb2.h | 4 --- script/api_protobuf/api_protobuf.py | 40 +++++++++++------------------ 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 7a9726f6e4..1d052f6114 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -1797,7 +1797,6 @@ class BluetoothGATTGetServicesRequest : public ProtoDecodableMessage { class BluetoothGATTDescriptor : public ProtoMessage { public: std::array uuid{}; - size_t uuid_index_{0}; uint32_t handle{0}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -1810,7 +1809,6 @@ class BluetoothGATTDescriptor : public ProtoMessage { class BluetoothGATTCharacteristic : public ProtoMessage { public: std::array uuid{}; - size_t uuid_index_{0}; uint32_t handle{0}; uint32_t properties{0}; std::vector descriptors{}; @@ -1825,7 +1823,6 @@ class BluetoothGATTCharacteristic : public ProtoMessage { class BluetoothGATTService : public ProtoMessage { public: std::array uuid{}; - size_t uuid_index_{0}; uint32_t handle{0}; std::vector characteristics{}; void encode(ProtoWriteBuffer buffer) const override; @@ -1845,7 +1842,6 @@ class BluetoothGATTGetServicesResponse : public ProtoMessage { #endif uint64_t address{0}; std::array services{}; - size_t services_index_{0}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 3ca390658b..1031b294e2 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -887,7 +887,11 @@ class SInt64Type(TypeInfo): class FixedArrayRepeatedType(TypeInfo): - """Special type for fixed-size repeated fields using std::array.""" + """Special type for fixed-size repeated fields using std::array. + + Fixed arrays are only supported for encoding (SOURCE_SERVER) since we cannot + control how many items we receive when decoding. + """ def __init__(self, field: descriptor.FieldDescriptorProto, size: int) -> None: super().__init__(field) @@ -915,42 +919,28 @@ class FixedArrayRepeatedType(TypeInfo): @property def public_content(self) -> list[str]: - # Add the array member and a counter for decoding - return [ - f"{self.cpp_type} {self.field_name}{{}};", - f"size_t {self.field_name}_index_{{0}};", - ] + # Just the array member, no index needed since we don't decode + return [f"{self.cpp_type} {self.field_name}{{}};"] @property def decode_varint_content(self) -> str: - content = self._ti.decode_varint - if content is None: - return None - return f"case {self.number}: if (this->{self.field_name}_index_ < {self.array_size}) {{ this->{self.field_name}[this->{self.field_name}_index_++] = {content}; }} break;" + # Fixed arrays don't support decoding + return None @property def decode_length_content(self) -> str: - content = self._ti.decode_length - if content is None and isinstance(self._ti, MessageType): - # Special handling for non-template message decoding - return f"case {self.number}: if (this->{self.field_name}_index_ < {self.array_size}) {{ value.decode_to_message(this->{self.field_name}[this->{self.field_name}_index_++]); }} break;" - if content is None: - return None - return f"case {self.number}: if (this->{self.field_name}_index_ < {self.array_size}) {{ this->{self.field_name}[this->{self.field_name}_index_++] = {content}; }} break;" + # Fixed arrays don't support decoding + return None @property def decode_32bit_content(self) -> str: - content = self._ti.decode_32bit - if content is None: - return None - return f"case {self.number}: if (this->{self.field_name}_index_ < {self.array_size}) {{ this->{self.field_name}[this->{self.field_name}_index_++] = {content}; }} break;" + # Fixed arrays don't support decoding + return None @property def decode_64bit_content(self) -> str: - content = self._ti.decode_64bit - if content is None: - return None - return f"case {self.number}: if (this->{self.field_name}_index_ < {self.array_size}) {{ this->{self.field_name}[this->{self.field_name}_index_++] = {content}; }} break;" + # Fixed arrays don't support decoding + return None @property def _ti_is_bool(self) -> bool: