25 #include <ndn-cxx/util/concepts.hpp> 26 #include <ndn-cxx/encoding/block-helpers.hpp> 33 BOOST_CONCEPT_ASSERT((ndn::WireEncodable<CoordinateLsa>));
34 BOOST_CONCEPT_ASSERT((ndn::WireDecodable<CoordinateLsa>));
35 static_assert(std::is_base_of<ndn::tlv::Error, CoordinateLsa::Error>::value,
36 "CoordinateLsa::Error must inherit from tlv::Error");
39 : m_hyperbolicRadius(0.0)
48 template<ndn::encoding::Tag TAG>
52 size_t totalLength = 0;
53 size_t doubleLength = 10;
55 const uint8_t* doubleBytes1;
56 for (
auto it = m_hyperbolicAngle.rbegin(); it != m_hyperbolicAngle.rend(); ++it) {
57 doubleBytes1 =
reinterpret_cast<const uint8_t*
>(&*it);
60 totalLength += block.prependVarNumber(doubleLength);
64 const uint8_t* doubleBytes2 =
reinterpret_cast<const uint8_t*
>(&m_hyperbolicRadius);
66 totalLength += block.prependVarNumber(doubleLength);
71 totalLength += block.prependVarNumber(totalLength);
78 CoordinateLsa::wireEncode<ndn::encoding::EncoderTag>(ndn::EncodingImpl<ndn::encoding::EncoderTag>& block)
const;
81 CoordinateLsa::wireEncode<ndn::encoding::EstimatorTag>(ndn::EncodingImpl<ndn::encoding::EstimatorTag>& block)
const;
86 if (m_wire.hasWire()) {
90 ndn::EncodingEstimator estimator;
93 ndn::EncodingBuffer buffer(estimatedSize, 0);
96 m_wire = buffer.block();
104 m_hyperbolicRadius = 0.0;
105 m_hyperbolicAngle.clear();
110 std::stringstream error;
111 error <<
"Expected CoordinateLsa Block, but Block is of a different type: #" 113 BOOST_THROW_EXCEPTION(
Error(error.str()));
118 ndn::Block::element_const_iterator val = m_wire.elements_begin();
125 std::cout <<
"Missing required LsaInfo field" << std::endl;
126 BOOST_THROW_EXCEPTION(
Error(
"Missing required LsaInfo field"));
131 ndn::Block::element_const_iterator it = val->elements_begin();
133 m_hyperbolicRadius = *
reinterpret_cast<const double*
>(it->value());
138 std::cout <<
"HyperbolicRadius: Missing required Double field" << std::endl;
139 BOOST_THROW_EXCEPTION(
Error(
"HyperbolicRadius: Missing required Double field"));
143 std::cout <<
"Missing required HyperbolicRadius field" << std::endl;
144 BOOST_THROW_EXCEPTION(
Error(
"Missing required HyperbolicRadius field"));
147 for (; val != m_wire.elements_end(); ++val) {
151 for (
auto it = val->elements_begin(); it != val->elements_end(); ++it) {
153 m_hyperbolicAngle.push_back(*reinterpret_cast<const double*>(it->value()));
156 std::cout <<
"HyperbolicAngle: Missing required Double field" << std::endl;
157 BOOST_THROW_EXCEPTION(
Error(
"HyperbolicAngle: Missing required Double field"));
167 os <<
"CoordinateLsa(" 171 os <<
"HyperbolicAngles: ";
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
Encodes LSA info using the method in TAG.
const LsaInfo & getLsaInfo() const
Data abstraction for CoordinateLsa.
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
const std::vector< double > getHyperbolicAngle() const
Copyright (c) 2014-2018, 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.