mirror of
https://github.com/esphome/esphome.git
synced 2025-08-01 07:57:47 +00:00
fix
This commit is contained in:
parent
dbbcbc0998
commit
72419eb540
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user