25 #include <ndn-cxx/util/concepts.hpp> 26 #include <ndn-cxx/encoding/block-helpers.hpp> 31 BOOST_CONCEPT_ASSERT((ndn::WireEncodable<Adjacency>));
32 BOOST_CONCEPT_ASSERT((ndn::WireDecodable<Adjacency>));
33 static_assert(std::is_base_of<ndn::tlv::Error, Adjacency::Error>::value,
34 "Adjacency::Error must inherit from tlv::Error");
46 template<ndn::encoding::Tag TAG>
50 size_t totalLength = 0;
54 totalLength += encoder.prependByteArrayBlock(
57 totalLength += m_name.wireEncode(encoder);
59 totalLength += encoder.prependVarNumber(totalLength);
66 Adjacency::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block)
const;
69 Adjacency::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block)
const;
74 if (m_wire.hasWire()) {
78 ndn::EncodingEstimator estimator;
81 ndn::EncodingBuffer buffer(estimatedSize, 0);
84 m_wire = buffer.block();
99 std::stringstream error;
100 error <<
"Expected Adjacency Block, but Block is of a different type: #" 102 throw Error(error.str());
107 ndn::Block::element_const_iterator val = m_wire.elements_begin();
109 if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
110 m_name.wireDecode(*val);
114 throw Error(
"Missing required Name field");
118 m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
122 throw Error(
"Missing required Uri field");
126 m_cost = ndn::readNonNegativeInteger(*val);
130 throw Error(
"Missing required Cost field");
138 <<
"Name: " << adjacency.
getName() <<
", " 139 <<
"Uri: " << adjacency.
getUri() <<
", " 140 <<
"Cost: " << adjacency.
getCost() <<
")";
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the object contained in the given block.
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
const std::string & getUri() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::Name & getName() const
std::ostream & operator<<(std::ostream &os, const AdjacencyLsa &adjacencyLsa)
Data abstraction for Adjacency.