optimize ArduinoJson serialization: avoid copies of strings
This commit is contained in:
parent
baa3d2d0b8
commit
fe8b33df72
10
src/ha.h
10
src/ha.h
@ -88,7 +88,7 @@ namespace Ha {
|
|||||||
const char* entityCategory = nullptr;
|
const char* entityCategory = nullptr;
|
||||||
const char* deviceClass = nullptr;
|
const char* deviceClass = nullptr;
|
||||||
const char* name = nullptr;
|
const char* name = nullptr;
|
||||||
char* id = nullptr;
|
const char* id = nullptr;
|
||||||
const char* type = nullptr;
|
const char* type = nullptr;
|
||||||
char configTopic[TOPIC_SIZE];
|
char configTopic[TOPIC_SIZE];
|
||||||
JsonPairs<bool> jsonBooleans;
|
JsonPairs<bool> jsonBooleans;
|
||||||
@ -98,7 +98,7 @@ namespace Ha {
|
|||||||
static List<Component> components;
|
static List<Component> components;
|
||||||
bool multiValueComponent = false;
|
bool multiValueComponent = false;
|
||||||
|
|
||||||
Component(const char* name, const char* id, const char* type) : name(name), id((char*)id), type(type) {
|
Component(const char* name, const char* id, const char* type) : name(name), id(id), type(type) {
|
||||||
components.add(this);
|
components.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ namespace Ha {
|
|||||||
if (deviceClass) jsonDoc["device_class"] = deviceClass;
|
if (deviceClass) jsonDoc["device_class"] = deviceClass;
|
||||||
jsonDoc["name"] = name;
|
jsonDoc["name"] = name;
|
||||||
buildUniqueId();
|
buildUniqueId();
|
||||||
jsonDoc["unique_id"] = uniqueId;
|
jsonDoc["unique_id"] = (const char*)uniqueId;
|
||||||
buildConfigTopic();
|
buildConfigTopic();
|
||||||
|
|
||||||
buildComponentConfig(jsonDoc);
|
buildComponentConfig(jsonDoc);
|
||||||
@ -276,7 +276,7 @@ namespace Ha {
|
|||||||
virtual void buildCommandConfig(JsonDocument& jsonDoc) = 0;
|
virtual void buildCommandConfig(JsonDocument& jsonDoc) = 0;
|
||||||
|
|
||||||
void buildComponentConfig(JsonDocument& jsonDoc) override {
|
void buildComponentConfig(JsonDocument& jsonDoc) override {
|
||||||
jsonDoc["command_topic"] = commandTopic;
|
jsonDoc["command_topic"] = (const char*)commandTopic;
|
||||||
if (retain) jsonDoc["retain"] = true;
|
if (retain) jsonDoc["retain"] = true;
|
||||||
buildCommandConfig(jsonDoc);
|
buildCommandConfig(jsonDoc);
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ namespace Ha {
|
|||||||
protected:
|
protected:
|
||||||
Component* cmp;
|
Component* cmp;
|
||||||
void buildConfig(JsonDocument& jsonDoc) {
|
void buildConfig(JsonDocument& jsonDoc) {
|
||||||
if (stateTopic[0]) jsonDoc["state_topic"] = stateTopic;
|
if (stateTopic[0]) jsonDoc["state_topic"] = (const char*)stateTopic;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user