1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-13 15:23:49 +01:00

just store key in flash

This commit is contained in:
J. Nick Koston
2025-10-07 14:54:28 -05:00
parent 9cecbee33a
commit cf1ba30e90
7 changed files with 8 additions and 8 deletions

View File

@@ -193,7 +193,7 @@ void MDNSComponent::dump_config() {
ESP_LOGV(TAG, " - %s, %s, %d", service.service_type.c_str(), service.proto.c_str(), ESP_LOGV(TAG, " - %s, %s, %d", service.service_type.c_str(), service.proto.c_str(),
const_cast<TemplatableValue<uint16_t> &>(service.port).value()); const_cast<TemplatableValue<uint16_t> &>(service.port).value());
for (const auto &record : service.txt_records) { for (const auto &record : service.txt_records) {
ESP_LOGV(TAG, " TXT: %s = %s", record.key.c_str(), ESP_LOGV(TAG, " TXT: %s = %s", record.key,
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str()); const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
} }
} }

View File

@@ -13,7 +13,7 @@ namespace mdns {
// MDNS_SERVICE_COUNT will always be defined // MDNS_SERVICE_COUNT will always be defined
struct MDNSTXTRecord { struct MDNSTXTRecord {
std::string key; const char *key;
TemplatableValue<std::string> value; TemplatableValue<std::string> value;
}; };

View File

@@ -29,8 +29,8 @@ void MDNSComponent::setup() {
std::vector<mdns_txt_item_t> txt_records; std::vector<mdns_txt_item_t> txt_records;
for (const auto &record : service.txt_records) { for (const auto &record : service.txt_records) {
mdns_txt_item_t it{}; mdns_txt_item_t it{};
// key is a persistent string in services_, no need to strdup // key is a compile-time string literal in flash, no need to strdup
it.key = record.key.c_str(); it.key = record.key;
// value is a temporary from TemplatableValue, must strdup to keep it alive // value is a temporary from TemplatableValue, must strdup to keep it alive
it.value = strdup(const_cast<TemplatableValue<std::string> &>(record.value).value().c_str()); it.value = strdup(const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
txt_records.push_back(it); txt_records.push_back(it);

View File

@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value(); uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
MDNS.addService(service_type, proto, port); MDNS.addService(service_type, proto, port);
for (const auto &record : service.txt_records) { for (const auto &record : service.txt_records) {
MDNS.addServiceTxt(service_type, proto, record.key.c_str(), MDNS.addServiceTxt(service_type, proto, record.key,
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str()); const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
} }
} }

View File

@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
uint16_t port_ = const_cast<TemplatableValue<uint16_t> &>(service.port).value(); uint16_t port_ = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
MDNS.addService(service_type, proto, port_); MDNS.addService(service_type, proto, port_);
for (const auto &record : service.txt_records) { for (const auto &record : service.txt_records) {
MDNS.addServiceTxt(service_type, proto, record.key.c_str(), MDNS.addServiceTxt(service_type, proto, record.key,
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str()); const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
} }
} }

View File

@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value(); uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
MDNS.addService(service_type, proto, port); MDNS.addService(service_type, proto, port);
for (const auto &record : service.txt_records) { for (const auto &record : service.txt_records) {
MDNS.addServiceTxt(service_type, proto, record.key.c_str(), MDNS.addServiceTxt(service_type, proto, record.key,
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str()); const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
} }
} }

View File

@@ -181,7 +181,7 @@ void OpenThreadSrpComponent::setup() {
for (size_t i = 0; i < service.txt_records.size(); i++) { for (size_t i = 0; i < service.txt_records.size(); i++) {
const auto &txt = service.txt_records[i]; const auto &txt = service.txt_records[i];
auto value = const_cast<TemplatableValue<std::string> &>(txt.value).value(); auto value = const_cast<TemplatableValue<std::string> &>(txt.value).value();
txt_entries[i].mKey = strdup(txt.key.c_str()); txt_entries[i].mKey = txt.key; // Compile-time string literal in flash
txt_entries[i].mValue = reinterpret_cast<const uint8_t *>(strdup(value.c_str())); txt_entries[i].mValue = reinterpret_cast<const uint8_t *>(strdup(value.c_str()));
txt_entries[i].mValueLength = value.size(); txt_entries[i].mValueLength = value.size();
} }