From be849f0a1aee99b67dcbf6f4988654267e38131e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2026 13:25:04 -0500 Subject: [PATCH] merge --- esphome/components/api/proto.h | 5 ++--- script/api_protobuf/api_protobuf.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 3ff65029e1b..808758aa351 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -844,12 +844,11 @@ class ProtoSize { return field_id_size + varint(value); } /// 48-bit MAC address variant: matches encode_varint_raw_48bit's fast path. - /// When any of the top 6 of 48 bits is set the encoded varint is 7 bytes; + /// When value uses any of bits [42..47] the encoded varint is 7 bytes; /// otherwise fall back to the general size calculation. - /// Caller must guarantee value fits in 48 bits (encoder asserts in debug). static constexpr inline uint32_t ESPHOME_ALWAYS_INLINE calc_uint64_48bit_force(uint32_t field_id_size, uint64_t value) { - return field_id_size + (value >= (1ULL << (MAC_ADDRESS_SIZE * 8 - 6)) ? 7 : varint(value)); + return field_id_size + (value >= (1ULL << 42) ? 7 : varint(value)); } static constexpr uint32_t calc_length(uint32_t field_id_size, size_t len) { return len ? field_id_size + varint(static_cast(len)) + static_cast(len) : 0; diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index bf672d05674..5c4a75c64a1 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -681,10 +681,10 @@ class UInt64Type(VarintTypeMixin, TypeInfo): def RAW_ENCODE_MAP(self) -> dict[str, str]: # noqa: N802 if self.mac_address: return { - **TypeInfo.RAW_ENCODE_MAP, + **super().RAW_ENCODE_MAP, "encode_uint64": "ProtoEncode::encode_varint_raw_48bit(pos, {value});", } - return TypeInfo.RAW_ENCODE_MAP + return super().RAW_ENCODE_MAP def get_estimated_size(self) -> int: return self.calculate_field_id_size() + 3 # field ID + 3 bytes typical varint