This commit is contained in:
J. Nick Koston 2025-07-21 13:13:45 -10:00
parent bc6b1ffc14
commit 55272dd0fd
No known key found for this signature in database
2 changed files with 15 additions and 6 deletions

View File

@ -1938,15 +1938,11 @@ void BluetoothGATTService::calculate_size(uint32_t &total_size) const {
} }
void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const { void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint64(1, this->address); buffer.encode_uint64(1, this->address);
for (const auto &it : this->services) { buffer.encode_message(2, this->services[0], true);
buffer.encode_message(2, it, true);
}
} }
void BluetoothGATTGetServicesResponse::calculate_size(uint32_t &total_size) const { void BluetoothGATTGetServicesResponse::calculate_size(uint32_t &total_size) const {
ProtoSize::add_uint64_field(total_size, 1, this->address); ProtoSize::add_uint64_field(total_size, 1, this->address);
for (const auto &it : this->services) { ProtoSize::add_message_object_repeated(total_size, 1, this->services[0]);
ProtoSize::add_message_object_repeated(total_size, 1, it);
}
} }
void BluetoothGATTGetServicesDoneResponse::encode(ProtoWriteBuffer buffer) const { void BluetoothGATTGetServicesDoneResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint64(1, this->address); buffer.encode_uint64(1, this->address);

View File

@ -929,6 +929,14 @@ class FixedArrayRepeatedType(TypeInfo):
@property @property
def encode_content(self) -> str: def encode_content(self) -> str:
# Special case for single-element arrays - no loop needed
if self.array_size == 1:
if isinstance(self._ti, EnumType):
return f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(this->{self.field_name}[0]), true);"
else:
return f"buffer.{self._ti.encode_func}({self.number}, this->{self.field_name}[0], true);"
# Multiple elements need a loop
o = f"for (const auto &it : this->{self.field_name}) {{\n" o = f"for (const auto &it : this->{self.field_name}) {{\n"
if isinstance(self._ti, EnumType): if isinstance(self._ti, EnumType):
o += f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(it), true);\n" o += f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(it), true);\n"
@ -953,6 +961,11 @@ class FixedArrayRepeatedType(TypeInfo):
def get_size_calculation(self, name: str, force: bool = False) -> str: def get_size_calculation(self, name: str, force: bool = False) -> str:
# For fixed arrays, we always encode all elements # For fixed arrays, we always encode all elements
# Special case for single-element arrays - no loop needed
if self.array_size == 1:
return self._ti.get_size_calculation(f"{name}[0]", True)
# Check if this is a fixed-size type by seeing if it has a fixed byte count # Check if this is a fixed-size type by seeing if it has a fixed byte count
num_bytes = self._ti.get_fixed_size_bytes() num_bytes = self._ti.get_fixed_size_bytes()
if num_bytes is not None: if num_bytes is not None: