face/rib/tools: avoid deprecate Block::fromBuffer overloads
refs #2553
Change-Id: I32ea424ab7547f59fea2fca70ad6f41cd90bab58
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index 886a8b3..adbf9e6 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -215,8 +215,9 @@
NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
this->getMutableCounters().getNInBytes() += nBytesReceived;
+ bool isOk = false;
Block element;
- bool isOk = Block::fromBuffer(buffer, nBytesReceived, element);
+ std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
if (!isOk)
{
NFD_LOG_FACE_WARN("Failed to parse incoming packet");
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 8bd2c7b..d2cd9a1 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -381,8 +381,9 @@
length -= ethernet::HDR_LEN;
/// \todo Reserve space in front and at the back of the underlying buffer
+ bool isOk = false;
Block fragment;
- bool isOk = Block::fromBuffer(packet, length, fragment);
+ std::tie(isOk, fragment) = Block::fromBuffer(packet, length);
if (!isOk)
{
NFD_LOG_FACE_WARN("Block received from " << sourceAddress.toString()
diff --git a/daemon/face/stream-face.hpp b/daemon/face/stream-face.hpp
index fb51afd..fa743de 100644
--- a/daemon/face/stream-face.hpp
+++ b/daemon/face/stream-face.hpp
@@ -268,22 +268,21 @@
bool isOk = true;
Block element;
- while (m_inputBufferSize - offset > 0)
- {
- isOk = Block::fromBuffer(m_inputBuffer + offset, m_inputBufferSize - offset, element);
- if (!isOk)
- break;
+ while (m_inputBufferSize - offset > 0) {
+ std::tie(isOk, element) = Block::fromBuffer(m_inputBuffer + offset, m_inputBufferSize - offset);
+ if (!isOk)
+ break;
- offset += element.size();
+ offset += element.size();
- BOOST_ASSERT(offset <= m_inputBufferSize);
+ BOOST_ASSERT(offset <= m_inputBufferSize);
- if (!this->decodeAndDispatchInput(element))
- {
- NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
- // ignore unknown packet and proceed
- }
+ if (!this->decodeAndDispatchInput(element)) {
+ NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
+ // ignore unknown packet and proceed
}
+ }
+
if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0)
{
NFD_LOG_FACE_WARN("Failed to parse incoming packet or packet too large to process");
diff --git a/daemon/face/websocket-face.cpp b/daemon/face/websocket-face.cpp
index 27a8f57..007e800 100644
--- a/daemon/face/websocket-face.cpp
+++ b/daemon/face/websocket-face.cpp
@@ -115,9 +115,10 @@
this->getMutableCounters().getNInBytes() += msg.size();
// Try to parse message data
+ bool isOk = false;
Block element;
- bool isOk = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()),
- msg.size(), element);
+ std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()),
+ msg.size());
if (!isOk)
{
NFD_LOG_FACE_WARN("Received block is invalid or too large to process");
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index fa2c318..2b79a53 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -853,20 +853,20 @@
size_t offset = 0;
FaceIdSet activeFaces;
- while (offset < buf->size())
- {
- if (!Block::fromBuffer(buf, offset, block))
- {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
-
- offset += block.size();
-
- ndn::nfd::FaceStatus status(block);
- activeFaces.insert(status.getFaceId());
+ while (offset < buf->size()) {
+ bool isOk = false;
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
+ break;
}
+ offset += block.size();
+
+ ndn::nfd::FaceStatus status(block);
+ activeFaces.insert(status.getFaceId());
+ }
+
// Look for face IDs that were registered but not active to find missed
// face destroyed events
for (FaceIdSet::iterator it = m_registeredFaces.begin(); it != m_registeredFaces.end(); ++it)
diff --git a/tests/daemon/face/websocket.t.cpp b/tests/daemon/face/websocket.t.cpp
index 75d552e..8e30517 100644
--- a/tests/daemon/face/websocket.t.cpp
+++ b/tests/daemon/face/websocket.t.cpp
@@ -144,11 +144,11 @@
client1_onMessage(websocketpp::connection_hdl hdl,
websocketpp::config::asio_client::message_type::ptr msg)
{
- bool isOk = true;
+ bool isOk = false;
Block element;
const std::string& payload = msg->get_payload();
- isOk = Block::fromBuffer(reinterpret_cast<const uint8_t*>(payload.c_str()),
- payload.size(), element);
+ std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(payload.c_str()),
+ payload.size());
if (isOk)
{
try {
diff --git a/tools/ndn-autoconfig/multicast-discovery.cpp b/tools/ndn-autoconfig/multicast-discovery.cpp
index 59db21f..ae3e72d 100644
--- a/tools/ndn-autoconfig/multicast-discovery.cpp
+++ b/tools/ndn-autoconfig/multicast-discovery.cpp
@@ -63,13 +63,13 @@
size_t offset = 0;
while (offset < buffer->size()) {
+ bool isOk = false;
Block block;
- bool ok = Block::fromBuffer(buffer, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buffer, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
+ break;
+ }
offset += block.size();
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index c6de1f5..6cc3288 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -284,22 +284,21 @@
std::vector<uint64_t> multicastFaces;
size_t offset = 0;
- while (offset < buf->size())
- {
- Block block;
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
-
- offset += block.size();
-
- nfd::FaceStatus faceStatus(block);
- registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()),
- faceStatus.getFacePersistency());
+ while (offset < buf->size()) {
+ bool isOk = false;
+ Block block;
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
+ break;
}
+
+ offset += block.size();
+
+ nfd::FaceStatus faceStatus(block);
+ registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()),
+ faceStatus.getFacePersistency());
+ }
}
int
diff --git a/tools/nfd-status.cpp b/tools/nfd-status.cpp
index 42a35be..9824d64 100644
--- a/tools/nfd-status.cpp
+++ b/tools/nfd-status.cpp
@@ -1,12 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -287,55 +287,51 @@
afterFetchedChannelStatusInformation()
{
ConstBufferPtr buf = m_buffer->buf();
- if (m_isOutputXml)
- {
- std::cout << "<channels>";
+ if (m_isOutputXml) {
+ std::cout << "<channels>";
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
+ break;
+ }
- offset += block.size();
+ offset += block.size();
- nfd::ChannelStatus channelStatus(block);
+ nfd::ChannelStatus channelStatus(block);
- std::cout << "<channel>";
-
- std::string localUri(channelStatus.getLocalUri());
- escapeSpecialCharacters(&localUri);
- std::cout << "<localUri>" << localUri << "</localUri>";
- std::cout << "</channel>";
- }
- std::cout << "</channels>";
+ std::cout << "<channel>";
+ std::string localUri(channelStatus.getLocalUri());
+ escapeSpecialCharacters(&localUri);
+ std::cout << "<localUri>" << localUri << "</localUri>";
+ std::cout << "</channel>";
}
- else
- {
- std::cout << "Channels:" << std::endl;
+ std::cout << "</channels>";
+ }
+ else {
+ std::cout << "Channels:" << std::endl;
+
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
+ break;
+ }
- offset += block.size();
+ offset += block.size();
- nfd::ChannelStatus channelStatus(block);
- std::cout << " " << channelStatus.getLocalUri() << std::endl;
- }
- }
+ nfd::ChannelStatus channelStatus(block);
+ std::cout << " " << channelStatus.getLocalUri() << std::endl;
+ }
+ }
runNextStep();
}
@@ -362,117 +358,113 @@
afterFetchedFaceStatusInformation()
{
ConstBufferPtr buf = m_buffer->buf();
- if (m_isOutputXml)
- {
- std::cout << "<faces>";
+ if (m_isOutputXml) {
+ std::cout << "<faces>";
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
+ break;
+ }
- offset += block.size();
+ offset += block.size();
- nfd::FaceStatus faceStatus(block);
+ nfd::FaceStatus faceStatus(block);
- std::cout << "<face>";
- std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
+ std::cout << "<face>";
+ std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
- std::string remoteUri(faceStatus.getRemoteUri());
- escapeSpecialCharacters(&remoteUri);
- std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
+ std::string remoteUri(faceStatus.getRemoteUri());
+ escapeSpecialCharacters(&remoteUri);
+ std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
- std::string localUri(faceStatus.getLocalUri());
- escapeSpecialCharacters(&localUri);
- std::cout << "<localUri>" << localUri << "</localUri>";
+ std::string localUri(faceStatus.getLocalUri());
+ escapeSpecialCharacters(&localUri);
+ std::cout << "<localUri>" << localUri << "</localUri>";
- if (faceStatus.hasExpirationPeriod()) {
- std::cout << "<expirationPeriod>PT"
- << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
- .count() << "S"
- << "</expirationPeriod>";
- }
+ if (faceStatus.hasExpirationPeriod()) {
+ std::cout << "<expirationPeriod>PT"
+ << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
+ .count() << "S"
+ << "</expirationPeriod>";
+ }
- std::cout << "<faceScope>" << faceStatus.getFaceScope()
- << "</faceScope>";
- std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
- << "</facePersistency>";
- std::cout << "<linkType>" << faceStatus.getLinkType()
- << "</linkType>";
+ std::cout << "<faceScope>" << faceStatus.getFaceScope()
+ << "</faceScope>";
+ std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
+ << "</facePersistency>";
+ std::cout << "<linkType>" << faceStatus.getLinkType()
+ << "</linkType>";
- std::cout << "<packetCounters>";
- std::cout << "<incomingPackets>";
- std::cout << "<nInterests>" << faceStatus.getNInInterests()
- << "</nInterests>";
- std::cout << "<nDatas>" << faceStatus.getNInDatas()
- << "</nDatas>";
- std::cout << "</incomingPackets>";
- std::cout << "<outgoingPackets>";
- std::cout << "<nInterests>" << faceStatus.getNOutInterests()
- << "</nInterests>";
- std::cout << "<nDatas>" << faceStatus.getNOutDatas()
- << "</nDatas>";
- std::cout << "</outgoingPackets>";
- std::cout << "</packetCounters>";
+ std::cout << "<packetCounters>";
+ std::cout << "<incomingPackets>";
+ std::cout << "<nInterests>" << faceStatus.getNInInterests()
+ << "</nInterests>";
+ std::cout << "<nDatas>" << faceStatus.getNInDatas()
+ << "</nDatas>";
+ std::cout << "</incomingPackets>";
+ std::cout << "<outgoingPackets>";
+ std::cout << "<nInterests>" << faceStatus.getNOutInterests()
+ << "</nInterests>";
+ std::cout << "<nDatas>" << faceStatus.getNOutDatas()
+ << "</nDatas>";
+ std::cout << "</outgoingPackets>";
+ std::cout << "</packetCounters>";
- std::cout << "<byteCounters>";
- std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
- << "</incomingBytes>";
- std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
- << "</outgoingBytes>";
- std::cout << "</byteCounters>";
+ std::cout << "<byteCounters>";
+ std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
+ << "</incomingBytes>";
+ std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
+ << "</outgoingBytes>";
+ std::cout << "</byteCounters>";
- std::cout << "</face>";
- }
- std::cout << "</faces>";
+ std::cout << "</face>";
}
- else
- {
- std::cout << "Faces:" << std::endl;
+ std::cout << "</faces>";
+ }
+ else {
+ std::cout << "Faces:" << std::endl;
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
+ break;
+ }
- offset += block.size();
+ offset += block.size();
- nfd::FaceStatus faceStatus(block);
+ nfd::FaceStatus faceStatus(block);
- std::cout << " faceid=" << faceStatus.getFaceId()
- << " remote=" << faceStatus.getRemoteUri()
- << " local=" << faceStatus.getLocalUri();
- if (faceStatus.hasExpirationPeriod()) {
- std::cout << " expires="
- << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
- .count() << "s";
- }
- std::cout << " counters={"
- << "in={" << faceStatus.getNInInterests() << "i "
- << faceStatus.getNInDatas() << "d "
- << faceStatus.getNInBytes() << "B}"
- << " out={" << faceStatus.getNOutInterests() << "i "
- << faceStatus.getNOutDatas() << "d "
- << faceStatus.getNOutBytes() << "B}"
- << "}";
- std::cout << " " << faceStatus.getFaceScope()
- << " " << faceStatus.getFacePersistency()
- << " " << faceStatus.getLinkType();
- std::cout << std::endl;
- }
- }
+ std::cout << " faceid=" << faceStatus.getFaceId()
+ << " remote=" << faceStatus.getRemoteUri()
+ << " local=" << faceStatus.getLocalUri();
+ if (faceStatus.hasExpirationPeriod()) {
+ std::cout << " expires="
+ << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
+ .count() << "s";
+ }
+ std::cout << " counters={"
+ << "in={" << faceStatus.getNInInterests() << "i "
+ << faceStatus.getNInDatas() << "d "
+ << faceStatus.getNInBytes() << "B}"
+ << " out={" << faceStatus.getNOutInterests() << "i "
+ << faceStatus.getNOutDatas() << "d "
+ << faceStatus.getNOutBytes() << "B}"
+ << "}";
+ std::cout << " " << faceStatus.getFaceScope()
+ << " " << faceStatus.getFacePersistency()
+ << " " << faceStatus.getLinkType();
+ std::cout << std::endl;
+ }
+ }
runNextStep();
}
@@ -498,77 +490,69 @@
afterFetchedFibEnumerationInformation()
{
ConstBufferPtr buf = m_buffer->buf();
- if (m_isOutputXml)
- {
- std::cout << "<fib>";
+ if (m_isOutputXml) {
+ std::cout << "<fib>";
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FibEntry TLV";
- break;
- }
- offset += block.size();
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FibEntry TLV";
+ break;
+ }
+ offset += block.size();
- nfd::FibEntry fibEntry(block);
+ nfd::FibEntry fibEntry(block);
- std::cout << "<fibEntry>";
- std::string prefix(fibEntry.getPrefix().toUri());
- escapeSpecialCharacters(&prefix);
- std::cout << "<prefix>" << prefix << "</prefix>";
- std::cout << "<nextHops>";
- for (std::list<nfd::NextHopRecord>::const_iterator
- nextHop = fibEntry.getNextHopRecords().begin();
- nextHop != fibEntry.getNextHopRecords().end();
- ++nextHop)
- {
- std::cout << "<nextHop>" ;
- std::cout << "<faceId>" << nextHop->getFaceId() << "</faceId>";
- std::cout << "<cost>" << nextHop->getCost() << "</cost>";
- std::cout << "</nextHop>";
- }
- std::cout << "</nextHops>";
- std::cout << "</fibEntry>";
- }
-
- std::cout << "</fib>";
+ std::cout << "<fibEntry>";
+ std::string prefix(fibEntry.getPrefix().toUri());
+ escapeSpecialCharacters(&prefix);
+ std::cout << "<prefix>" << prefix << "</prefix>";
+ std::cout << "<nextHops>";
+ for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
+ std::cout << "<nextHop>" ;
+ std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>";
+ std::cout << "<cost>" << nextHop.getCost() << "</cost>";
+ std::cout << "</nextHop>";
+ }
+ std::cout << "</nextHops>";
+ std::cout << "</fibEntry>";
}
- else
- {
- std::cout << "FIB:" << std::endl;
+ std::cout << "</fib>";
+ }
+ else {
+ std::cout << "FIB:" << std::endl;
+
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
- break;
- }
- offset += block.size();
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
+ break;
+ }
+ offset += block.size();
- nfd::FibEntry fibEntry(block);
+ nfd::FibEntry fibEntry(block);
- std::cout << " " << fibEntry.getPrefix() << " nexthops={";
- for (std::list<nfd::NextHopRecord>::const_iterator
- nextHop = fibEntry.getNextHopRecords().begin();
- nextHop != fibEntry.getNextHopRecords().end();
- ++nextHop)
- {
- if (nextHop != fibEntry.getNextHopRecords().begin())
- std::cout << ", ";
- std::cout << "faceid=" << nextHop->getFaceId()
- << " (cost=" << nextHop->getCost() << ")";
- }
- std::cout << "}" << std::endl;
- }
+ std::cout << " " << fibEntry.getPrefix() << " nexthops={";
+ bool isFirst = true;
+ for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
+ if (isFirst)
+ isFirst = false;
+ else
+ std::cout << ", ";
+
+ std::cout << "faceid=" << nextHop.getFaceId()
+ << " (cost=" << nextHop.getCost() << ")";
+ }
+ std::cout << "}" << std::endl;
}
+ }
runNextStep();
}
@@ -594,63 +578,59 @@
afterFetchedStrategyChoiceInformationInformation()
{
ConstBufferPtr buf = m_buffer->buf();
- if (m_isOutputXml)
- {
- std::cout << "<strategyChoices>";
+ if (m_isOutputXml) {
+ std::cout << "<strategyChoices>";
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode StrategyChoice TLV";
- break;
- }
- offset += block.size();
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode StrategyChoice TLV";
+ break;
+ }
+ offset += block.size();
- nfd::StrategyChoice strategyChoice(block);
+ nfd::StrategyChoice strategyChoice(block);
- std::cout << "<strategyChoice>";
+ std::cout << "<strategyChoice>";
- std::string name(strategyChoice.getName().toUri());
- escapeSpecialCharacters(&name);
- std::cout << "<namespace>" << name << "</namespace>";
- std::cout << "<strategy>";
+ std::string name(strategyChoice.getName().toUri());
+ escapeSpecialCharacters(&name);
+ std::cout << "<namespace>" << name << "</namespace>";
+ std::cout << "<strategy>";
- std::string strategy(strategyChoice.getStrategy().toUri());
- escapeSpecialCharacters(&strategy);
+ std::string strategy(strategyChoice.getStrategy().toUri());
+ escapeSpecialCharacters(&strategy);
- std::cout << "<name>" << strategy << "</name>";
- std::cout << "</strategy>";
- std::cout << "</strategyChoice>";
- }
-
- std::cout << "</strategyChoices>";
+ std::cout << "<name>" << strategy << "</name>";
+ std::cout << "</strategy>";
+ std::cout << "</strategyChoice>";
}
- else
- {
- std::cout << "Strategy choices:" << std::endl;
+ std::cout << "</strategyChoices>";
+ }
+ else {
+ std::cout << "Strategy choices:" << std::endl;
+
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
- break;
- }
- offset += block.size();
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
+ break;
+ }
+ offset += block.size();
- nfd::StrategyChoice strategyChoice(block);
+ nfd::StrategyChoice strategyChoice(block);
- std::cout << " " << strategyChoice.getName()
- << " strategy=" << strategyChoice.getStrategy() << std::endl;
- }
+ std::cout << " " << strategyChoice.getName()
+ << " strategy=" << strategyChoice.getStrategy() << std::endl;
}
+ }
runNextStep();
}
@@ -674,106 +654,98 @@
afterFetchedRibStatusInformation()
{
ConstBufferPtr buf = m_buffer->buf();
- if (m_isOutputXml)
- {
- std::cout << "<rib>";
+ if (m_isOutputXml) {
+ std::cout << "<rib>";
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode RibEntry TLV";
- break;
- }
- offset += block.size();
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode RibEntry TLV";
+ break;
+ }
+ offset += block.size();
- nfd::RibEntry ribEntry(block);
+ nfd::RibEntry ribEntry(block);
- std::cout << "<ribEntry>";
- std::string prefix(ribEntry.getName().toUri());
- escapeSpecialCharacters(&prefix);
- std::cout << "<prefix>" << prefix << "</prefix>";
- std::cout << "<routes>";
- for (std::list<nfd::Route>::const_iterator
- nextRoute = ribEntry.begin();
- nextRoute != ribEntry.end();
- ++nextRoute)
- {
- std::cout << "<route>" ;
- std::cout << "<faceId>" << nextRoute->getFaceId() << "</faceId>";
- std::cout << "<origin>" << nextRoute->getOrigin() << "</origin>";
- std::cout << "<cost>" << nextRoute->getCost() << "</cost>";
+ std::cout << "<ribEntry>";
+ std::string prefix(ribEntry.getName().toUri());
+ escapeSpecialCharacters(&prefix);
+ std::cout << "<prefix>" << prefix << "</prefix>";
+ std::cout << "<routes>";
+ for (const nfd::Route& nextRoute : ribEntry) {
+ std::cout << "<route>" ;
+ std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>";
+ std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>";
+ std::cout << "<cost>" << nextRoute.getCost() << "</cost>";
- std::cout << "<flags>";
- if (nextRoute->isChildInherit())
- std::cout << "<childInherit/>";
- if (nextRoute->isRibCapture())
- std::cout << "<ribCapture/>";
- std::cout << "</flags>";
+ std::cout << "<flags>";
+ if (nextRoute.isChildInherit())
+ std::cout << "<childInherit/>";
+ if (nextRoute.isRibCapture())
+ std::cout << "<ribCapture/>";
+ std::cout << "</flags>";
- if (!nextRoute->hasInfiniteExpirationPeriod()) {
- std::cout << "<expirationPeriod>PT"
- << time::duration_cast<time::seconds>(nextRoute->getExpirationPeriod())
- .count() << "S"
- << "</expirationPeriod>";
- }
- std::cout << "</route>";
- }
- std::cout << "</routes>";
- std::cout << "</ribEntry>";
+ if (!nextRoute.hasInfiniteExpirationPeriod()) {
+ std::cout << "<expirationPeriod>PT"
+ << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
+ .count() << "S"
+ << "</expirationPeriod>";
}
-
- std::cout << "</rib>";
+ std::cout << "</route>";
+ }
+ std::cout << "</routes>";
+ std::cout << "</ribEntry>";
}
- else
- {
- std::cout << "RIB:" << std::endl;
+ std::cout << "</rib>";
+ }
+ else {
+ std::cout << "RIB:" << std::endl;
+
+ size_t offset = 0;
+ while (offset < buf->size()) {
+ bool isOk = false;
Block block;
- size_t offset = 0;
- while (offset < buf->size())
- {
- bool ok = Block::fromBuffer(buf, offset, block);
- if (!ok)
- {
- std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
- break;
- }
+ std::tie(isOk, block) = Block::fromBuffer(buf, offset);
+ if (!isOk) {
+ std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
+ break;
+ }
- offset += block.size();
+ offset += block.size();
- nfd::RibEntry ribEntry(block);
+ nfd::RibEntry ribEntry(block);
- std::cout << " " << ribEntry.getName().toUri() << " route={";
- for (std::list<nfd::Route>::const_iterator
- nextRoute = ribEntry.begin();
- nextRoute != ribEntry.end();
- ++nextRoute)
- {
- if (nextRoute != ribEntry.begin())
- std::cout << ", ";
- std::cout << "faceid=" << nextRoute->getFaceId()
- << " (origin=" << nextRoute->getOrigin()
- << " cost=" << nextRoute->getCost();
- if (!nextRoute->hasInfiniteExpirationPeriod()) {
- std::cout << " expires="
- << time::duration_cast<time::seconds>(nextRoute->getExpirationPeriod())
- .count() << "s";
- }
+ std::cout << " " << ribEntry.getName().toUri() << " route={";
+ bool isFirst = true;
+ for (const nfd::Route& nextRoute : ribEntry) {
+ if (isFirst)
+ isFirst = false;
+ else
+ std::cout << ", ";
- if (nextRoute->isChildInherit())
- std::cout << " ChildInherit";
- if (nextRoute->isRibCapture())
- std::cout << " RibCapture";
-
- std::cout << ")";
- }
- std::cout << "}" << std::endl;
+ std::cout << "faceid=" << nextRoute.getFaceId()
+ << " (origin=" << nextRoute.getOrigin()
+ << " cost=" << nextRoute.getCost();
+ if (!nextRoute.hasInfiniteExpirationPeriod()) {
+ std::cout << " expires="
+ << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
+ .count() << "s";
}
- }
+
+ if (nextRoute.isChildInherit())
+ std::cout << " ChildInherit";
+ if (nextRoute.isRibCapture())
+ std::cout << " RibCapture";
+
+ std::cout << ")";
+ }
+ std::cout << "}" << std::endl;
+ }
+ }
runNextStep();
}
diff --git a/tools/nfdc.cpp b/tools/nfdc.cpp
index 02fe28a..207d3ee 100644
--- a/tools/nfdc.cpp
+++ b/tools/nfdc.cpp
@@ -178,10 +178,11 @@
const ndn::util::FaceUri& canonicalUri)
{
size_t offset = 0;
+ bool isOk = false;
ndn::Block block;
- bool ok = ndn::Block::fromBuffer(data, offset, block);
+ std::tie(isOk, block) = ndn::Block::fromBuffer(data, offset);
- if (!ok) {
+ if (!isOk) {
if (m_allowCreate) {
startFaceCreate(canonicalUri);
}