1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 08:41:59 +00:00

[packet_transport] Fix packet size check to account for round4 padding (#13165)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-01-12 14:10:15 -05:00
committed by GitHub
parent c50bf45496
commit f9ffd134df

View File

@@ -274,7 +274,7 @@ void PacketTransport::flush_() {
void PacketTransport::add_binary_data_(uint8_t key, const char *id, bool data) {
auto len = 1 + 1 + 1 + strlen(id);
if (len + this->header_.size() + this->data_.size() > this->get_max_packet_size()) {
if (round4(this->header_.size()) + round4(this->data_.size() + len) > this->get_max_packet_size()) {
this->flush_();
this->init_data_();
}
@@ -289,7 +289,7 @@ void PacketTransport::add_data_(uint8_t key, const char *id, float data) {
void PacketTransport::add_data_(uint8_t key, const char *id, uint32_t data) {
auto len = 4 + 1 + 1 + strlen(id);
if (len + this->header_.size() + this->data_.size() > this->get_max_packet_size()) {
if (round4(this->header_.size()) + round4(this->data_.size() + len) > this->get_max_packet_size()) {
this->flush_();
this->init_data_();
}