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::upCast(signature); }
57 
59  getSignature() { return SignatureLite::upCast(signature); }
60 
61  const NameLite&
62  getName() const { return NameLite::upCast(name); }
63 
64  NameLite&
65  getName() { return NameLite::upCast(name); }
66 
67  const MetaInfoLite&
68  getMetaInfo() const { return MetaInfoLite::upCast(metaInfo); }
69 
71  getMetaInfo() { return MetaInfoLite::upCast(metaInfo); }
72 
73  const BlobLite&
74  getContent() const { return BlobLite::upCast(content); }
75 
82  ndn_Error
83  setName(const NameLite& name)
84  {
85  return NameLite::upCast(this->name).set(name);
86  }
87 
94  DataLite&
96  {
97  BlobLite::upCast(this->content) = content;
98  return *this;
99  }
100 
107  ndn_Error
108  set(const DataLite& other);
109 
115  static DataLite&
116  upCast(ndn_Data& data) { return *(DataLite*)&data; }
117 
118  static const DataLite&
119  upCast(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(DataLite& other);
131  DataLite(const DataLite& other);
132 
138  DataLite& operator=(const DataLite& other);
139 };
140 
141 }
142 
143 #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-2015 Regents of the University of California.
Definition: common.hpp:35
static SignatureLite & upCast(ndn_Signature &signature)
Upcast the reference to the ndn_Signature struct to a SignatureLite.
Definition: signature-lite.hpp:124
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
static DataLite & upCast(ndn_Data &data)
Upcast the reference to the ndn_Data struct to a DataLite.
Definition: data-lite.hpp:116
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:86
struct ndn_Blob content
A Blob with a pointer to the content.
Definition: data-types.h:90
static BlobLite & upCast(ndn_Blob &blob)
Upcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:69
ndn_Error set(const NameLite &other)
Set this name to have the values from the other name.
Definition: name-lite.cpp:181
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 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 NameLite & upCast(ndn_Name &name)
Upcast the reference to the ndn_Name struct to a NameLite.
Definition: name-lite.hpp:377
static MetaInfoLite & upCast(ndn_MetaInfo &metaInfo)
Upcast the reference to the ndn_MetaInfo struct to a MetaInfoLite.
Definition: meta-info-lite.hpp:77
A DataLite holds a NameLite and other fields to represent an NDN Data packet.
Definition: data-lite.hpp:34