meta-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 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_CXX_META_INFO_HPP
23 #define NDN_CXX_META_INFO_HPP
24 
29 #include "ndn-cxx/util/time.hpp"
30 
31 #include <list>
32 
33 namespace ndn {
34 
39 
61 class MetaInfo
62 {
63 public:
64  class Error : public tlv::Error
65  {
66  public:
67  using tlv::Error::Error;
68  };
69 
70  MetaInfo();
71 
75  explicit
76  MetaInfo(const Block& block);
77 
78  template<encoding::Tag TAG>
79  size_t
80  wireEncode(EncodingImpl<TAG>& encoder) const;
81 
82  const Block&
83  wireEncode() const;
84 
85  void
86  wireDecode(const Block& wire);
87 
88 public: // getter/setter
93  uint32_t
94  getType() const
95  {
96  return m_type;
97  }
98 
102  MetaInfo&
103  setType(uint32_t type);
104 
111  {
112  return m_freshnessPeriod;
113  }
114 
118  MetaInfo&
119  setFreshnessPeriod(time::milliseconds freshnessPeriod);
120 
123  const optional<name::Component>&
125  {
126  return m_finalBlockId;
127  }
128 
131  MetaInfo&
132  setFinalBlock(optional<name::Component> finalBlockId);
133 
134 public: // app-defined MetaInfo items
141  const std::list<Block>&
142  getAppMetaInfo() const;
143 
155  MetaInfo&
156  setAppMetaInfo(const std::list<Block>& info);
157 
167  MetaInfo&
168  addAppMetaInfo(const Block& block);
169 
178  bool
179  removeAppMetaInfo(uint32_t tlvType);
180 
192  const Block*
193  findAppMetaInfo(uint32_t tlvType) const;
194 
195 private:
196  uint32_t m_type;
197  time::milliseconds m_freshnessPeriod;
198  optional<name::Component> m_finalBlockId;
199  std::list<Block> m_appMetaInfo;
200 
201  mutable Block m_wire;
202 };
203 
205 
206 std::ostream&
207 operator<<(std::ostream& os, const MetaInfo& info);
208 
209 } // namespace ndn
210 
211 #endif // NDN_CXX_META_INFO_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
A MetaInfo holds the meta info which is signed inside the Data packet.
Definition: meta-info.hpp:62
void wireDecode(const Block &wire)
Definition: meta-info.cpp:181
const optional< name::Component > & getFinalBlock() const
Return the value of FinalBlockId.
Definition: meta-info.hpp:124
time::milliseconds getFreshnessPeriod() const
Return the value of FreshnessPeriod.
Definition: meta-info.hpp:110
MetaInfo & addAppMetaInfo(const Block &block)
Add an app-defined MetaInfo item.
Definition: meta-info.cpp:93
MetaInfo & setAppMetaInfo(const std::list< Block > &info)
Set app-defined MetaInfo items.
Definition: meta-info.cpp:80
MetaInfo & setType(uint32_t type)
Set ContentType.
Definition: meta-info.cpp:47
MetaInfo & setFinalBlock(optional< name::Component > finalBlockId)
Set FinalBlockId.
Definition: meta-info.cpp:66
const Block & wireEncode() const
Definition: meta-info.cpp:165
const Block * findAppMetaInfo(uint32_t tlvType) const
Find a first app-defined MetaInfo item of type tlvType.
Definition: meta-info.cpp:117
MetaInfo & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Set FreshnessPeriod.
Definition: meta-info.cpp:55
uint32_t getType() const
Return the value of ContentType.
Definition: meta-info.hpp:94
const std::list< Block > & getAppMetaInfo() const
Get all app-defined MetaInfo items.
Definition: meta-info.cpp:74
bool removeAppMetaInfo(uint32_t tlvType)
Remove a first app-defined MetaInfo item with type tlvType.
Definition: meta-info.cpp:104
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48
@ MetaInfo
Definition: tlv.hpp:92
Definition: data.cpp:25
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:374
const time::milliseconds DEFAULT_FRESHNESS_PERIOD
Default value of FreshnessPeriod.
Definition: meta-info.hpp:38
uint64_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
Definition: packet.cpp:62
SignatureInfo info