1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 07:03:55 +00:00
This commit is contained in:
J. Nick Koston
2025-09-15 21:44:50 -05:00
parent 7549d031fd
commit 7aae946678
2 changed files with 4 additions and 15 deletions

View File

@@ -44,17 +44,6 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks) // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
// JsonBuilder implementation
JsonBuilder::JsonBuilder()
: doc_(
#ifdef USE_PSRAM
&allocator_
#else
nullptr
#endif
) {
}
std::string JsonBuilder::serialize() { std::string JsonBuilder::serialize() {
if (doc_.overflowed()) { if (doc_.overflowed()) {
ESP_LOGE(TAG, "JSON document overflow"); ESP_LOGE(TAG, "JSON document overflow");

View File

@@ -46,8 +46,6 @@ bool parse_json(const std::string &data, const json_parse_t &f);
/// Builder class for creating JSON documents without lambdas /// Builder class for creating JSON documents without lambdas
class JsonBuilder { class JsonBuilder {
public: public:
JsonBuilder();
JsonObject root() { JsonObject root() {
if (!root_created_) { if (!root_created_) {
root_ = doc_.to<JsonObject>(); root_ = doc_.to<JsonObject>();
@@ -61,8 +59,10 @@ class JsonBuilder {
private: private:
#ifdef USE_PSRAM #ifdef USE_PSRAM
SpiRamAllocator allocator_; // Just a regular member on the stack! SpiRamAllocator allocator_; // Just a regular member on the stack!
JsonDocument doc_{&allocator_}; // Initialize with allocator
#else
JsonDocument doc_; // Default initialization
#endif #endif
JsonDocument doc_;
JsonObject root_; JsonObject root_;
bool root_created_{false}; bool root_created_{false};
}; };