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);
70 if (m_wire.hasWire()) {
74 ndn::EncodingEstimator estimator;
77 ndn::EncodingBuffer buffer(estimatedSize, 0);
80 m_wire = buffer.block();
95 BOOST_THROW_EXCEPTION(
Error(
"Expected Adjacency Block, but Block is of a different type: #" +
96 ndn::to_string(m_wire.type())));
101 ndn::Block::element_const_iterator val = m_wire.elements_begin();
103 if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
104 m_name.wireDecode(*val);
108 BOOST_THROW_EXCEPTION(
Error(
"Missing required Name field"));
112 m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
116 BOOST_THROW_EXCEPTION(
Error(
"Missing required Uri field"));
120 m_cost = ndn::readNonNegativeInteger(*val);
124 BOOST_THROW_EXCEPTION(
Error(
"Missing required Cost field"));
132 <<
"Name: " << adjacency.
getName() <<
", " 133 <<
"Uri: " << adjacency.
getUri() <<
", " 134 <<
"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
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(AdjacencyLsa)
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.