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 "meta-info.hpp"
26 #include "name.hpp"
27 #include "packet-base.hpp"
28 #include "signature.hpp"
29 #include "encoding/block.hpp"
30 
31 namespace ndn {
32 
35 class Data : public PacketBase, public enable_shared_from_this<Data>
36 {
37 public:
38  class Error : public tlv::Error
39  {
40  public:
41  explicit
42  Error(const std::string& what)
43  : tlv::Error(what)
44  {
45  }
46  };
47 
52  explicit
53  Data(const Name& name = Name());
54 
61  explicit
62  Data(const Block& wire);
63 
71  template<encoding::Tag TAG>
72  size_t
73  wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const;
74 
91  const Block&
92  wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const;
93 
101  const Block&
102  wireEncode() const;
103 
106  void
107  wireDecode(const Block& wire);
108 
111  bool
112  hasWire() const
113  {
114  return m_wire.hasWire();
115  }
116 
121  const Name&
122  getFullName() const;
123 
124 public: // Data fields
127  const Name&
128  getName() const
129  {
130  return m_name;
131  }
132 
136  Data&
137  setName(const Name& name);
138 
141  const MetaInfo&
142  getMetaInfo() const
143  {
144  return m_metaInfo;
145  }
146 
150  Data&
151  setMetaInfo(const MetaInfo& metaInfo);
152 
158  const Block&
159  getContent() const;
160 
168  Data&
169  setContent(const Block& block);
170 
176  Data&
177  setContent(const uint8_t* value, size_t valueSize);
178 
183  Data&
184  setContent(const ConstBufferPtr& value);
185 
188  const Signature&
189  getSignature() const
190  {
191  return m_signature;
192  }
193 
197  Data&
198  setSignature(const Signature& signature);
199 
203  Data&
204  setSignatureValue(const Block& value);
205 
206 public: // MetaInfo fields
207  uint32_t
209  {
210  return m_metaInfo.getType();
211  }
212 
213  Data&
214  setContentType(uint32_t type);
215 
216  time::milliseconds
218  {
219  return m_metaInfo.getFreshnessPeriod();
220  }
221 
222  Data&
223  setFreshnessPeriod(time::milliseconds freshnessPeriod);
224 
227  {
228  return m_metaInfo.getFinalBlock();
229  }
230 
231  Data&
233 
239  getFinalBlockId() const;
240 
245  Data&
246  setFinalBlockId(const name::Component& finalBlockId);
247 
248 protected:
252  void
253  resetWire();
254 
255 private:
256  Name m_name;
257  MetaInfo m_metaInfo;
258  Block m_content;
259  Signature m_signature;
260 
261  mutable Block m_wire;
262  mutable Name m_fullName;
263 };
264 
265 #ifndef DOXYGEN
266 extern template size_t
267 Data::wireEncode<encoding::EncoderTag>(EncodingBuffer&, bool) const;
268 
269 extern template size_t
270 Data::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, bool) const;
271 #endif
272 
273 std::ostream&
274 operator<<(std::ostream& os, const Data& data);
275 
276 bool
277 operator==(const Data& lhs, const Data& rhs);
278 
279 inline bool
280 operator!=(const Data& lhs, const Data& rhs)
281 {
282  return !(lhs == rhs);
283 }
284 
285 } // namespace ndn
286 
287 #endif // NDN_DATA_HPP
Error(const std::string &what)
Definition: data.hpp:42
const Block & wireEncode() const
Encode to a Block.
Definition: data.cpp:106
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:252
Data & setContentType(uint32_t type)
Definition: data.cpp:290
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getName() const
Get name.
Definition: data.hpp:128
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
Definition: data.cpp:122
const Block & getContent() const
Get Content.
Definition: data.cpp:234
Data & setSignature(const Signature &signature)
Set Signature.
Definition: data.cpp:274
Data & setName(const Name &name)
Set name.
Definition: data.cpp:218
NDN_CXX_DEPRECATED name::Component getFinalBlockId() const
Definition: data.cpp:314
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:337
Data(const Name &name=Name())
Construct an unsigned Data packet with given name and empty Content.
Definition: data.cpp:35
Data & setContent(const Block &block)
Set Content from a block.
Definition: data.cpp:243
void resetWire()
Clear wire encoding and cached FullName.
Definition: data.cpp:211
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:280
uint32_t getType() const
return ContentType
Definition: meta-info.hpp:95
Data & setSignatureValue(const Block &value)
Set SignatureValue.
Definition: data.cpp:282
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:189
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:58
time::milliseconds getFreshnessPeriod() const
return FreshnessPeriod
Definition: meta-info.hpp:111
base class to allow simple management of packet tags
Definition: packet-base.hpp:31
bool hasWire() const
Check if this instance has cached wire encoding.
Definition: data.hpp:112
Represents an absolute name.
Definition: name.hpp:42
const optional< name::Component > & getFinalBlock() const
return FinalBlockId
Definition: meta-info.hpp:125
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:197
Represents a name component.
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Definition: data.cpp:298
Data & setFinalBlock(optional< name::Component > finalBlockId)
Definition: data.cpp:306
const MetaInfo & getMetaInfo() const
Get MetaInfo.
Definition: data.hpp:142
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:328
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
Definition: data.cpp:226
#define NDN_CXX_DEPRECATED
Mark a type, variable, or function as deprecated.
Definition: backports.hpp:75
NDN_CXX_DEPRECATED Data & setFinalBlockId(const name::Component &finalBlockId)
Definition: data.cpp:320
time::milliseconds getFreshnessPeriod() const
Definition: data.hpp:217
Represents a Data packet.
Definition: data.hpp:35
uint32_t getContentType() const
Definition: data.hpp:208
const optional< name::Component > & getFinalBlock() const
Definition: data.hpp:226
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
EncodingImpl< EstimatorTag > EncodingEstimator
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89