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-2024 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 
28 #include "ndn-cxx/util/time.hpp"
29 
30 #include <list>
31 #include <optional>
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 
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
94  uint32_t
95  getType() const noexcept
96  {
97  return m_type;
98  }
99 
104  MetaInfo&
105  setType(uint32_t type);
106 
115  getFreshnessPeriod() const noexcept;
116 
121  MetaInfo&
122  setFreshnessPeriod(time::milliseconds freshnessPeriod);
123 
127  const std::optional<name::Component>&
128  getFinalBlock() const noexcept
129  {
130  return m_finalBlockId;
131  }
132 
136  MetaInfo&
137  setFinalBlock(std::optional<name::Component> finalBlockId);
138 
139 public: // app-defined MetaInfo items
146  const std::list<Block>&
147  getAppMetaInfo() const;
148 
160  MetaInfo&
161  setAppMetaInfo(const std::list<Block>& info);
162 
172  MetaInfo&
173  addAppMetaInfo(const Block& block);
174 
183  bool
184  removeAppMetaInfo(uint32_t tlvType);
185 
197  const Block*
198  findAppMetaInfo(uint32_t tlvType) const;
199 
200 private:
201  uint32_t m_type = tlv::ContentType_Blob;
202  uint64_t m_freshnessPeriod = DEFAULT_FRESHNESS_PERIOD.count();
203  std::optional<name::Component> m_finalBlockId;
204  std::list<Block> m_appMetaInfo;
205 
206  mutable Block m_wire;
207 };
208 
210 
211 std::ostream&
212 operator<<(std::ostream& os, const MetaInfo& info);
213 
214 } // namespace ndn
215 
216 #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
uint32_t getType() const noexcept
Return the value of ContentType.
Definition: meta-info.hpp:95
void wireDecode(const Block &wire)
Definition: meta-info.cpp:180
MetaInfo & setFinalBlock(std::optional< name::Component > finalBlockId)
Set the FinalBlockId.
Definition: meta-info.cpp:66
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 the ContentType.
Definition: meta-info.cpp:38
const std::optional< name::Component > & getFinalBlock() const noexcept
Return the value of FinalBlockId.
Definition: meta-info.hpp:128
const Block & wireEncode() const
Definition: meta-info.cpp:164
const Block * findAppMetaInfo(uint32_t tlvType) const
Find a first app-defined MetaInfo item of type tlvType.
Definition: meta-info.cpp:117
time::milliseconds getFreshnessPeriod() const noexcept
Return the value of FreshnessPeriod.
Definition: meta-info.cpp:46
MetaInfo & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Set the FreshnessPeriod.
Definition: meta-info.cpp:55
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:28
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
::boost::chrono::milliseconds milliseconds
Definition: time.hpp:52
@ MetaInfo
Definition: tlv.hpp:92
@ ContentType_Blob
payload
Definition: tlv.hpp:145
Definition: data.cpp:25
constexpr time::milliseconds DEFAULT_FRESHNESS_PERIOD
Default value of FreshnessPeriod.
Definition: meta-info.hpp:38
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:377
uint32_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
Definition: packet.cpp:49
SignatureInfo info