diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index f12141e197a..4e0663d7f48 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -2033,8 +2033,7 @@ uint16_t APIConnection::encode_to_buffer(uint32_t calculated_size, MessageEncode // Batch message second or later // Reserve for full message, resize to include footer gap + header padding + payload size_t current_size = shared_buf.size(); - shared_buf.reserve_and_resize(current_size + total_calculated_size, - current_size + footer_size + header_padding + calculated_size); + shared_buf.resize(current_size + total_calculated_size); write_start = shared_buf.size() - calculated_size; } @@ -2042,7 +2041,7 @@ uint16_t APIConnection::encode_to_buffer(uint32_t calculated_size, MessageEncode encode_fn(msg, buffer); // Return total size (header + payload + footer) - return static_cast(header_padding + calculated_size + footer_size); + return static_cast(total_calculated_size); } bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) { const bool is_log_message = (message_type == SubscribeLogsResponse::MESSAGE_TYPE);