This commit is contained in:
J. Nick Koston 2025-07-21 13:17:18 -10:00
parent 55272dd0fd
commit 7b9acd39e1
No known key found for this signature in database
2 changed files with 34 additions and 19 deletions

View File

@ -1891,21 +1891,18 @@ bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarI
return true;
}
void BluetoothGATTDescriptor::encode(ProtoWriteBuffer buffer) const {
for (const auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
}
void BluetoothGATTDescriptor::calculate_size(uint32_t &total_size) const {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
}
void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const {
for (const auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
buffer.encode_uint32(3, this->properties);
for (auto &it : this->descriptors) {
@ -1913,26 +1910,23 @@ void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const {
}
}
void BluetoothGATTCharacteristic::calculate_size(uint32_t &total_size) const {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
ProtoSize::add_uint32_field(total_size, 1, this->properties);
ProtoSize::add_repeated_message(total_size, 1, this->descriptors);
}
void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const {
for (const auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
for (auto &it : this->characteristics) {
buffer.encode_message(3, it, true);
}
}
void BluetoothGATTService::calculate_size(uint32_t &total_size) const {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
ProtoSize::add_repeated_message(total_size, 1, this->characteristics);
}

View File

@ -936,7 +936,20 @@ class FixedArrayRepeatedType(TypeInfo):
else:
return f"buffer.{self._ti.encode_func}({self.number}, this->{self.field_name}[0], true);"
# Multiple elements need a loop
# Special case for 2-element arrays - unroll the loop
if self.array_size == 2:
if isinstance(self._ti, EnumType):
return (
f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(this->{self.field_name}[0]), true);\n"
f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(this->{self.field_name}[1]), true);"
)
else:
return (
f"buffer.{self._ti.encode_func}({self.number}, this->{self.field_name}[0], true);\n"
f" buffer.{self._ti.encode_func}({self.number}, this->{self.field_name}[1], true);"
)
# 3 or more elements need a loop
o = f"for (const auto &it : this->{self.field_name}) {{\n"
if isinstance(self._ti, EnumType):
o += f" buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>(it), true);\n"
@ -966,6 +979,14 @@ class FixedArrayRepeatedType(TypeInfo):
if self.array_size == 1:
return self._ti.get_size_calculation(f"{name}[0]", True)
# Special case for 2-element arrays - unroll the calculation
if self.array_size == 2:
return (
self._ti.get_size_calculation(f"{name}[0]", True)
+ "\n "
+ self._ti.get_size_calculation(f"{name}[1]", True)
)
# 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()
if num_bytes is not None: