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
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:249
Data & setContentType(uint32_t type)
Definition: data.cpp:289
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getName() const
Get name.
Definition: data.hpp:124
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:233
Data & setSignature(const Signature &signature)
Set Signature.
Definition: data.cpp:273
Data & setName(const Name &name)
Set name.
Definition: data.cpp:217
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
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:242
void resetWire()
Clear wire encoding and cached FullName.
Definition: data.cpp:210
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:262
uint32_t getType() const
return ContentType
Definition: meta-info.hpp:91
Data & setSignatureValue(const Block &value)
Set SignatureValue.
Definition: data.cpp:281
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:185
A 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:107
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:108
Represents an absolute name.
Definition: name.hpp:43
const optional< name::Component > & getFinalBlock() const
return FinalBlockId
Definition: meta-info.hpp:121
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:196
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Definition: data.cpp:297
Data & setFinalBlock(optional< name::Component > finalBlockId)
Definition: data.cpp:305
const MetaInfo & getMetaInfo() const
Get MetaInfo.
Definition: data.hpp:138
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:313
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
Definition: data.cpp:225
time::milliseconds getFreshnessPeriod() const
Definition: data.hpp:213
Represents a Data packet.
Definition: data.hpp:35
uint32_t getContentType() const
Definition: data.hpp:204
const optional< name::Component > & getFinalBlock() const
Definition: data.hpp:222
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
EncodingImpl< EstimatorTag > EncodingEstimator
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126