mirror of
https://github.com/esphome/esphome.git
synced 2025-10-19 10:13:49 +01:00
[mdns] Use FixedVector for txt_records to reduce flash usage (#11228)
This commit is contained in:
@@ -83,7 +83,7 @@ void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUN
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto &txt_records = service.txt_records;
|
auto &txt_records = service.txt_records;
|
||||||
txt_records.reserve(txt_count);
|
txt_records.init(txt_count);
|
||||||
|
|
||||||
if (!friendly_name_empty) {
|
if (!friendly_name_empty) {
|
||||||
txt_records.push_back({MDNS_STR(TXT_FRIENDLY_NAME), MDNS_STR(friendly_name.c_str())});
|
txt_records.push_back({MDNS_STR(TXT_FRIENDLY_NAME), MDNS_STR(friendly_name.c_str())});
|
||||||
@@ -171,12 +171,7 @@ void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUN
|
|||||||
fallback_service.service_type = MDNS_STR(SERVICE_HTTP);
|
fallback_service.service_type = MDNS_STR(SERVICE_HTTP);
|
||||||
fallback_service.proto = MDNS_STR(SERVICE_TCP);
|
fallback_service.proto = MDNS_STR(SERVICE_TCP);
|
||||||
fallback_service.port = USE_WEBSERVER_PORT;
|
fallback_service.port = USE_WEBSERVER_PORT;
|
||||||
fallback_service.txt_records.push_back({MDNS_STR(TXT_VERSION), MDNS_STR(VALUE_VERSION)});
|
fallback_service.txt_records = {{MDNS_STR(TXT_VERSION), MDNS_STR(VALUE_VERSION)}};
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_MDNS_STORE_SERVICES
|
|
||||||
// Copy to member variable if storage is enabled (verbose logging, OpenThread, or extra services)
|
|
||||||
this->services_ = services;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ struct MDNSService {
|
|||||||
// as defined in RFC6763 Section 7, like "_tcp" or "_udp"
|
// as defined in RFC6763 Section 7, like "_tcp" or "_udp"
|
||||||
const MDNSString *proto;
|
const MDNSString *proto;
|
||||||
TemplatableValue<uint16_t> port;
|
TemplatableValue<uint16_t> port;
|
||||||
std::vector<MDNSTXTRecord> txt_records;
|
FixedVector<MDNSTXTRecord> txt_records;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MDNSComponent : public Component {
|
class MDNSComponent : public Component {
|
||||||
|
@@ -12,8 +12,13 @@ namespace mdns {
|
|||||||
static const char *const TAG = "mdns";
|
static const char *const TAG = "mdns";
|
||||||
|
|
||||||
void MDNSComponent::setup() {
|
void MDNSComponent::setup() {
|
||||||
|
#ifdef USE_MDNS_STORE_SERVICES
|
||||||
|
this->compile_records_(this->services_);
|
||||||
|
const auto &services = this->services_;
|
||||||
|
#else
|
||||||
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
||||||
this->compile_records_(services);
|
this->compile_records_(services);
|
||||||
|
#endif
|
||||||
|
|
||||||
esp_err_t err = mdns_init();
|
esp_err_t err = mdns_init();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
|
@@ -12,8 +12,13 @@ namespace esphome {
|
|||||||
namespace mdns {
|
namespace mdns {
|
||||||
|
|
||||||
void MDNSComponent::setup() {
|
void MDNSComponent::setup() {
|
||||||
|
#ifdef USE_MDNS_STORE_SERVICES
|
||||||
|
this->compile_records_(this->services_);
|
||||||
|
const auto &services = this->services_;
|
||||||
|
#else
|
||||||
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
||||||
this->compile_records_(services);
|
this->compile_records_(services);
|
||||||
|
#endif
|
||||||
|
|
||||||
MDNS.begin(this->hostname_.c_str());
|
MDNS.begin(this->hostname_.c_str());
|
||||||
|
|
||||||
|
@@ -12,8 +12,13 @@ namespace esphome {
|
|||||||
namespace mdns {
|
namespace mdns {
|
||||||
|
|
||||||
void MDNSComponent::setup() {
|
void MDNSComponent::setup() {
|
||||||
|
#ifdef USE_MDNS_STORE_SERVICES
|
||||||
|
this->compile_records_(this->services_);
|
||||||
|
const auto &services = this->services_;
|
||||||
|
#else
|
||||||
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
||||||
this->compile_records_(services);
|
this->compile_records_(services);
|
||||||
|
#endif
|
||||||
|
|
||||||
MDNS.begin(this->hostname_.c_str());
|
MDNS.begin(this->hostname_.c_str());
|
||||||
|
|
||||||
|
@@ -12,8 +12,13 @@ namespace esphome {
|
|||||||
namespace mdns {
|
namespace mdns {
|
||||||
|
|
||||||
void MDNSComponent::setup() {
|
void MDNSComponent::setup() {
|
||||||
|
#ifdef USE_MDNS_STORE_SERVICES
|
||||||
|
this->compile_records_(this->services_);
|
||||||
|
const auto &services = this->services_;
|
||||||
|
#else
|
||||||
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
|
||||||
this->compile_records_(services);
|
this->compile_records_(services);
|
||||||
|
#endif
|
||||||
|
|
||||||
MDNS.begin(this->hostname_.c_str());
|
MDNS.begin(this->hostname_.c_str());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user