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/src/main.cpp b/src/main.cpp
index 5cf6c10..bb45f55 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -61,11 +61,13 @@
             return nullptr;
         }
 
-        log<level::INFO>("Loading from config with",
-                         entry("BASE_ID=%s", config.blobBaseId.c_str()),
-                         entry("FILE=%s", config.sysFilePath.c_str()),
-                         entry("MAX_SIZE=%llx", static_cast<unsigned long long>(
-                                                    config.maxSizeBytes)));
+        log<level::INFO>(
+            "Loading from config with",
+            entry("BASE_ID=%s", config.blobBaseId.c_str()),
+            entry("FILE=%s", config.sysFilePath.c_str()),
+            entry("MAX_SIZE=%llx",
+                  static_cast<unsigned long long>(
+                      config.maxSizeBytes ? *config.maxSizeBytes : 0)));
 
         auto file = std::make_unique<binstore::SysFileImpl>(config.sysFilePath,
                                                             config.offsetBytes);
diff --git a/src/sys_file_impl.cpp b/src/sys_file_impl.cpp
index 243d82d..9fab76a 100644
--- a/src/sys_file_impl.cpp
+++ b/src/sys_file_impl.cpp
@@ -1,5 +1,6 @@
 #include "sys_file_impl.hpp"
 
+#include <optional>
 #include <system_error>
 
 using namespace std::string_literals;
@@ -19,12 +20,12 @@
 
 } // namespace
 
-SysFileImpl::SysFileImpl(const std::string& path, size_t offset,
+SysFileImpl::SysFileImpl(const std::string& path, std::optional<size_t> offset,
                          const internal::Sys* sys) :
     sys(sys)
 {
     fd_ = sys->open(path.c_str(), O_RDWR);
-    offset_ = offset;
+    offset_ = offset ? *offset : 0;
 
     if (fd_ < 0)
     {