Use binary serialization instead of JSON

The binary format is much more efficient than JSON in terms of
computational speed and disk space consumption. The former is important
in case the host is sending a constant stream of POST codes.
post-code-manager can fall behind because it takes too long to store
each new POST code on disk, causing D-Bus messages to pile up and
increase memory consumption inside dbus-broker.

Tested:
Rebooted the host a few times and observed that POST code history is
populated normally in Redfish. After upgrading to this change, old POST
code history stored in JSON format is lost, but remains on disk until it
gets overwritten during subsequent host boots.

Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Change-Id: Id55909a55d950e6e62b78b3333df687b4c582c42
diff --git a/inc/post_code.hpp b/inc/post_code.hpp
index 243feaf..3ae58d8 100644
--- a/inc/post_code.hpp
+++ b/inc/post_code.hpp
@@ -18,12 +18,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <cereal/access.hpp>
-#include <cereal/archives/json.hpp>
-#include <cereal/cereal.hpp>
-#include <cereal/types/map.hpp>
-#include <cereal/types/tuple.hpp>
-#include <cereal/types/vector.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
diff --git a/src/post_code.cpp b/src/post_code.cpp
index 6186f97..8ab2e32 100644
--- a/src/post_code.cpp
+++ b/src/post_code.cpp
@@ -15,6 +15,13 @@
 */
 #include "post_code.hpp"
 
+#include <cereal/access.hpp>
+#include <cereal/archives/binary.hpp>
+#include <cereal/cereal.hpp>
+#include <cereal/types/map.hpp>
+#include <cereal/types/tuple.hpp>
+#include <cereal/types/vector.hpp>
+
 #include <iomanip>
 
 void PostCode::deleteAll()
@@ -124,16 +131,16 @@
     try
     {
         std::ofstream osIdx(path / CurrentBootCycleIndexName, std::ios::binary);
-        cereal::JSONOutputArchive idxArchive(osIdx);
+        cereal::BinaryOutputArchive idxArchive(osIdx);
         idxArchive(currentBootCycleIndex);
 
         uint16_t count = currentBootCycleCount();
         std::ofstream osCnt(path / CurrentBootCycleCountName, std::ios::binary);
-        cereal::JSONOutputArchive cntArchive(osCnt);
+        cereal::BinaryOutputArchive cntArchive(osCnt);
         cntArchive(count);
 
         std::ofstream osPostCodes(path / std::to_string(currentBootCycleIndex));
-        cereal::JSONOutputArchive oarchivePostCodes(osPostCodes);
+        cereal::BinaryOutputArchive oarchivePostCodes(osPostCodes);
         oarchivePostCodes(postCodes);
     }
     catch (const cereal::Exception& e)
@@ -156,7 +163,7 @@
         if (fs::exists(path))
         {
             std::ifstream is(path, std::ios::in | std::ios::binary);
-            cereal::JSONInputArchive iarchive(is);
+            cereal::BinaryInputArchive iarchive(is);
             iarchive(index);
             return true;
         }
@@ -183,7 +190,7 @@
         if (fs::exists(path))
         {
             std::ifstream is(path, std::ios::in | std::ios::binary);
-            cereal::JSONInputArchive iarchive(is);
+            cereal::BinaryInputArchive iarchive(is);
             iarchive(codes);
             return true;
         }