o Bug fix in FileManifest::wireDecode
o Add I/O test for FileManifest
Change-Id: I7307605a71cc0cdc76585421f73346dccbca6a6a
diff --git a/src/file-manifest.cpp b/src/file-manifest.cpp
index 71ba3a6..40726e6 100644
--- a/src/file-manifest.cpp
+++ b/src/file-manifest.cpp
@@ -32,6 +32,8 @@
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
+#include <ndn-cxx/encoding/tlv.hpp>
+
using std::vector;
using std::streamsize;
using boost::irange;
@@ -219,9 +221,6 @@
template<ndn::encoding::Tag TAG>
size_t
FileManifest::encodeContent(ndn::EncodingImpl<TAG>& encoder) const {
- // FileManifestName ::= NAME-TYPE TLV-LENGTH
- // Name
-
// ManifestContent ::= CONTENT-TYPE TLV-LENGTH
// DataPacketName*
// CatalogPrefix
@@ -234,7 +233,7 @@
// CatalogPrefix ::= NAME-TYPE TLV-LENGTH
// Name
- // DataPacketSize ::= CONTENT-TYPE TLV-LENGTH
+ // DataPacketSize ::= CONTENT-TYPE TLV-LENGTH
// nonNegativeInteger
// FileManifestPtr ::= NAME-TYPE TLV-LENGTH
@@ -242,6 +241,7 @@
size_t totalLength = 0;
+ // build suffix catalog
vector<Name> suffixCatalog;
suffixCatalog.reserve(m_catalog.size());
for (auto name: m_catalog) {
@@ -355,16 +355,11 @@
content.parse();
auto element = content.elements_begin();
-
if (content.elements_end() == element) {
BOOST_THROW_EXCEPTION(Error("FileManifest with empty content"));
}
-
- element->parse();
- Name name(*element);
-
- // Submanifest ptr
- if (!name.empty()) {
+ if (element->type() == tlv::Name) {
+ Name name(*element);
m_submanifestPtr = std::make_shared<Name>(name);
++element;
}
@@ -372,16 +367,14 @@
// DataPacketSize
m_dataPacketSize = readNonNegativeInteger(*element);
++element;
-
// CatalogPrefix
m_catalogPrefix = Name(*element);
- element++;
-
+ ++element;
// Catalog
m_catalog.clear();
for (; element != content.elements_end(); ++element) {
element->parse();
- name = m_catalogPrefix;
+ Name name = m_catalogPrefix;
name.append(Name(*element));
if (name == m_catalogPrefix) {
BOOST_THROW_EXCEPTION(Error("Empty name included in a FileManifest"));