mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 18:52:19 +01:00
preen
This commit is contained in:
@@ -35,25 +35,10 @@ struct SpiRamAllocator : ArduinoJson::Allocator {
|
|||||||
|
|
||||||
std::string build_json(const json_build_t &f) {
|
std::string build_json(const json_build_t &f) {
|
||||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||||
#ifdef USE_PSRAM
|
JsonBuilder builder;
|
||||||
auto doc_allocator = SpiRamAllocator();
|
JsonObject root = builder.root();
|
||||||
JsonDocument json_document(&doc_allocator);
|
|
||||||
#else
|
|
||||||
JsonDocument json_document;
|
|
||||||
#endif
|
|
||||||
if (json_document.overflowed()) {
|
|
||||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
JsonObject root = json_document.to<JsonObject>();
|
|
||||||
f(root);
|
f(root);
|
||||||
if (json_document.overflowed()) {
|
return builder.serialize();
|
||||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
std::string output;
|
|
||||||
serializeJson(json_document, output);
|
|
||||||
return output;
|
|
||||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user