data-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_DATA_LITE_HPP
23 #define NDN_DATA_LITE_HPP
24 
25 #include "meta-info-lite.hpp"
26 #include "signature-lite.hpp"
27 #include "../c/data-types.h"
28 
29 namespace ndn {
30 
34 class DataLite : private ndn_Data {
35 public:
52  DataLite(ndn_NameComponent* nameComponents, size_t maxNameComponents,
53  ndn_NameComponent* keyNameComponents, size_t maxKeyNameComponents);
54 
55  const SignatureLite&
56  getSignature() const { return SignatureLite::downCast(signature); }
57 
59  getSignature() { return SignatureLite::downCast(signature); }
60 
61  const NameLite&
62  getName() const { return NameLite::downCast(name); }
63 
64  NameLite&
65  getName() { return NameLite::downCast(name); }
66 
67  const MetaInfoLite&
68  getMetaInfo() const { return MetaInfoLite::downCast(metaInfo); }
69 
71  getMetaInfo() { return MetaInfoLite::downCast(metaInfo); }
72 
73  const BlobLite&
74  getContent() const { return BlobLite::downCast(content); }
75 
82  ndn_Error
83  setName(const NameLite& name)
84  {
85  return NameLite::downCast(this->name).set(name);
86  }
87 
94  DataLite&
96  {
97  BlobLite::downCast(this->content) = content;
98  return *this;
99  }
100 
107  ndn_Error
108  set(const DataLite& other);
109 
115  static DataLite&
116  downCast(ndn_Data& data) { return *(DataLite*)&data; }
117 
118  static const DataLite&
119  downCast(const ndn_Data& data) { return *(DataLite*)&data; }
120 
121 private:
122  // Declare friends who can downcast to the private base.
123  friend class Tlv0_1_1WireFormatLite;
124 
130  DataLite(const DataLite& other);
131 
137  DataLite& operator=(const DataLite& other);
138 };
139 
140 }
141 
142 #endif
ndn_Error set(const DataLite &other)
Set this data packet object to have the values from the other data.
Definition: data-lite.cpp:37
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
ndn_Error setName(const NameLite &name)
Set this data packet's name to have the values from the given name.
Definition: data-lite.hpp:83
A NameLite holds an array of NameLite::Component.
Definition: name-lite.hpp:34
A MetaInfoLite holds a type and other info to represent the meta info of a Data packet.
Definition: meta-info-lite.hpp:35
A SignatureLite holds a signature type, a KeyLocatorLite, the signature bytes and other fields to rep...
Definition: signature-lite.hpp:36
Definition: data-types.h:78
struct ndn_Blob content
A Blob with a pointer to the content.
Definition: data-types.h:82
static DataLite & downCast(ndn_Data &data)
Downcast the reference to the ndn_Data struct to a DataLite.
Definition: data-lite.hpp:116
static BlobLite & downCast(ndn_Blob &blob)
Downcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:76
ndn_Error set(const NameLite &other)
Set this name to have the values from the other name.
Definition: name-lite.cpp:216
DataLite(ndn_NameComponent *nameComponents, size_t maxNameComponents, ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents)
Create a DataLite with the pre-allocated nameComponents and keyNameComponents, and defaults for all t...
Definition: data-lite.cpp:28
Copyright (C) 2015-2016 Regents of the University of California.
Definition: name-types.h:33
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
DataLite & setContent(const BlobLite &content)
Set this data packet's content.
Definition: data-lite.hpp:95
static SignatureLite & downCast(ndn_Signature &signature)
Downcast the reference to the ndn_Signature struct to a SignatureLite.
Definition: signature-lite.hpp:132
static MetaInfoLite & downCast(ndn_MetaInfo &metaInfo)
Downcast the reference to the ndn_MetaInfo struct to a MetaInfoLite.
Definition: meta-info-lite.hpp:77
static NameLite & downCast(ndn_Name &name)
Downcast the reference to the ndn_Name struct to a NameLite.
Definition: name-lite.hpp:429
A DataLite holds a NameLite and other fields to represent an NDN Data packet.
Definition: data-lite.hpp:34