binarystore: Add std::optional for optional config options

The `maxSizeBytes` was using 0 size by default instead of skipping it.
Letting `config.maxSizeBytes` be std::optional allow us to have more
control to see if the 0 value is expected or nullopt.

Change-Id: I128216825609909c489cbd5471b324d88d3aa25b
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/include/parse_config.hpp b/include/parse_config.hpp
index b778923..5bef8ad 100644
--- a/include/parse_config.hpp
+++ b/include/parse_config.hpp
@@ -2,6 +2,7 @@
 
 #include <cstdint>
 #include <nlohmann/json.hpp>
+#include <optional>
 #include <string>
 
 using std::uint32_t;
@@ -12,10 +13,10 @@
 
 struct BinaryBlobConfig
 {
-    std::string blobBaseId;  // Required
-    std::string sysFilePath; // Required
-    uint32_t offsetBytes;    // Optional
-    uint32_t maxSizeBytes;   // Optional
+    std::string blobBaseId;               // Required
+    std::string sysFilePath;              // Required
+    std::optional<uint32_t> offsetBytes;  // Optional
+    std::optional<uint32_t> maxSizeBytes; // Optional
 };
 
 /**
@@ -28,8 +29,19 @@
 {
     j.at("blobBaseId").get_to(config.blobBaseId);
     j.at("sysFilePath").get_to(config.sysFilePath);
-    config.offsetBytes = j.value("offsetBytes", 0);
-    config.maxSizeBytes = j.value("maxSizeBytes", 0);
+    if (j.contains("offsetBytes"))
+    {
+        uint32_t val;
+        j.at("offsetBytes").get_to(val);
+        config.offsetBytes = val;
+    }
+
+    if (j.contains("maxSizeBytes"))
+    {
+        uint32_t val;
+        j.at("maxSizeBytes").get_to(val);
+        config.maxSizeBytes = val;
+    }
 }
 
 } // namespace conf
diff --git a/include/sys_file_impl.hpp b/include/sys_file_impl.hpp
index c74c965..fa6f5ec 100644
--- a/include/sys_file_impl.hpp
+++ b/include/sys_file_impl.hpp
@@ -6,6 +6,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#include <optional>
 #include <string>
 
 namespace binstore
@@ -21,7 +22,8 @@
      *     actually reads underlying file at 'offset'
      * @param sys Syscall operation interface
      */
-    explicit SysFileImpl(const std::string& path, size_t offset = 0,
+    explicit SysFileImpl(const std::string& path,
+                         std::optional<size_t> offset = std::nullopt,
                          const internal::Sys* sys = &internal::sys_impl);
     ~SysFileImpl();
     SysFileImpl() = delete;