This commit is contained in:
J. Nick Koston 2025-07-17 07:21:32 -10:00
parent dbbcbc0998
commit 72419eb540
No known key found for this signature in database
2 changed files with 14 additions and 3 deletions

View File

@ -1923,7 +1923,9 @@ void BluetoothLERawAdvertisement::calculate_size(uint32_t &total_size) const {
ProtoSize::add_uint64_field(total_size, 1, this->address);
ProtoSize::add_sint32_field(total_size, 1, this->rssi);
ProtoSize::add_uint32_field(total_size, 1, this->address_type);
total_size += 1 + ProtoSize::varint(static_cast<uint32_t>(this->data_len)) + this->data_len;
if (this->data_len != 0) {
total_size += 1 + ProtoSize::varint(static_cast<uint32_t>(this->data_len)) + this->data_len;
}
}
void BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer buffer) const {
for (auto &it : this->advertisements) {

View File

@ -663,9 +663,18 @@ class FixedArrayBytesType(TypeInfo):
def get_size_calculation(self, name: str, force: bool = False) -> str:
# Use the actual length stored in the _len field
length_field = f"this->{self.field_name}_len"
# Size = field_id_size + varint(length) + actual_data_bytes
field_id_size = self.calculate_field_id_size()
return f" total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};\n"
if force:
# For repeated fields, always calculate size
return f"total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};"
else:
# For non-repeated fields, skip if length is 0 (matching encode_string behavior)
return (
f"if ({length_field} != 0) {{\n"
f" total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};\n"
f"}}"
)
def get_estimated_size(self) -> int:
# Estimate based on typical BLE advertisement size