26 #include <ndn-cxx/util/concepts.hpp> 27 #include <ndn-cxx/encoding/block-helpers.hpp> 36 BOOST_CONCEPT_ASSERT((ndn::WireEncodable<CoordinateLsa>));
37 BOOST_CONCEPT_ASSERT((ndn::WireDecodable<CoordinateLsa>));
38 static_assert(std::is_base_of<ndn::tlv::Error, CoordinateLsa::Error>::value,
39 "CoordinateLsa::Error must inherit from tlv::Error");
42 : m_hyperbolicRadius(0.0)
51 template<ndn::encoding::Tag TAG>
55 size_t totalLength = 0;
56 size_t doubleLength = 10;
58 const uint8_t* doubleBytes1;
59 for (
auto it = m_hyperbolicAngle.rbegin(); it != m_hyperbolicAngle.rend(); ++it) {
60 doubleBytes1 =
reinterpret_cast<const uint8_t*
>(&*it);
63 totalLength += block.prependVarNumber(doubleLength);
67 const uint8_t* doubleBytes2 =
reinterpret_cast<const uint8_t*
>(&m_hyperbolicRadius);
69 totalLength += block.prependVarNumber(doubleLength);
74 totalLength += block.prependVarNumber(totalLength);
81 CoordinateLsa::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block)
const;
84 CoordinateLsa::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block)
const;
89 if (m_wire.hasWire()) {
93 ndn::EncodingEstimator estimator;
96 ndn::EncodingBuffer buffer(estimatedSize, 0);
99 m_wire = buffer.block();
107 m_hyperbolicRadius = 0.0;
108 m_hyperbolicAngle.clear();
113 std::stringstream error;
114 error <<
"Expected CoordinateLsa Block, but Block is of a different type: #" 116 BOOST_THROW_EXCEPTION(
Error(error.str()));
121 ndn::Block::element_const_iterator val = m_wire.elements_begin();
128 std::cout <<
"Missing required LsaInfo field" << std::endl;
129 BOOST_THROW_EXCEPTION(
Error(
"Missing required LsaInfo field"));
134 ndn::Block::element_const_iterator it = val->elements_begin();
136 m_hyperbolicRadius = *
reinterpret_cast<const double*
>(it->value());
141 std::cout <<
"HyperbolicRadius: Missing required Double field" << std::endl;
142 BOOST_THROW_EXCEPTION(
Error(
"HyperbolicRadius: Missing required Double field"));
146 std::cout <<
"Missing required HyperbolicRadius field" << std::endl;
147 BOOST_THROW_EXCEPTION(
Error(
"Missing required HyperbolicRadius field"));
150 for (; val != m_wire.elements_end(); ++val) {
154 for (
auto it = val->elements_begin(); it != val->elements_end(); ++it) {
156 m_hyperbolicAngle.push_back(*reinterpret_cast<const double*>(it->value()));
159 std::cout <<
"HyperbolicAngle: Missing required Double field" << std::endl;
160 BOOST_THROW_EXCEPTION(
Error(
"HyperbolicAngle: Missing required Double field"));
170 os <<
"CoordinateLsa(" 174 os <<
"HyperbolicAngles: ";
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
Encodes LSA info using the method in TAG.
const LsaInfo & getLsaInfo() const
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
Data abstraction for CoordinateLsa.
#define INIT_LOGGER(name)
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
const std::vector< double > getHyperbolicAngle() const
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
double getHyperbolicRadius() const
std::ostream & operator<<(std::ostream &os, const AdjacencyLsa &adjacencyLsa)
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the one contained in the given block.
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the one contained in the given block.