FDStore class for binary serialization
[archive/platform/core/system/libConfig.git] / src / config / manager.hpp
index 688bc54..a2623ea 100644 (file)
 
 #include "config/to-json-visitor.hpp"
 #include "config/to-kvstore-visitor.hpp"
+#include "config/to-fdstore-visitor.hpp"
 #include "config/from-json-visitor.hpp"
 #include "config/from-kvstore-visitor.hpp"
+#include "config/from-fdstore-visitor.hpp"
 #include "config/is-visitable.hpp"
 #include "config/fs-utils.hpp"
 
@@ -121,7 +123,7 @@ void loadFromKVStore(const std::string& filename, Config& config, const std::str
  * Saves the config to a KVStore.
  *
  * @param filename   path to the KVStore db
- * @param config     visitable structure to load
+ * @param config     visitable structure to save
  * @param configName name of the config inside the KVStore db
  */
 template <class Config>
@@ -133,6 +135,36 @@ void saveToKVStore(const std::string& filename, const Config& config, const std:
     config.accept(visitor);
 }
 
+/**
+ * Load binary data from a file/socket/pipe represented by the fd
+ *
+ * @param fd file descriptor
+ * @param config visitable structure to load
+ */
+template <class Config>
+void loadFromFD(const int fd, Config& config)
+{
+    static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
+
+    FromFDStoreVisitor visitor(fd);
+    config.accept(visitor);
+}
+
+/**
+ * Save binary data to a file/socket/pipe represented by the fd
+ *
+ * @param fd file descriptor
+ * @param config visitable structure to save
+ */
+template <class Config>
+void saveToFD(const int fd, const Config& config)
+{
+    static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
+
+    ToFDStoreVisitor visitor(fd);
+    config.accept(visitor);
+}
+
 } // namespace config
 
 #endif // CONFIG_MANAGER_HPP