dissect: no longer dissect Content element by default
Use the new -c/--content option to enable it
Change-Id: Id5692b53a0921918bb029ad653b9f5504ab5e4ab
diff --git a/tools/dissect/README.md b/tools/dissect/README.md
index b0da01a..70d2458 100644
--- a/tools/dissect/README.md
+++ b/tools/dissect/README.md
@@ -1,13 +1,14 @@
# ndn-dissect
**ndn-dissect** is an NDN packet format inspector.
-It reads zero or more NDN packets from either an input file or the standard input,
-and displays the Type-Length-Value (TLV) structure of those packets on the standard output.
+It reads zero or more NDN packets from either an input file or the standard
+input, and displays the Type-Length-Value (TLV) structure of those packets
+on the standard output.
Usage example:
-1. start NFD on local machine
-2. execute `echo 'HELLO WORLD' | ndnpoke ndn:/localhost/demo/hello`
-3. on another console, execute `ndnpeek ndn:/localhost/demo/hello | ndn-dissect`
+1. start NFD on the local machine
+2. run `echo 'HELLO WORLD' | ndnpoke /localhost/demo/hello`
+3. on another console, run `ndnpeek /localhost/demo/hello | ndn-dissect`
For more information, consult the manpage.
diff --git a/tools/dissect/ndn-dissect.cpp b/tools/dissect/dissector.cpp
similarity index 92%
rename from tools/dissect/ndn-dissect.cpp
rename to tools/dissect/dissector.cpp
index d21926f..3c0ca5c 100644
--- a/tools/dissect/ndn-dissect.cpp
+++ b/tools/dissect/dissector.cpp
@@ -18,10 +18,11 @@
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ * @author Alexander Afanasyev
+ * @author Davide Pesavento
*/
-#include "ndn-dissect.hpp"
+#include "dissector.hpp"
#include <map>
@@ -31,14 +32,15 @@
namespace ndn {
namespace dissect {
-NdnDissect::NdnDissect(std::istream& input, std::ostream& output)
- : m_in(input)
+Dissector::Dissector(std::istream& input, std::ostream& output, const Options& options)
+ : m_options(options)
+ , m_in(input)
, m_out(output)
{
}
void
-NdnDissect::dissect()
+Dissector::dissect()
{
size_t offset = 0;
try {
@@ -60,7 +62,7 @@
static const char GLYPH_SPACE[] = " ";
void
-NdnDissect::printBranches()
+Dissector::printBranches()
{
for (size_t i = 0; i < m_branches.size(); ++i) {
if (i == m_branches.size() - 1) {
@@ -114,7 +116,7 @@
};
void
-NdnDissect::printType(uint32_t type)
+Dissector::printType(uint32_t type)
{
m_out << type << " (";
@@ -139,14 +141,15 @@
}
void
-NdnDissect::printBlock(const Block& block)
+Dissector::printBlock(const Block& block)
{
printBranches();
printType(block.type());
m_out << " (size: " << block.value_size() << ")";
try {
- if (block.type() != tlv::SignatureValue) {
+ if (block.type() != tlv::SignatureValue &&
+ (block.type() != tlv::Content || m_options.dissectContent)) {
block.parse();
}
}
diff --git a/tools/dissect/ndn-dissect.hpp b/tools/dissect/dissector.hpp
similarity index 81%
rename from tools/dissect/ndn-dissect.hpp
rename to tools/dissect/dissector.hpp
index 29c5e6a..e408efe 100644
--- a/tools/dissect/ndn-dissect.hpp
+++ b/tools/dissect/dissector.hpp
@@ -17,8 +17,8 @@
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
-#define NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
+#ifndef NDN_TOOLS_DISSECT_DISSECTOR_HPP
+#define NDN_TOOLS_DISSECT_DISSECTOR_HPP
#include "core/common.hpp"
@@ -27,10 +27,15 @@
namespace ndn {
namespace dissect {
-class NdnDissect : noncopyable
+struct Options
+{
+ bool dissectContent = false;
+};
+
+class Dissector : noncopyable
{
public:
- NdnDissect(std::istream& input, std::ostream& output);
+ Dissector(std::istream& input, std::ostream& output, const Options& options);
void
dissect();
@@ -46,6 +51,7 @@
printBlock(const Block& block);
private:
+ const Options& m_options;
std::istream& m_in;
std::ostream& m_out;
@@ -56,4 +62,4 @@
} // namespace dissect
} // namespace ndn
-#endif // NDN_TOOLS_DISSECT_NDN_DISSECT_HPP
+#endif // NDN_TOOLS_DISSECT_DISSECTOR_HPP
diff --git a/tools/dissect/main.cpp b/tools/dissect/main.cpp
index b5f2a68..bcb2339 100644
--- a/tools/dissect/main.cpp
+++ b/tools/dissect/main.cpp
@@ -17,7 +17,7 @@
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ndn-dissect.hpp"
+#include "dissector.hpp"
#include "core/version.hpp"
#include <boost/program_options/options_description.hpp>
@@ -42,12 +42,14 @@
static int
main(int argc, char* argv[])
{
+ Options options;
std::string inputFileName;
po::options_description visibleOptions("Options");
visibleOptions.add_options()
- ("help,h", "print help and exit")
- ("version,V", "print version and exit")
+ ("help,h", "print this help message and exit")
+ ("content,c", po::bool_switch(&options.dissectContent), "dissect the value of Content elements")
+ ("version,V", "print program version and exit")
;
po::options_description hiddenOptions;
@@ -91,8 +93,8 @@
inputStream = &inputFile;
}
- NdnDissect program(*inputStream, std::cout);
- program.dissect();
+ Dissector d(*inputStream, std::cout, options);
+ d.dissect();
return 0;
}