1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +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)
}
// JsonBuilder implementation
JsonBuilder::JsonBuilder()
: doc_(
#ifdef USE_PSRAM
&allocator_
#else
nullptr
#endif
) {
}
std::string JsonBuilder::serialize() {
if (doc_.overflowed()) {
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
class JsonBuilder {
public:
JsonBuilder();
JsonObject root() {
if (!root_created_) {
root_ = doc_.to<JsonObject>();
@@ -60,9 +58,11 @@ class JsonBuilder {
private:
#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
JsonDocument doc_;
JsonObject root_;
bool root_created_{false};
};