1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 13:22:19 +01:00
This commit is contained in:
J. Nick Koston
2025-07-20 20:07:30 -10:00
parent 5e906b1dd9
commit b24ff7236e
2 changed files with 20 additions and 5 deletions

View File

@@ -3485,7 +3485,11 @@ void VoiceAssistantAudio::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64]; __attribute__((unused)) char buffer[64];
out.append("VoiceAssistantAudio {\n"); out.append("VoiceAssistantAudio {\n");
out.append(" data: "); out.append(" data: ");
out.append(format_hex_pretty(this->data_ptr_, this->data_len_)); if (this->data_ptr_ != nullptr) {
out.append(format_hex_pretty(this->data_ptr_, this->data_len_));
} else {
out.append(format_hex_pretty(reinterpret_cast<const uint8_t *>(this->data.data()), this->data.size()));
}
out.append("\n"); out.append("\n");
out.append(" end: "); out.append(" end: ");

View File

@@ -657,12 +657,23 @@ class BytesType(TypeInfo):
return f"buffer.encode_bytes({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);" return f"buffer.encode_bytes({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);"
def dump(self, name: str) -> str: def dump(self, name: str) -> str:
# Use pointer/length if available (SOURCE_SERVER/SOURCE_BOTH), otherwise use std::string # For SOURCE_CLIENT only, always use std::string
if self.needs_encode: if not 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<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size()));" return f"out.append(format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size()));"
# For SOURCE_SERVER, always use pointer/length
if not self.needs_decode:
return f"out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));"
# For SOURCE_BOTH, check if pointer is set (sending) or use string (received)
return (
f"if (this->{self.field_name}_ptr_ != nullptr) {{\n"
f" out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));\n"
f" }} else {{\n"
f" out.append(format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size()));\n"
f" }}"
)
def get_size_calculation(self, name: str, force: bool = False) -> str: 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_);" return f"ProtoSize::add_bytes_field(total_size, {self.calculate_field_id_size()}, this->{self.field_name}_len_);"