Skip to content

Commit 536e78c

Browse files
committed
antipattern fix
1 parent 885a471 commit 536e78c

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/BootstrapManager.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,8 @@ JsonDocument BootstrapManager::readLittleFS(const String &filenameToUse) {
463463
Helpers::smartPrintln("Failed to open [" + filenameToUse + "] file");
464464
helper.smartDisplay();
465465
}
466-
size_t size = jsonFile.size();
467-
// Allocate a buffer to store contents of the file.
468-
std::unique_ptr<char[]> buf(new char[size]);
469-
// We don't use String here because ArduinoJson library requires the input
470-
// buffer to be mutable. If you don't use ArduinoJson, you may as well
471-
// use configFile.readString instead.
472-
jsonFile.readBytes(buf.get(), size);
473466
JsonDocument jsonDoc;
474-
auto error = deserializeJson(jsonDoc, buf.get());
467+
auto error = deserializeJson(jsonDoc, jsonFile);
475468
if (filenameToUse != "setup.json") serializeJsonPretty(jsonDoc, Serial);
476469
jsonFile.close();
477470
if (error) {
@@ -496,11 +489,8 @@ String BootstrapManager::readValueFromFile(const String &filenameToUse, const St
496489
Helpers::smartPrintln("Failed to open [" + filenameToUse + "] file");
497490
helper.smartDisplay();
498491
}
499-
size_t size = jsonFile.size();
500-
std::unique_ptr<char[]> buf(new char[size]);
501-
jsonFile.readBytes(buf.get(), size);
502492
JsonDocument jDoc;
503-
auto error = deserializeJson(jDoc, buf.get());
493+
auto error = deserializeJson(jDoc, jsonFile);
504494
serializeJsonPretty(jDoc, Serial);
505495
JsonVariant answer = jDoc[paramName];
506496
if (answer.is<const char*>()) {

0 commit comments

Comments
 (0)