From 510c874061cd73ec95afcd26ab4f814463776d9e Mon Sep 17 00:00:00 2001 From: Keith Burzinski Date: Fri, 16 Jan 2026 19:23:41 -0600 Subject: [PATCH] [helpers] Remove `base85` functions (#13266) --- esphome/core/helpers.cpp | 49 ---------------------------------------- esphome/core/helpers.h | 8 ------- 2 files changed, 57 deletions(-) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 5cad2308df..5de1c70562 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -664,55 +664,6 @@ bool base64_decode_int32_vector(const std::string &base64, std::vector return !out.empty(); } -/// Encode int32 to 5 base85 characters + null terminator -/// Standard ASCII85 alphabet: '!' (33) = 0 through 'u' (117) = 84 -inline void base85_encode_int32(int32_t value, std::span output) { - uint32_t v = static_cast(value); - // Encode least significant digit first, then reverse - for (int i = 4; i >= 0; i--) { - output[i] = static_cast('!' + (v % 85)); - v /= 85; - } - output[5] = '\0'; -} - -/// Decode 5 base85 characters to int32 -inline bool base85_decode_int32(const char *input, int32_t &out) { - uint8_t c0 = static_cast(input[0] - '!'); - uint8_t c1 = static_cast(input[1] - '!'); - uint8_t c2 = static_cast(input[2] - '!'); - uint8_t c3 = static_cast(input[3] - '!'); - uint8_t c4 = static_cast(input[4] - '!'); - - // Each digit must be 0-84. Since uint8_t wraps, chars below '!' become > 84 - if (c0 > 84 || c1 > 84 || c2 > 84 || c3 > 84 || c4 > 84) - return false; - - // 85^4 = 52200625, 85^3 = 614125, 85^2 = 7225, 85^1 = 85 - out = static_cast(c0 * 52200625u + c1 * 614125u + c2 * 7225u + c3 * 85u + c4); - return true; -} - -/// Decode base85 string directly into vector (no intermediate buffer) -bool base85_decode_int32_vector(const std::string &base85, std::vector &out) { - size_t len = base85.size(); - if (len % 5 != 0) - return false; - - out.clear(); - const char *ptr = base85.data(); - const char *end = ptr + len; - - while (ptr < end) { - int32_t value; - if (!base85_decode_int32(ptr, value)) - return false; - out.push_back(value); - ptr += 5; - } - return true; -} - // Colors float gamma_correct(float value, float gamma) { diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 000762c9bf..0acc6bdc60 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1143,14 +1143,6 @@ size_t base64_decode(const uint8_t *encoded_data, size_t encoded_len, uint8_t *b /// @return true if successful, false if decode failed or invalid size bool base64_decode_int32_vector(const std::string &base64, std::vector &out); -/// Size of buffer needed for base85 encoded int32 (5 chars + null terminator) -static constexpr size_t BASE85_INT32_ENCODED_SIZE = 6; - -void base85_encode_int32(int32_t value, std::span output); - -bool base85_decode_int32(const char *input, int32_t &out); -bool base85_decode_int32_vector(const std::string &base85, std::vector &out); - ///@} /// @name Colors