From 65b32731d4250ad9f8f6492ee580c5078d126c5e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 12 Oct 2026 16:53:23 -1000 Subject: [PATCH] Keep the ESP8266 short string encode on the shared progmem copy --- esphome/components/api/proto.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index e01deccbc21..f8e9dae09a6 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -409,6 +409,10 @@ class ProtoEncode { /// Tag must be a single-byte varint (< 128). Always encodes (no zero check). [[nodiscard]] static inline uint8_t *encode_short_string_force(uint8_t *__restrict__ pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const StringRef &ref) { +#ifdef USE_ESP8266 + // memcpy_P reads RAM too, and sharing the progmem copy is smaller than an inline memcpy + return encode_short_progmem_string_force(pos PROTO_ENCODE_DEBUG_ARG, tag, ProgmemStringRef(ref)); +#else #ifdef ESPHOME_DEBUG_API assert(ref.size() < 128 && "encode_short_string_force: string exceeds max_data_length < 128"); #endif @@ -417,6 +421,7 @@ class ProtoEncode { pos[1] = static_cast(ref.size()); std::memcpy(pos + 2, ref.c_str(), ref.size()); return pos + 2 + ref.size(); +#endif } /// encode_short_string_force for a string that may be in flash (PROGMEM). [[nodiscard]] static inline uint8_t *encode_short_progmem_string_force(