Set json no IO

There's only a couple remaining places we use json IO.  Not including IO
improves compile times in a minor way, because the nlohmann stream/file
template is relatively expensive to compile.

Tested: Launched bmcweb.  Observed bmcweb_persistent_data.json created.
Rebooted bmcweb with 'systemctl restart bmcweb' and observed launched
correctly with persistent file present.

Change-Id: I56f674f20fa8553dc86245a765818849aa5fa102
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index bb24f77..1260103 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -15,9 +15,9 @@
 #include <nlohmann/json.hpp>
 
 #include <chrono>
+#include <cstddef>
 #include <cstdint>
 #include <filesystem>
-#include <fstream>
 #include <memory>
 #include <optional>
 #include <string>
@@ -74,12 +74,29 @@
     // this application for the moment
     void readData()
     {
-        std::ifstream persistentFile(filename());
+        boost::beast::file_posix persistentFile;
+        boost::system::error_code ec;
+        const std::string& file = filename();
+        persistentFile.open(file.c_str(), boost::beast::file_mode::read, ec);
         uint64_t fileRevision = 0;
-        if (persistentFile.is_open())
+        if (!ec)
         {
+            uint64_t size = persistentFile.size(ec);
+            if (ec)
+            {
+                BMCWEB_LOG_CRITICAL("Can't get filesize of {}", file);
+                return;
+            }
+            std::string str;
+            str.resize(static_cast<size_t>(size), '\0');
+            persistentFile.read(str.data(), str.size(), ec);
+            if (ec)
+            {
+                BMCWEB_LOG_CRITICAL("Failed to read file {}", file);
+                return;
+            }
             // call with exceptions disabled
-            auto data = nlohmann::json::parse(persistentFile, nullptr, false);
+            auto data = nlohmann::json::parse(str, nullptr, false);
             if (data.is_discarded())
             {
                 BMCWEB_LOG_ERROR("Error parsing persistent data in json file.");
diff --git a/meson.build b/meson.build
index 205ee90..93c26b7 100644
--- a/meson.build
+++ b/meson.build
@@ -197,6 +197,7 @@
             '-DBOOST_URL_NO_SOURCE_LOCATION',
             '-DBOOST_SPIRIT_X3_NO_RTTI',
             '-DJSON_NOEXCEPTION',
+            '-DJSON_NO_IO',
             '-DJSON_USE_IMPLICIT_CONVERSIONS=0',
             '-DOPENSSL_NO_FILENAMES',
             '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',