From 5ebce4a901f18ee93398308df4f04acfe5681974 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 26 Jul 2025 15:01:45 -1000 Subject: [PATCH] dry --- esphome/components/api/proto.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 63fdcce126..bfca80960f 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -513,14 +513,9 @@ class ProtoSize { * @brief Calculates and adds the size of an int32 field to the total message size (force version) */ inline void add_int32_force(uint32_t field_id_size, int32_t value) { - // Always calculate size when force is true - if (value < 0) { - // Negative values are encoded as 10-byte varints in protobuf - total_size_ += field_id_size + 10; - } else { - // For non-negative values, use the standard varint size - total_size_ += field_id_size + varint(static_cast(value)); - } + // Always calculate size when forced + // Negative values are encoded as 10-byte varints in protobuf + total_size_ += field_id_size + (value < 0 ? 10 : varint(static_cast(value))); } /**