From 175c19f29e02447dbcccacf5e8548f63ca8536b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 28 Oct 2025 15:33:45 -0500 Subject: [PATCH] remove dead code --- esphome/components/api/proto.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index aa5c2c073d..c656d19645 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -487,6 +487,34 @@ class ProtoSize { } } + /** + * @brief Calculates the size in bytes needed to encode a uint64_t value as a varint + * + * @param value The uint64_t value to calculate size for + * @return The number of bytes needed to encode the value + */ + static constexpr uint32_t varint(uint64_t value) { + // Most uint64 values fit in uint32 range (field IDs, lengths, etc.) + if (value <= UINT32_MAX) { + return varint(static_cast(value)); + } + + // True 64-bit values (bluetooth addresses, UUIDs) + if (value < (1ULL << 35)) { + return 5; + } else if (value < (1ULL << 42)) { + return 6; + } else if (value < (1ULL << 49)) { + return 7; + } else if (value < (1ULL << 56)) { + return 8; + } else if (value < (1ULL << 63)) { + return 9; + } else { + return 10; + } + } + /** * @brief Calculates the size in bytes needed to encode an int32_t value as a varint *