diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 6cbe887c2e..29121f05e0 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -28,6 +28,12 @@ static inline void append_with_newline(DumpBuffer &out, const char *str) { out.append("\n"); } +static inline void append_uint(DumpBuffer &out, uint32_t value) { + char buf[16]; + snprintf(buf, sizeof(buf), "%" PRIu32, value); + out.append(buf); +} + // RAII helper for message dump formatting class MessageDumpHelper { public: @@ -2484,9 +2490,9 @@ const char *InfraredRFTransmitRawTimingsRequest::dump_to(DumpBuffer &out) const dump_field(out, "repeat_count", this->repeat_count); out.append(" timings: "); out.append("packed buffer ["); - out.append(std::to_string(this->timings_count_)); + append_uint(out, this->timings_count_); out.append(" values, "); - out.append(std::to_string(this->timings_length_)); + append_uint(out, this->timings_length_); out.append(" bytes]\n"); return out.c_str(); } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 8937e1a88a..7625458f9f 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -990,9 +990,9 @@ class PackedBufferTypeInfo(TypeInfo): return ( f'out.append(" {self.name}: ");\n' + 'out.append("packed buffer [");\n' - + f"out.append(std::to_string(this->{self.field_name}_count_));\n" + + f"append_uint(out, this->{self.field_name}_count_);\n" + 'out.append(" values, ");\n' - + f"out.append(std::to_string(this->{self.field_name}_length_));\n" + + f"append_uint(out, this->{self.field_name}_length_);\n" + 'out.append(" bytes]\\n");' ) @@ -2604,6 +2604,12 @@ static inline void append_with_newline(DumpBuffer &out, const char *str) { out.append("\\n"); } +static inline void append_uint(DumpBuffer &out, uint32_t value) { + char buf[16]; + snprintf(buf, sizeof(buf), "%" PRIu32, value); + out.append(buf); +} + // RAII helper for message dump formatting class MessageDumpHelper { public: