fix merge issues and clean up old comments

This commit is contained in:
Kevin Ahrendt 2025-07-14 10:47:38 -04:00
parent a1281febe9
commit 815744b0f6

View File

@ -26,11 +26,6 @@ struct SpiRamAllocator : ArduinoJson::Allocator {
};
std::string build_json(const json_build_t &f) {
// Here we are allocating up to 5kb of memory,
// with the heap size minus 2kb to be safe if less than 5kb
// as we can not have a true dynamic sized document.
// The excess memory is freed below with `shrinkToFit()`
while (true) {
auto doc_allocator = SpiRamAllocator();
JsonDocument json_document(&doc_allocator);
if (json_document.overflowed()) {
@ -40,25 +35,15 @@ std::string build_json(const json_build_t &f) {
JsonObject root = json_document.to<JsonObject>();
f(root);
if (json_document.overflowed()) {
if (request_size == free_heap) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
return "{}";
}
request_size = std::min(request_size * 2, free_heap);
continue;
}
std::string output;
serializeJson(json_document, output);
return output;
}
}
bool parse_json(const std::string &data, const json_parse_t &f) {
// Here we are allocating 1.5 times the data size,
// with the heap size minus 2kb to be safe if less than that
// as we can not have a true dynamic sized document.
// The excess memory is freed below with `shrinkToFit()`
while (true) {
auto doc_allocator = SpiRamAllocator();
JsonDocument json_document(&doc_allocator);
if (json_document.overflowed()) {
@ -74,11 +59,8 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
} else if (err == DeserializationError::NoMemory) {
ESP_LOGE(TAG, "Can not allocate more memory for deserialization. Consider making source string smaller");
return false;
} else {
ESP_LOGE(TAG, "Parse error: %s", err.c_str());
return false;
}
};
ESP_LOGE(TAG, "Parse error: %s", err.c_str());
return false;
}