NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
geo-tag.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "ndn-cxx/lp/geo-tag.hpp"
23 #include "ndn-cxx/lp/tlv.hpp"
24 
25 namespace ndn {
26 namespace lp {
27 
28 GeoTag::GeoTag(const Block& block)
29 {
30  wireDecode(block);
31 }
32 
33 template<encoding::Tag TAG>
34 size_t
36 {
37  size_t length = 0;
38  length += prependDoubleBlock(encoder, tlv::GeoTagPos, std::get<2>(m_pos));
39  length += prependDoubleBlock(encoder, tlv::GeoTagPos, std::get<1>(m_pos));
40  length += prependDoubleBlock(encoder, tlv::GeoTagPos, std::get<0>(m_pos));
41  length += encoder.prependVarNumber(length);
42  length += encoder.prependVarNumber(tlv::GeoTag);
43  return length;
44 }
45 
46 template size_t
47 GeoTag::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder) const;
48 
49 template size_t
50 GeoTag::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder) const;
51 
52 const Block&
54 {
55  if (m_wire.hasWire()) {
56  return m_wire;
57  }
58 
59  EncodingEstimator estimator;
60  size_t estimatedSize = wireEncode(estimator);
61 
62  EncodingBuffer buffer(estimatedSize, 0);
63  wireEncode(buffer);
64 
65  m_wire = buffer.block();
66 
67  return m_wire;
68 }
69 
70 void
72 {
73  if (wire.type() != tlv::GeoTag) {
74  NDN_THROW(ndn::tlv::Error("expecting GeoTag block"));
75  }
76 
77  m_wire = wire;
78  m_wire.parse();
79 
80  if (m_wire.elements().size() < 3 ||
81  m_wire.elements()[0].type() != tlv::GeoTagPos ||
82  m_wire.elements()[1].type() != tlv::GeoTagPos ||
83  m_wire.elements()[2].type() != tlv::GeoTagPos) {
84  NDN_THROW(ndn::tlv::Error("Unexpected input while decoding GeoTag"));
85  }
86  m_pos = {encoding::readDouble(m_wire.elements()[0]),
87  encoding::readDouble(m_wire.elements()[1]),
88  encoding::readDouble(m_wire.elements()[2])};
89 }
90 
91 } // namespace lp
92 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:324
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:221
GeoTag()=default
const element_container & elements() const
Get container of sub-elements.
Definition: block.hpp:425
#define NDN_THROW(e)
Definition: exception.hpp:61
void wireDecode(const Block &wire)
get GeoTag from wire format
Definition: geo-tag.cpp:71
double readDouble(const Block &block)
Read TLV-VALUE of a TLV element as an IEEE 754 double-precision floating-point number.
const Block & wireEncode() const
encode GeoTag into wire format
Definition: geo-tag.cpp:53
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition: block.hpp:277
size_t prependDoubleBlock(EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing an IEEE 754 double-precision floating-point number.
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
EncodingImpl< EstimatorTag > EncodingEstimator