NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
data.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_DATA_HPP
23 #define NDN_DATA_HPP
24 
25 #include "ndn-cxx/meta-info.hpp"
26 #include "ndn-cxx/name.hpp"
27 #include "ndn-cxx/signature.hpp"
30 
31 namespace ndn {
32 
35 class Data : public PacketBase, public std::enable_shared_from_this<Data>
36 {
37 public:
38  class Error : public tlv::Error
39  {
40  public:
41  using tlv::Error::Error;
42  };
43 
48  explicit
49  Data(const Name& name = Name());
50 
57  explicit
58  Data(const Block& wire);
59 
67  template<encoding::Tag TAG>
68  size_t
69  wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const;
70 
87  const Block&
88  wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const;
89 
97  const Block&
98  wireEncode() const;
99 
102  void
103  wireDecode(const Block& wire);
104 
107  bool
108  hasWire() const
109  {
110  return m_wire.hasWire();
111  }
112 
117  const Name&
118  getFullName() const;
119 
120 public: // Data fields
123  const Name&
124  getName() const
125  {
126  return m_name;
127  }
128 
132  Data&
133  setName(const Name& name);
134 
137  const MetaInfo&
138  getMetaInfo() const
139  {
140  return m_metaInfo;
141  }
142 
146  Data&
147  setMetaInfo(const MetaInfo& metaInfo);
148 
154  const Block&
155  getContent() const;
156 
164  Data&
165  setContent(const Block& block);
166 
172  Data&
173  setContent(const uint8_t* value, size_t valueSize);
174 
179  Data&
180  setContent(ConstBufferPtr value);
181 
184  const Signature&
185  getSignature() const
186  {
187  return m_signature;
188  }
189 
193  Data&
194  setSignature(const Signature& signature);
195 
199  Data&
200  setSignatureValue(const Block& value);
201 
202 public: // MetaInfo fields
203  uint32_t
205  {
206  return m_metaInfo.getType();
207  }
208 
209  Data&
210  setContentType(uint32_t type);
211 
212  time::milliseconds
214  {
215  return m_metaInfo.getFreshnessPeriod();
216  }
217 
218  Data&
219  setFreshnessPeriod(time::milliseconds freshnessPeriod);
220 
221  const optional<name::Component>&
223  {
224  return m_metaInfo.getFinalBlock();
225  }
226 
227  Data&
228  setFinalBlock(optional<name::Component> finalBlockId);
229 
230 protected:
234  void
235  resetWire();
236 
237 private:
238  Name m_name;
239  MetaInfo m_metaInfo;
240  Block m_content;
241  Signature m_signature;
242 
243  mutable Block m_wire;
244  mutable Name m_fullName;
245 };
246 
247 #ifndef DOXYGEN
248 extern template size_t
249 Data::wireEncode<encoding::EncoderTag>(EncodingBuffer&, bool) const;
250 
251 extern template size_t
252 Data::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, bool) const;
253 #endif
254 
255 std::ostream&
256 operator<<(std::ostream& os, const Data& data);
257 
258 bool
259 operator==(const Data& lhs, const Data& rhs);
260 
261 inline bool
262 operator!=(const Data& lhs, const Data& rhs)
263 {
264  return !(lhs == rhs);
265 }
266 
267 } // namespace ndn
268 
269 #endif // NDN_DATA_HPP
ndn::Data::getContentType
uint32_t getContentType() const
Definition: data.hpp:204
ndn::Data::setContentType
Data & setContentType(uint32_t type)
Definition: data.cpp:288
ndn::Data::setMetaInfo
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
Definition: data.cpp:224
meta-info.hpp
ndn::MetaInfo::getType
uint32_t getType() const
return ContentType
Definition: meta-info.hpp:91
ndn::Data::resetWire
void resetWire()
Clear wire encoding and cached FullName.
Definition: data.cpp:209
block.hpp
ndn::MetaInfo::getFreshnessPeriod
time::milliseconds getFreshnessPeriod() const
return FreshnessPeriod
Definition: meta-info.hpp:107
ndn::Data::getContent
const Block & getContent() const
Get Content.
Definition: data.cpp:232
name.hpp
ndn::Data::setName
Data & setName(const Name &name)
Set name.
Definition: data.cpp:216
ndn::Data::getName
const Name & getName() const
Get name.
Definition: data.hpp:124
ndn::MetaInfo::getFinalBlock
const optional< name::Component > & getFinalBlock() const
return FinalBlockId
Definition: meta-info.hpp:121
ndn::MetaInfo
A MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:59
ndn::Data::hasWire
bool hasWire() const
Check if this instance has cached wire encoding.
Definition: data.hpp:108
ndn::Data::getFreshnessPeriod
time::milliseconds getFreshnessPeriod() const
Definition: data.hpp:213
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition: encoding-buffer-fwd.hpp:39
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
signature.hpp
ndn::Data::wireDecode
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
Definition: data.cpp:122
ndn::Signature
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:38
ndn::Data::setContent
Data & setContent(const Block &block)
Set Content from a block.
Definition: data.cpp:241
ndn::Data::setSignatureValue
Data & setSignatureValue(const Block &value)
Set SignatureValue.
Definition: data.cpp:280
ndn::Data::setFreshnessPeriod
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Definition: data.cpp:296
ndn::Data::Error
Definition: data.hpp:39
ndn::Data
Represents a Data packet.
Definition: data.hpp:36
ndn::Data::setSignature
Data & setSignature(const Signature &signature)
Set Signature.
Definition: data.cpp:272
ndn::tlv::Data
@ Data
Definition: tlv.hpp:66
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
ndn::Data::getFinalBlock
const optional< name::Component > & getFinalBlock() const
Definition: data.hpp:222
ndn::Data::setFinalBlock
Data & setFinalBlock(optional< name::Component > finalBlockId)
Definition: data.cpp:304
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::operator==
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:312
packet-base.hpp
ndn::operator<<
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
ndn::name
Definition: name-component-types.hpp:33
ndn::Data::wireEncode
const Block & wireEncode() const
Encode to a Block.
Definition: data.cpp:106
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:230
ndn::Data::getMetaInfo
const MetaInfo & getMetaInfo() const
Get MetaInfo.
Definition: data.hpp:138
ndn::Data::Data
Data(const Name &name=Name())
Construct an unsigned Data packet with given name and empty Content.
Definition: data.cpp:35
ndn::PacketBase
base class to allow simple management of packet tags
Definition: packet-base.hpp:32
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition: tlv.hpp:53
ndn::Data::getFullName
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:195
ndn::operator!=
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:262
ndn::tlv::Error::Error
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
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
ndn::Data::getSignature
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:185