♻️ Replaces JsonObject with JsonVariant
This commit is contained in:
@@ -18,12 +18,12 @@ typedef struct {
|
||||
String key;
|
||||
String value;
|
||||
|
||||
void serialize(JsonObject &json) const {
|
||||
void serialize(JsonVariant &json) const {
|
||||
json["key"] = key;
|
||||
json["value"] = value;
|
||||
}
|
||||
|
||||
bool deserialize(const JsonObject &json) {
|
||||
bool deserialize(const JsonVariant &json) {
|
||||
key = json["key"].as<String>();
|
||||
value = json["value"].as<String>();
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef struct {
|
||||
uint16_t port;
|
||||
std::vector<mdns_txt_record_t> txtRecords;
|
||||
|
||||
void serialize(JsonObject &json) const {
|
||||
void serialize(JsonVariant &json) const {
|
||||
json["service"] = service;
|
||||
json["protocol"] = protocol;
|
||||
json["port"] = port;
|
||||
@@ -45,13 +45,13 @@ typedef struct {
|
||||
if (txtRecords.size() > 0) {
|
||||
JsonArray txtArray = json["txt_records"].to<JsonArray>();
|
||||
for (const auto &txt : txtRecords) {
|
||||
JsonObject txtObj = txtArray.add<JsonObject>();
|
||||
JsonVariant txtObj = txtArray.add<JsonVariant>();
|
||||
txt.serialize(txtObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool deserialize(const JsonObject &json) {
|
||||
bool deserialize(const JsonVariant &json) {
|
||||
service = json["service"].as<String>();
|
||||
protocol = json["protocol"].as<String>();
|
||||
port = json["port"] | 0;
|
||||
@@ -59,7 +59,7 @@ typedef struct {
|
||||
txtRecords.clear();
|
||||
if (json["txt_records"].is<JsonArray>()) {
|
||||
JsonArray txtArray = json["txt_records"];
|
||||
for (JsonObject txtObj : txtArray) {
|
||||
for (JsonVariant txtObj : txtArray) {
|
||||
mdns_txt_record_t txt;
|
||||
if (txt.deserialize(txtObj)) {
|
||||
txtRecords.push_back(txt);
|
||||
@@ -78,31 +78,31 @@ class MDNSSettings {
|
||||
std::vector<mdns_service_t> services;
|
||||
std::vector<mdns_txt_record_t> globalTxtRecords;
|
||||
|
||||
static void read(MDNSSettings &settings, JsonObject &root) {
|
||||
static void read(MDNSSettings &settings, JsonVariant &root) {
|
||||
root["hostname"] = settings.hostname;
|
||||
root["instance"] = settings.instance;
|
||||
|
||||
JsonArray servicesArray = root["services"].to<JsonArray>();
|
||||
for (const auto &service : settings.services) {
|
||||
JsonObject serviceObj = servicesArray.add<JsonObject>();
|
||||
JsonVariant serviceObj = servicesArray.add<JsonVariant>();
|
||||
service.serialize(serviceObj);
|
||||
}
|
||||
|
||||
JsonArray txtArray = root["global_txt_records"].to<JsonArray>();
|
||||
for (const auto &txt : settings.globalTxtRecords) {
|
||||
JsonObject txtObj = txtArray.add<JsonObject>();
|
||||
JsonVariant txtObj = txtArray.add<JsonVariant>();
|
||||
txt.serialize(txtObj);
|
||||
}
|
||||
}
|
||||
|
||||
static StateUpdateResult update(JsonObject &root, MDNSSettings &settings) {
|
||||
static StateUpdateResult update(JsonVariant &root, MDNSSettings &settings) {
|
||||
settings.hostname = root["hostname"] | FACTORY_MDNS_HOSTNAME;
|
||||
settings.instance = root["instance"] | FACTORY_MDNS_INSTANCE;
|
||||
|
||||
settings.services.clear();
|
||||
if (root["services"].is<JsonArray>()) {
|
||||
JsonArray servicesArray = root["services"];
|
||||
for (JsonObject serviceObj : servicesArray) {
|
||||
for (JsonVariant serviceObj : servicesArray) {
|
||||
mdns_service_t service;
|
||||
if (service.deserialize(serviceObj)) {
|
||||
settings.services.push_back(service);
|
||||
@@ -121,7 +121,7 @@ class MDNSSettings {
|
||||
settings.globalTxtRecords.clear();
|
||||
if (root["global_txt_records"].is<JsonArray>()) {
|
||||
JsonArray txtArray = root["global_txt_records"];
|
||||
for (JsonObject txtObj : txtArray) {
|
||||
for (JsonVariant txtObj : txtArray) {
|
||||
mdns_txt_record_t txt;
|
||||
if (txt.deserialize(txtObj)) {
|
||||
settings.globalTxtRecords.push_back(txt);
|
||||
|
||||
Reference in New Issue
Block a user