NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-channel-status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nfd-channel-status.hpp"
23 #include "encoding/tlv-nfd.hpp"
25 #include "util/concepts.hpp"
26 
27 namespace ndn {
28 namespace nfd {
29 
30 //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ChannelStatus>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<ChannelStatus>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<ChannelStatus>));
33 static_assert(std::is_base_of<tlv::Error, ChannelStatus::Error>::value,
34  "ChannelStatus::Error must inherit from tlv::Error");
35 
37 {
38 }
39 
41 {
42  this->wireDecode(payload);
43 }
44 
45 template<encoding::Tag TAG>
46 size_t
47 ChannelStatus::wireEncode(EncodingImpl<TAG>& encoder) const
48 {
49  size_t totalLength = 0;
50 
51  totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri,
52  reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
53 
54  totalLength += encoder.prependVarNumber(totalLength);
55  totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus);
56  return totalLength;
57 }
58 
59 template size_t
60 ChannelStatus::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>&) const;
61 
62 template size_t
63 ChannelStatus::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
64 
65 const Block&
67 {
68  if (m_wire.hasWire())
69  return m_wire;
70 
71  EncodingEstimator estimator;
72  size_t estimatedSize = wireEncode(estimator);
73 
74  EncodingBuffer buffer(estimatedSize, 0);
75  wireEncode(buffer);
76 
77  m_wire = buffer.block();
78  return m_wire;
79 }
80 
81 void
83 {
84  if (block.type() != tlv::nfd::ChannelStatus) {
85  BOOST_THROW_EXCEPTION(Error("Expecting ChannelStatus block"));
86  }
87  m_wire = block;
88  m_wire.parse();
90 
91  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
92  m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
93  ++val;
94  }
95  else {
96  BOOST_THROW_EXCEPTION(Error("Missing required LocalUri field"));
97  }
98 }
99 
101 ChannelStatus::setLocalUri(const std::string localUri)
102 {
103  m_wire.reset();
104  m_localUri = localUri;
105  return *this;
106 }
107 
108 } // namespace nfd
109 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EstimatorTag > EncodingEstimator
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
element_const_iterator elements_end() const
Definition: block.cpp:595
element_const_iterator elements_begin() const
Definition: block.cpp:589
EncodingImpl< EncoderTag > EncodingBuffer
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
const Block & wireEncode() const
element_container::const_iterator element_const_iterator
Definition: block.hpp:48
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
uint32_t type() const
Definition: block.hpp:346
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
represents NFD Channel Status dataset
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:34
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:70
void wireDecode(const Block &wire)
ChannelStatus & setLocalUri(const std::string localUri)