mirror of
https://github.com/esphome/esphome.git
synced 2025-09-11 07:42:26 +01:00
Ensure we can send batches where the first message exceeds MAX_PACKET_SIZE
This commit is contained in:
@@ -1791,7 +1791,7 @@ void APIConnection::process_batch_() {
|
|||||||
this->batch_first_message_ = true;
|
this->batch_first_message_ = true;
|
||||||
|
|
||||||
size_t items_processed = 0;
|
size_t items_processed = 0;
|
||||||
uint32_t remaining_size = MAX_PACKET_SIZE;
|
uint32_t remaining_size = std::numeric_limits<uint16_t>::max();
|
||||||
|
|
||||||
// Track where each message's header padding begins in the buffer
|
// Track where each message's header padding begins in the buffer
|
||||||
// For plaintext: this is where the 6-byte header padding starts
|
// For plaintext: this is where the 6-byte header padding starts
|
||||||
@@ -1816,11 +1816,15 @@ void APIConnection::process_batch_() {
|
|||||||
packet_info.emplace_back(item.message_type, current_offset, proto_payload_size);
|
packet_info.emplace_back(item.message_type, current_offset, proto_payload_size);
|
||||||
|
|
||||||
// Update tracking variables
|
// Update tracking variables
|
||||||
|
items_processed++;
|
||||||
|
// After first message, set remaining size to MAX_PACKET_SIZE to avoid fragmentation
|
||||||
|
if (items_processed == 1) {
|
||||||
|
remaining_size = MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
remaining_size -= payload_size;
|
remaining_size -= payload_size;
|
||||||
// Calculate where the next message's header padding will start
|
// Calculate where the next message's header padding will start
|
||||||
// Current buffer size + footer space (that prepare_message_buffer will add for this message)
|
// Current buffer size + footer space (that prepare_message_buffer will add for this message)
|
||||||
current_offset = this->parent_->get_shared_buffer_ref().size() + footer_size;
|
current_offset = this->parent_->get_shared_buffer_ref().size() + footer_size;
|
||||||
items_processed++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items_processed == 0) {
|
if (items_processed == 0) {
|
||||||
|
Reference in New Issue
Block a user