From 5e906b1dd935fd8ffefade1e46aebc1568022863 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 20 Jul 2025 20:06:50 -1000 Subject: [PATCH] cleanup --- esphome/components/api/api_pb2_dump.cpp | 6 +++--- script/api_protobuf/api_protobuf.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 7eb0da6a6f..bf4ca5e402 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -1679,7 +1679,7 @@ void NoiseEncryptionSetKeyRequest::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("NoiseEncryptionSetKeyRequest {\n"); out.append(" key: "); - out.append(format_hex_pretty(this->key_ptr_, this->key_len_)); + out.append(format_hex_pretty(reinterpret_cast(this->key.data()), this->key.size())); out.append("\n"); out.append("}"); } @@ -3163,7 +3163,7 @@ void BluetoothGATTWriteRequest::dump_to(std::string &out) const { out.append("\n"); out.append(" data: "); - out.append(format_hex_pretty(this->data_ptr_, this->data_len_)); + out.append(format_hex_pretty(reinterpret_cast(this->data.data()), this->data.size())); out.append("\n"); out.append("}"); } @@ -3195,7 +3195,7 @@ void BluetoothGATTWriteDescriptorRequest::dump_to(std::string &out) const { out.append("\n"); out.append(" data: "); - out.append(format_hex_pretty(this->data_ptr_, this->data_len_)); + out.append(format_hex_pretty(reinterpret_cast(this->data.data()), this->data.size())); out.append("\n"); out.append("}"); } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index b23f788256..298f0a6d18 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -657,7 +657,11 @@ class BytesType(TypeInfo): return f"buffer.encode_bytes({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);" def dump(self, name: str) -> str: - return f"out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));" + # Use pointer/length if available (SOURCE_SERVER/SOURCE_BOTH), otherwise use std::string + if self.needs_encode: + return f"out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));" + else: + return f"out.append(format_hex_pretty(reinterpret_cast(this->{self.field_name}.data()), this->{self.field_name}.size()));" def get_size_calculation(self, name: str, force: bool = False) -> str: return f"ProtoSize::add_bytes_field(total_size, {self.calculate_field_id_size()}, this->{self.field_name}_len_);"