1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-18 12:05:41 +00:00

[json] use correct formatting (#8039)

This commit is contained in:
Clyde Stubbs 2025-01-13 13:56:42 +11:00 committed by GitHub
parent dd3ffc7f29
commit 92a8ebe1f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,11 +17,11 @@ std::string build_json(const json_build_t &f) {
auto free_heap = ALLOCATOR.get_max_free_block_size();
size_t request_size = std::min(free_heap, (size_t) 512);
while (true) {
ESP_LOGV(TAG, "Attempting to allocate %u bytes for JSON serialization", request_size);
ESP_LOGV(TAG, "Attempting to allocate %zu bytes for JSON serialization", request_size);
DynamicJsonDocument json_document(request_size);
if (json_document.capacity() == 0) {
ESP_LOGE(TAG,
"Could not allocate memory for JSON document! Requested %u bytes, largest free heap block: %u bytes",
"Could not allocate memory for JSON document! Requested %zu bytes, largest free heap block: %zu bytes",
request_size, free_heap);
return "{}";
}
@ -29,7 +29,7 @@ std::string build_json(const json_build_t &f) {
f(root);
if (json_document.overflowed()) {
if (request_size == free_heap) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %u bytes",
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %zu bytes",
free_heap);
return "{}";
}
@ -37,7 +37,7 @@ std::string build_json(const json_build_t &f) {
continue;
}
json_document.shrinkToFit();
ESP_LOGV(TAG, "Size after shrink %u bytes", json_document.capacity());
ESP_LOGV(TAG, "Size after shrink %zu bytes", json_document.capacity());
std::string output;
serializeJson(json_document, output);
return output;