NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22 #ifndef NDN_DATA_HPP
23 #define NDN_DATA_HPP
24 
25 #include "name.hpp"
26 #include "encoding/block.hpp"
27 
28 #include "signature.hpp"
29 #include "meta-info.hpp"
30 #include "key-locator.hpp"
31 #include "tag-host.hpp"
32 
33 namespace ndn {
34 
37 class Data : public TagHost, public enable_shared_from_this<Data>
38 {
39 public:
40  class Error : public tlv::Error
41  {
42  public:
43  explicit
44  Error(const std::string& what)
45  : tlv::Error(what)
46  {
47  }
48  };
49 
60  Data();
61 
74  Data(const Name& name);
75 
86  explicit
87  Data(const Block& wire);
88 
98  template<encoding::Tag TAG>
99  size_t
100  wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const;
101 
105  const Block&
106  wireEncode() const;
107 
127  const Block&
128  wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const;
129 
133  void
134  wireDecode(const Block& wire);
135 
139  bool
140  hasWire() const;
141 
143 
147  const Name&
148  getName() const;
149 
155  Data&
156  setName(const Name& name);
157 
158  //
159 
166  const Name&
167  getFullName() const;
168 
172  const MetaInfo&
173  getMetaInfo() const;
174 
180  Data&
181  setMetaInfo(const MetaInfo& metaInfo);
182 
183  //
184 
188  // MetaInfo proxy methods
189 
190  uint32_t
191  getContentType() const;
192 
193  Data&
194  setContentType(uint32_t type);
195 
196  //
197 
198  const time::milliseconds&
199  getFreshnessPeriod() const;
200 
201  Data&
202  setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
203 
204  //
205 
206  const name::Component&
207  getFinalBlockId() const;
208 
209  Data&
210  setFinalBlockId(const name::Component& finalBlockId);
211 
212  //
216 
223  const Block&
224  getContent() const;
225 
234  Data&
235  setContent(const uint8_t* buffer, size_t bufferSize);
236 
252  Data&
253  setContent(const Block& block);
254 
266  Data&
267  setContent(const ConstBufferPtr& contentValue);
268 
269  //
270 
271  const Signature&
272  getSignature() const;
273 
278  Data&
279  setSignature(const Signature& signature);
280 
281  Data&
282  setSignatureValue(const Block& value);
283 
284 public: // EqualityComparable concept
285  bool
286  operator==(const Data& other) const;
287 
288  bool
289  operator!=(const Data& other) const;
290 
291 protected:
295  void
296  onChanged();
297 
298 private:
299  Name m_name;
300  MetaInfo m_metaInfo;
301  mutable Block m_content;
302  Signature m_signature;
303 
304  mutable Block m_wire;
305  mutable Name m_fullName;
306 };
307 
308 std::ostream&
309 operator<<(std::ostream& os, const Data& data);
310 
311 inline bool
313 {
314  return m_wire.hasWire();
315 }
316 
317 inline const Name&
319 {
320  return m_name;
321 }
322 
323 inline const MetaInfo&
325 {
326  return m_metaInfo;
327 }
328 
329 inline uint32_t
331 {
332  return m_metaInfo.getType();
333 }
334 
335 inline const time::milliseconds&
337 {
338  return m_metaInfo.getFreshnessPeriod();
339 }
340 
341 inline const name::Component&
343 {
344  return m_metaInfo.getFinalBlockId();
345 }
346 
347 inline const Signature&
349 {
350  return m_signature;
351 }
352 
353 } // namespace ndn
354 
355 #endif
Error(const std::string &what)
Definition: data.hpp:44
const Block & wireEncode() const
Encode to a wire format.
Definition: data.cpp:119
Data & setContentType(uint32_t type)
Definition: data.cpp:203
Copyright (c) 2011-2015 Regents of the University of California.
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: data.cpp:135
const Block & getContent() const
Get content Block.
Definition: data.cpp:230
Data()
Create an empty Data object.
Definition: data.cpp:35
Data & setSignature(const Signature &signature)
Set the signature to a copy of the given signature.
Definition: data.cpp:275
Base class to store tag information (e.g., inside Interest and Data packets)
Definition: tag-host.hpp:34
Data & setName(const Name &name)
Set name to a copy of the given Name.
Definition: data.cpp:170
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:318
const name::Component & getFinalBlockId() const
Definition: data.hpp:342
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:320
Data & setContent(const uint8_t *buffer, size_t bufferSize)
Set the content from the buffer (buffer will be copied)
Definition: data.cpp:241
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
bool operator!=(const Data &other) const
Definition: data.cpp:314
bool operator==(const Data &other) const
Definition: data.cpp:305
Data & setFreshnessPeriod(const time::milliseconds &freshnessPeriod)
Definition: data.cpp:212
void onChanged()
Clear the wire encoding.
Definition: data.cpp:293
Data & setSignatureValue(const Block &value)
Definition: data.cpp:284
EncodingImpl< EncoderTag > EncodingBuffer
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:56
bool hasWire() const
Check if Data is already has wire encoding.
Definition: data.hpp:312
const MetaInfo & getMetaInfo() const
Get MetaInfo block from Data packet.
Definition: data.hpp:324
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const Name & getFullName() const
Get full name of Data packet, including the implicit digest.
Definition: data.cpp:179
const time::milliseconds & getFreshnessPeriod() const
Definition: data.hpp:336
Component holds a read-only name component value.
Data & setMetaInfo(const MetaInfo &metaInfo)
Set metaInfo to a copy of the given MetaInfo.
Definition: data.cpp:194
const Signature & getSignature() const
Definition: data.hpp:348
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
Data & setFinalBlockId(const name::Component &finalBlockId)
Definition: data.cpp:221
represents a Data packet
Definition: data.hpp:37
uint32_t getContentType() const
Definition: data.hpp:330
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:33