15#define ESPHOME_F(string_literal) F(string_literal)
16#define ESPHOME_PGM_P PGM_P
17#define ESPHOME_PSTR(s) PSTR(s)
18#define ESPHOME_strncpy_P strncpy_P
19#define ESPHOME_strncat_P strncat_P
20#define ESPHOME_snprintf_P snprintf_P
21#define ESPHOME_strcmp_P strcmp_P
22#define ESPHOME_strcasecmp_P strcasecmp_P
23#define ESPHOME_strncmp_P strncmp_P
24#define ESPHOME_strncasecmp_P strncasecmp_P
28#define ESPHOME_F(string_literal) (string_literal)
29#define ESPHOME_PGM_P const char *
30#define ESPHOME_PSTR(s) (s)
31#define ESPHOME_strncpy_P strncpy
32#define ESPHOME_strncat_P strncat
33#define ESPHOME_snprintf_P snprintf
34#define ESPHOME_strcmp_P strcmp
35#define ESPHOME_strcasecmp_P strcasecmp
36#define ESPHOME_strncmp_P strncmp
37#define ESPHOME_strncasecmp_P strncasecmp
48 for (
size_t i = 0; i < N; ++i)
51 constexpr size_t size()
const {
return N - 1; }
63 static constexpr size_t COUNT =
sizeof...(Strs);
64 static constexpr size_t BLOB_SIZE = (0 + ... + (Strs.size() + 1));
68 std::array<char, BLOB_SIZE> result{};
70 auto copy = [&](
const auto &str) {
71 for (
size_t i = 0; i <= str.size(); ++i)
72 result[
pos++] = str.data[i];
80 static_assert(
COUNT > 0,
"PROGMEM_STRING_TABLE must contain at least one string");
81 static_assert(
COUNT <= 255,
"PROGMEM_STRING_TABLE supports at most 255 strings with uint8_t indices");
82 static_assert(
BLOB_SIZE <= 255,
"PROGMEM_STRING_TABLE blob exceeds 255 bytes; use fewer/shorter strings");
83 std::array<uint8_t, COUNT> result{};
84 size_t pos = 0, idx = 0;
85 ((result[idx++] =
static_cast<uint8_t
>(
pos),
pos += Strs.size() + 1), ...);
96#define PROGMEM_STRING_TABLE(Name, ...) \
98 using Table = ::esphome::ProgmemStringTable<__VA_ARGS__>; \
99 static constexpr size_t COUNT = Table::COUNT; \
100 static constexpr uint8_t LAST_INDEX = COUNT - 1; \
101 static constexpr size_t BLOB_SIZE = Table::BLOB_SIZE; \
102 static constexpr auto BLOB PROGMEM = Table::make_blob(); \
103 static constexpr auto OFFSETS PROGMEM = Table::make_offsets(); \
104 static const char *get_(uint8_t idx, uint8_t fallback) { \
107 return &BLOB[::esphome::progmem_read_byte(&OFFSETS[idx])]; \
109 static ::ProgmemStr get_progmem_str(uint8_t idx, uint8_t fallback) { \
110 return reinterpret_cast<::ProgmemStr>(get_(idx, fallback)); \
112 static const ::esphome::LogString *get_log_str(uint8_t idx, uint8_t fallback) { \
113 return reinterpret_cast<const ::esphome::LogString *>(get_(idx, fallback)); \
Providing packet encoding functions for exchanging data with a remote host.
const __FlashStringHelper * ProgmemStr
Helper for C++20 string literal template arguments.
constexpr size_t size() const
constexpr FixedString(const char(&str)[N])
Compile-time string table that packs strings into a single blob with offset lookup.
static constexpr size_t COUNT
static constexpr size_t BLOB_SIZE
static constexpr auto make_blob()
Generate packed string blob at compile time.
static constexpr auto make_offsets()
Generate offset table at compile time (uint8_t limits blob to 255 bytes)