From 1ef6c6a4166338fcde69ee78bccc7e5c56a954a2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 4 Jan 2026 12:46:35 -1000 Subject: [PATCH] move const --- esphome/components/api/api_connection.h | 5 +---- esphome/components/api/api_frame_helper.h | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 088939fb71..cffd52bfdb 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -28,10 +28,7 @@ static constexpr uint32_t KEEPALIVE_TIMEOUT_MS = 60000; // TODO: Remove MAX_INITIAL_PER_BATCH_LEGACY before 2026.7.0 - all clients should support API 1.14 by then static constexpr size_t MAX_INITIAL_PER_BATCH_LEGACY = 24; // For clients < API 1.14 (includes object_id) static constexpr size_t MAX_INITIAL_PER_BATCH = 34; // For clients >= API 1.14 (no object_id) -// Maximum number of messages to process in a single batch -// This limit exists to prevent stack overflow from the MessageInfo/iovec arrays in process_batch_ -// Each MessageInfo is 6 bytes, each iovec is 8 bytes: 34 * (6 + 8) = 476 bytes -static constexpr size_t MAX_MESSAGES_PER_BATCH = 34; +// Verify MAX_MESSAGES_PER_BATCH (defined in api_frame_helper.h) can hold the initial batch static_assert(MAX_MESSAGES_PER_BATCH >= MAX_INITIAL_PER_BATCH, "MAX_MESSAGES_PER_BATCH must be >= MAX_INITIAL_PER_BATCH"); diff --git a/esphome/components/api/api_frame_helper.h b/esphome/components/api/api_frame_helper.h index c796b2e987..383e763e6d 100644 --- a/esphome/components/api/api_frame_helper.h +++ b/esphome/components/api/api_frame_helper.h @@ -29,6 +29,10 @@ static constexpr uint16_t MAX_MESSAGE_SIZE = 8192; // 8 KiB for ESP8266 static constexpr uint16_t MAX_MESSAGE_SIZE = 32768; // 32 KiB for ESP32 and other platforms #endif +// Maximum number of messages to batch in a single write operation +// Must be >= MAX_INITIAL_PER_BATCH in api_connection.h (enforced by static_assert there) +static constexpr size_t MAX_MESSAGES_PER_BATCH = 34; + // Forward declaration struct ClientInfo;