mirror of
https://github.com/esphome/esphome.git
synced 2025-10-13 23:33:48 +01:00
Fix bluetooth_proxy heap allocations during BLE scanning (#9633)
This commit is contained in:
@@ -1381,7 +1381,7 @@ message BluetoothLERawAdvertisement {
|
||||
sint32 rssi = 2;
|
||||
uint32 address_type = 3;
|
||||
|
||||
bytes data = 4;
|
||||
bytes data = 4 [(fixed_array_size) = 62];
|
||||
}
|
||||
|
||||
message BluetoothLERawAdvertisementsResponse {
|
||||
|
@@ -26,4 +26,5 @@ extend google.protobuf.MessageOptions {
|
||||
|
||||
extend google.protobuf.FieldOptions {
|
||||
optional string field_ifdef = 1042;
|
||||
optional uint32 fixed_array_size = 50007;
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "api_pb2.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace esphome {
|
||||
namespace api {
|
||||
@@ -1916,13 +1917,15 @@ void BluetoothLERawAdvertisement::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_uint64(1, this->address);
|
||||
buffer.encode_sint32(2, this->rssi);
|
||||
buffer.encode_uint32(3, this->address_type);
|
||||
buffer.encode_bytes(4, reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size());
|
||||
buffer.encode_bytes(4, this->data, this->data_len);
|
||||
}
|
||||
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);
|
||||
ProtoSize::add_string_field(total_size, 1, this->data);
|
||||
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) {
|
||||
|
@@ -1768,7 +1768,8 @@ class BluetoothLERawAdvertisement : public ProtoMessage {
|
||||
uint64_t address{0};
|
||||
int32_t rssi{0};
|
||||
uint32_t address_type{0};
|
||||
std::string data{};
|
||||
uint8_t data[62]{};
|
||||
uint8_t data_len{0};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
|
@@ -3132,7 +3132,7 @@ void BluetoothLERawAdvertisement::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" data: ");
|
||||
out.append(format_hex_pretty(this->data));
|
||||
out.append(format_hex_pretty(this->data, this->data_len));
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user