Make Data content_ use a Blob.
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index 68b4779..629ff37 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -72,7 +72,7 @@
dataStruct.contentLength = content_.size();
if (content_.size() > 0)
- dataStruct.content = (unsigned char *)&content_[0];
+ dataStruct.content = (unsigned char*)content_.buf();
else
dataStruct.content = 0;
}
@@ -82,7 +82,7 @@
signature_.set(dataStruct.signature);
name_.set(dataStruct.name);
metaInfo_.set(dataStruct.metaInfo);
- setVector(content_, dataStruct.content, dataStruct.contentLength);
+ content_ = Blob(dataStruct.content, dataStruct.contentLength);
}
}
diff --git a/ndn-cpp/data.hpp b/ndn-cpp/data.hpp
index 28d753a..e1ad290 100644
--- a/ndn-cpp/data.hpp
+++ b/ndn-cpp/data.hpp
@@ -187,8 +187,7 @@
const MetaInfo& getMetaInfo() const { return metaInfo_; }
MetaInfo& getMetaInfo() { return metaInfo_; }
- const std::vector<unsigned char>& getContent() const { return content_; }
- std::vector<unsigned char>& getContent() { return content_; }
+ const std::vector<unsigned char>& getContent() const { return (*content_); }
void setSignature(const Signature& signature) { signature_ = signature; }
@@ -196,17 +195,21 @@
void setMetainfo(const MetaInfo& metaInfo) { metaInfo_ = metaInfo; }
+ /**
+ * Set the content to a copy of the data in the vector.
+ * @param content A vector whose contents are copied.
+ */
void setContent(const std::vector<unsigned char>& content) { content_ = content; }
void setContent(const unsigned char *content, unsigned int contentLength)
{
- setVector(content_, content, contentLength);
+ content_ = Blob(content, contentLength);
}
private:
Signature signature_;
Name name_;
MetaInfo metaInfo_;
- std::vector<unsigned char> content_;
+ Blob content_;
};
}