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
35
GeoTag::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
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
&
53
GeoTag::wireEncode
()
const
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
71
GeoTag::wireDecode
(
const
Block
& wire)
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
ndn::Block::elements
const element_container & elements() const
Get container of sub-elements.
Definition:
block.hpp:391
ndn::lp::GeoTag::GeoTag
GeoTag()=default
geo-tag.hpp
ndn::lp::tlv::GeoTag
@ GeoTag
Definition:
tlv.hpp:39
ndn::lp::tlv::GeoTagPos
@ GeoTagPos
Definition:
tlv.hpp:40
ndn::lp::GeoTag::wireEncode
const Block & wireEncode() const
encode GeoTag into wire format
Definition:
geo-tag.cpp:53
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:39
ndn::Block::type
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition:
block.hpp:274
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
tlv.hpp
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition:
block.cpp:325
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:36
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:43
ndn::encoding::prependDoubleBlock
size_t prependDoubleBlock(EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing an IEEE 754 double-precision floating-point number.
Definition:
block-helpers.cpp:133
ndn::lp::GeoTag::wireDecode
void wireDecode(const Block &wire)
get GeoTag from wire format
Definition:
geo-tag.cpp:71
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition:
block.hpp:230
ndn::lp
Definition:
cache-policy.cpp:28
ndn::encoding::readDouble
double readDouble(const Block &block)
Read TLV-VALUE of a TLV element as an IEEE 754 double-precision floating-point number.
Definition:
block-helpers.cpp:160
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition:
tlv.hpp:53
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:38
ndnSIM
ndn-cxx
ndn-cxx
lp
geo-tag.cpp
Generated on Mon Jun 1 2020 22:32:14 for ndnSIM by
1.8.18