mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	preen
This commit is contained in:
		| @@ -282,19 +282,20 @@ uint16_t APIConnection::encode_message_to_buffer(ProtoMessage &msg, uint8_t mess | |||||||
|   const uint8_t footer_size = conn->helper_->frame_footer_size(); |   const uint8_t footer_size = conn->helper_->frame_footer_size(); | ||||||
|  |  | ||||||
|   // Calculate total size with padding |   // Calculate total size with padding | ||||||
|   size_t total_size = calculated_size + header_padding + footer_size; |   size_t total_calculated_size = calculated_size + header_padding + footer_size; | ||||||
|  |  | ||||||
|   // Check if it fits |   // Check if it fits | ||||||
|   if (total_size > remaining_size) { |   if (total_calculated_size > remaining_size) { | ||||||
|     return 0;  // Doesn't fit |     return 0;  // Doesn't fit | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Get buffer and prepare it inline |   // Get buffer and prepare it inline | ||||||
|   std::vector<uint8_t> &shared_buf = conn->parent_->get_shared_buffer_ref(); |   std::vector<uint8_t> &shared_buf = conn->parent_->get_shared_buffer_ref(); | ||||||
|  |   size_t size_before_encode = shared_buf.size(); | ||||||
|  |  | ||||||
|   if (is_single || conn->flags_.batch_first_message) { |   if (is_single || conn->flags_.batch_first_message) { | ||||||
|     // Single message or first batch message |     // Single message or first batch message | ||||||
|     conn->prepare_first_message_buffer(shared_buf, header_padding, total_size); |     conn->prepare_first_message_buffer(shared_buf, header_padding, total_calculated_size); | ||||||
|     if (conn->flags_.batch_first_message) { |     if (conn->flags_.batch_first_message) { | ||||||
|       conn->flags_.batch_first_message = false; |       conn->flags_.batch_first_message = false; | ||||||
|     } |     } | ||||||
| @@ -302,13 +303,12 @@ uint16_t APIConnection::encode_message_to_buffer(ProtoMessage &msg, uint8_t mess | |||||||
|     // Batch message second or later |     // Batch message second or later | ||||||
|     // Add padding for previous message footer + this message header |     // Add padding for previous message footer + this message header | ||||||
|     size_t current_size = shared_buf.size(); |     size_t current_size = shared_buf.size(); | ||||||
|     shared_buf.reserve(current_size + total_size); |     shared_buf.reserve(current_size + total_calculated_size); | ||||||
|     shared_buf.resize(current_size + footer_size + header_padding); |     shared_buf.resize(current_size + footer_size + header_padding); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Encode directly into buffer |   // Encode directly into buffer | ||||||
|   ProtoWriteBuffer buffer{&shared_buf}; |   ProtoWriteBuffer buffer{&shared_buf}; | ||||||
|   size_t size_before_encode = shared_buf.size(); |  | ||||||
|   msg.encode(buffer); |   msg.encode(buffer); | ||||||
|  |  | ||||||
|   // Calculate actual encoded size (not including header that was already added) |   // Calculate actual encoded size (not including header that was already added) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user