Create utility method to generate file manifests
Refs: #3431
Change-Id: I1a0f06b87689e71349b4fa9346ebc29e785d86cc
diff --git a/src/file-manifest.hpp b/src/file-manifest.hpp
index 6ce957e..b3cf3ff 100644
--- a/src/file-manifest.hpp
+++ b/src/file-manifest.hpp
@@ -22,9 +22,9 @@
#define INCLUDED_FILE_MANIFEST_HPP
#include <cstring>
-#include <list>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include <ndn-cxx/data.hpp>
@@ -53,6 +53,39 @@
};
public:
+ // CLASS METHODS
+ static std::vector<FileManifest>
+ generate(const std::string& filePath,
+ const ndn::Name& manifestPrefix,
+ size_t subManifestSize,
+ size_t dataPacketSize);
+
+
+ static std::pair<std::vector<FileManifest>, std::vector<Data>>
+ generate(const std::string& filePath,
+ const ndn::Name& manifestPrefix,
+ size_t subManifestSize,
+ size_t dataPacketSize,
+ bool returnData);
+ /**
+ * \brief Generates the FileManifest(s) and Data packets for the file at the specified 'filePath'
+ *
+ * @param filePath The path to the file for which we are to create a manifest
+ * @param manifestPrefix The prefix to be used for the name of this manifest
+ * @param subManifestSize The maximum number of data packets to be included in a sub-manifest
+ * @param dataPacketSize The maximum number of bytes per Data packet packets for the file
+ * @param returnData If true also return the Data
+ *
+ * @throws Error if there is any I/O issue when trying to read the filePath.
+ *
+ * Generates the FileManfiest(s) for the file at the specified 'filePath', splitting the manifest
+ * into sub-manifests of size at most the specified 'subManifestSize'. Each sub-manifest is
+ * composed of a catalog of Data packets of at most the specified 'dataPacketSize'. Returns all
+ * of the manifests that were created in order. The behavior is undefined unless the
+ * trailing component of of the manifestPrefix is a subComponent filePath and
+ '* O < subManifestSize' and '0 < dataPacketSize'.
+ */
+
// CREATORS
FileManifest() = delete;
@@ -129,9 +162,17 @@
/// Assigns the value of the specific 'rhs' object to this object.
void
+ set_submanifest_ptr(std::shared_ptr<Name> subManifestPtr);
+ /// Sets the sub-manifest pointer of manifest to the specified 'subManifestPtr'
+
+ void
push_back(const Name& name);
/// Appends a Name to the catalog
+ void
+ reserve(size_t capacity);
+ /// Reserve memory in the catalog adequate to hold at least 'capacity' Names.
+
bool
remove(const Name& name);
/// If 'name' in catalog, removes first instance and returns 'true', otherwise returns 'false'.
@@ -179,6 +220,16 @@
/// Returns 'true' if 'lhs' and 'rhs' have different values, and 'false' otherwise.
inline
+std::vector<FileManifest>
+FileManifest::generate(const std::string& filePath,
+ const ndn::Name& manifestPrefix,
+ size_t subManifestSize,
+ size_t dataPacketSize)
+{
+ return generate(filePath, manifestPrefix, subManifestSize, dataPacketSize, false).first;
+}
+
+inline
FileManifest::FileManifest(
const Name& name,
size_t dataPacketSize,
@@ -193,6 +244,7 @@
{
}
+
inline
FileManifest::FileManifest(
const Name& name,
@@ -249,6 +301,18 @@
return m_submanifestPtr;
}
+inline void
+FileManifest::set_submanifest_ptr(std::shared_ptr<Name> subManifestPtr)
+{
+ m_submanifestPtr = subManifestPtr;
+}
+
+inline void
+FileManifest::reserve(size_t capacity)
+{
+ m_catalog.reserve(capacity);
+}
+
} // end ntorrent
} // end ndn