dissect+peek: avoid deprecated ndn-cxx functions
Change-Id: Ibd9f8ad30e315f537d1560db823372af3d58d713
diff --git a/tools/dissect/dissector.cpp b/tools/dissect/dissector.cpp
index c612352..4a64f18 100644
--- a/tools/dissect/dissector.cpp
+++ b/tools/dissect/dissector.cpp
@@ -27,7 +27,7 @@
#include <map>
#include <ndn-cxx/encoding/tlv.hpp>
-#include <ndn-cxx/name-component.hpp>
+#include <ndn-cxx/util/string-helper.hpp>
namespace ndn::dissect {
@@ -168,7 +168,7 @@
const auto& elements = block.elements();
if (elements.empty()) {
m_out << " [[";
- name::Component(block.value(), block.value_size()).toUri(m_out);
+ escape(m_out, reinterpret_cast<const char*>(block.value()), block.value_size());
m_out << "]]";
}
m_out << "\n";
diff --git a/tools/dump/ndndump.hpp b/tools/dump/ndndump.hpp
index 9d786e7..83b0710 100644
--- a/tools/dump/ndndump.hpp
+++ b/tools/dump/ndndump.hpp
@@ -105,7 +105,7 @@
std::string interface;
std::string inputFile;
std::string pcapFilter{getDefaultPcapFilter()};
- optional<std::regex> nameFilter;
+ std::optional<std::regex> nameFilter;
bool wantPromisc = true;
bool wantTimestamp = true;
bool wantVerbose = false;
diff --git a/tools/peek/ndnpeek/ndnpeek.cpp b/tools/peek/ndnpeek/ndnpeek.cpp
index d58b92e..3fb540f 100644
--- a/tools/peek/ndnpeek/ndnpeek.cpp
+++ b/tools/peek/ndnpeek/ndnpeek.cpp
@@ -64,7 +64,9 @@
interest.setMustBeFresh(m_options.mustBeFresh);
interest.setForwardingHint(m_options.forwardingHint);
interest.setInterestLifetime(m_options.interestLifetime);
- interest.setHopLimit(m_options.hopLimit);
+ if (m_options.hopLimit) {
+ interest.setHopLimit(*m_options.hopLimit);
+ }
if (m_options.applicationParameters) {
interest.setApplicationParameters(m_options.applicationParameters);
}
@@ -76,6 +78,12 @@
return interest;
}
+static void
+writeToCout(span<const uint8_t> bytes)
+{
+ std::cout.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
+}
+
void
NdnPeek::onData(const Data& data)
{
@@ -89,12 +97,10 @@
}
if (m_options.wantPayloadOnly) {
- const Block& block = data.getContent();
- std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
+ writeToCout(data.getContent().value_bytes());
}
else {
- const Block& block = data.wireEncode();
- std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
+ writeToCout(data.wireEncode());
}
}
@@ -104,7 +110,7 @@
m_result = Result::NACK;
m_timeoutEvent.cancel();
- lp::NackHeader header = nack.getHeader();
+ const auto& header = nack.getHeader();
if (m_options.isVerbose) {
std::cerr << "NACK: " << header.getReason() << "\nRTT: "
<< time::duration_cast<time::milliseconds>(time::steady_clock::now() - m_sendTime).count()
@@ -115,8 +121,7 @@
std::cout << header.getReason() << std::endl;
}
else {
- const Block& block = header.wireEncode();
- std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
+ writeToCout(header.wireEncode());
}
}
diff --git a/tools/peek/ndnpeek/ndnpeek.hpp b/tools/peek/ndnpeek/ndnpeek.hpp
index eba1b1f..f7f246b 100644
--- a/tools/peek/ndnpeek/ndnpeek.hpp
+++ b/tools/peek/ndnpeek/ndnpeek.hpp
@@ -48,13 +48,13 @@
bool mustBeFresh = false;
std::vector<Name> forwardingHint;
time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME;
- optional<uint8_t> hopLimit;
+ std::optional<uint8_t> hopLimit;
shared_ptr<Buffer> applicationParameters;
// program behavior options
bool isVerbose = false;
bool wantPayloadOnly = false;
- optional<time::milliseconds> timeout;
+ std::optional<time::milliseconds> timeout;
};
class NdnPeek : noncopyable
diff --git a/tools/peek/ndnpoke/ndnpoke.hpp b/tools/peek/ndnpoke/ndnpoke.hpp
index 16a3795..a3cd393 100644
--- a/tools/peek/ndnpoke/ndnpoke.hpp
+++ b/tools/peek/ndnpoke/ndnpoke.hpp
@@ -49,7 +49,7 @@
// program behavior options
bool isVerbose = false;
bool wantUnsolicited = false;
- optional<time::milliseconds> timeout;
+ std::optional<time::milliseconds> timeout;
};
class NdnPoke : noncopyable