data: Add ability to print out information about Data packet using std::ostream
Change-Id: I20869cebd259e90f8b69d48758a090a8c31fa34c
diff --git a/include/ndn-cpp/data.hpp b/include/ndn-cpp/data.hpp
index 3f0d00b..d25253f 100644
--- a/include/ndn-cpp/data.hpp
+++ b/include/ndn-cpp/data.hpp
@@ -273,6 +273,9 @@
wire_ = Block();
}
+std::ostream&
+operator << (std::ostream &os, const Data &data);
+
} // namespace ndn
#endif
diff --git a/include/ndn-cpp/meta-info.hpp b/include/ndn-cpp/meta-info.hpp
index 27e97e8..3a33dc4 100644
--- a/include/ndn-cpp/meta-info.hpp
+++ b/include/ndn-cpp/meta-info.hpp
@@ -111,6 +111,19 @@
}
}
+inline std::ostream&
+operator << (std::ostream &os, const MetaInfo &info)
+{
+ // ContentType
+ os << "ContentType: " << info.getType();
+
+ // FreshnessPeriod
+ if (info.getFreshnessPeriod() >= 0) {
+ os << ", FreshnessPeriod: " << info.getFreshnessPeriod();
+ }
+ return os;
+}
+
} // namespace ndn
#endif // NDN_META_INFO_HPP
diff --git a/src/data.cpp b/src/data.cpp
index 4326040..6b1efd7 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -77,5 +77,18 @@
signature_.setValue(wire_.get(Tlv::SignatureValue));
}
+std::ostream&
+operator << (std::ostream &os, const Data &data)
+{
+ os << "Name: " << data.getName() << "\n";
+ os << "MetaInfo: " << data.getMetaInfo() << "\n";
+ os << "Content: (size: " << data.getContent().value_size() << ")\n";
+ os << "Signature: (type: " << data.getSignature().getType() <<
+ ", value_length: "<< data.getSignature().getValue().value_size() << ")";
+ os << std::endl;
+
+ return os;
+}
+
}