Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 2 | /** |
Junxiao Shi | a1478db | 2016-09-09 04:13:15 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 22 | #ifndef NDN_DATA_HPP |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 23 | #define NDN_DATA_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 24 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 25 | #include "name.hpp" |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 26 | #include "encoding/block.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 28 | #include "signature.hpp" |
| 29 | #include "meta-info.hpp" |
| 30 | #include "key-locator.hpp" |
Alexander Afanasyev | a3887ae | 2014-12-29 16:11:57 -0800 | [diff] [blame] | 31 | #include "tag-host.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 35 | /** @brief represents a Data packet |
| 36 | */ |
Alexander Afanasyev | a3887ae | 2014-12-29 16:11:57 -0800 | [diff] [blame] | 37 | class Data : public TagHost, public enable_shared_from_this<Data> |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 38 | { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 39 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 40 | class Error : public tlv::Error |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 45 | : tlv::Error(what) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 46 | { |
| 47 | } |
| 48 | }; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 50 | /** |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 51 | * @brief Create an empty Data object |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 52 | * |
| 53 | * Note that in certain contexts that use Data::shared_from_this(), Data must be |
| 54 | * created using `make_shared`: |
| 55 | * |
| 56 | * shared_ptr<Data> data = make_shared<Data>(); |
| 57 | * |
| 58 | * Otherwise, Data::shared_from_this() will throw an exception. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 59 | */ |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 60 | Data(); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 61 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 62 | /** |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 63 | * @brief Create a new Data object with the given name |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 64 | * |
| 65 | * @param name A reference to the name |
| 66 | * |
| 67 | * Note that in certain contexts that use Data::shared_from_this(), Data must be |
| 68 | * created using `make_shared`: |
| 69 | * |
| 70 | * shared_ptr<Data> data = make_shared<Data>(name); |
| 71 | * |
| 72 | * Otherwise, Data::shared_from_this() will throw an exception. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 73 | */ |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 74 | Data(const Name& name); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * @brief Create a new Data object from wire encoding |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 78 | * |
| 79 | * Note that in certain contexts that use Data::shared_from_this(), Data must be |
| 80 | * created using `make_shared`: |
| 81 | * |
| 82 | * shared_ptr<Data> data = make_shared<Data>(wire); |
| 83 | * |
| 84 | * Otherwise, Data::shared_from_this() will throw an exception. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 85 | */ |
| 86 | explicit |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 87 | Data(const Block& wire); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 88 | |
Jeff Thompson | 25bfdca | 2013-10-16 17:05:41 -0700 | [diff] [blame] | 89 | /** |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 90 | * @brief Fast encoding or block size estimation |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 91 | * |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 92 | * @param encoder EncodingEstimator or EncodingBuffer instance |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 93 | * @param wantUnsignedPortionOnly Request only unsigned portion to be encoded in block. |
| 94 | * If true, only Name, MetaInfo, Content, and SignatureInfo |
| 95 | * blocks will be encoded into the block. Note that there |
| 96 | * will be no outer TLV header of the Data packet. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 97 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 98 | template<encoding::Tag TAG> |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 99 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 100 | wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 102 | /** |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 103 | * @brief Encode to a wire format |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 104 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 105 | const Block& |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 106 | wireEncode() const; |
| 107 | |
| 108 | /** |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 109 | * @brief Finalize Data packet encoding with the specified SignatureValue |
| 110 | * |
| 111 | * @param encoder EncodingBuffer instance, containing Name, MetaInfo, Content, and |
| 112 | * SignatureInfo (without outer TLV header of the Data packet). |
| 113 | * @param signatureValue SignatureValue block to be added to Data packet to finalize |
| 114 | * the wire encoding |
| 115 | * |
| 116 | * This method is intended to be used in concert with Data::wireEncode(EncodingBuffer&, true) |
| 117 | * method to optimize Data packet wire format creation: |
| 118 | * |
| 119 | * Data data; |
| 120 | * ... |
| 121 | * EncodingBuffer encoder; |
| 122 | * data.wireEncode(encoder, true); |
| 123 | * ... |
| 124 | * Block signatureValue = <sign_over_unsigned_portion>(encoder.buf(), encoder.size()); |
| 125 | * data.wireEncode(encoder, signatureValue) |
| 126 | */ |
| 127 | const Block& |
| 128 | wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const; |
| 129 | |
| 130 | /** |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 131 | * @brief Decode from the wire format |
| 132 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 133 | void |
| 134 | wireDecode(const Block& wire); |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 136 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 137 | * @brief Check if Data is already has wire encoding |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 138 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 139 | bool |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 140 | hasWire() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 141 | |
| 142 | //////////////////////////////////////////////////////////////////// |
| 143 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 144 | /** |
| 145 | * @brief Get name of the Data packet |
| 146 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 147 | const Name& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 148 | getName() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 149 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 150 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 151 | * @brief Set name to a copy of the given Name |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 152 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 153 | * @return This Data so that you can chain calls to update values |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 154 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 155 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 156 | setName(const Name& name); |
| 157 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 158 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 159 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 160 | /** |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 161 | * @brief Get full name of Data packet, including the implicit digest |
| 162 | * |
| 163 | * @throws Error if Data packet doesn't have a full name yet (wire encoding has not been |
| 164 | * yet created) |
| 165 | */ |
| 166 | const Name& |
| 167 | getFullName() const; |
| 168 | |
| 169 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 170 | * @brief Get MetaInfo block from Data packet |
| 171 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 172 | const MetaInfo& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 173 | getMetaInfo() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 174 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 175 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 176 | * @brief Set metaInfo to a copy of the given MetaInfo |
| 177 | * |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 178 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 179 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 180 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 181 | setMetaInfo(const MetaInfo& metaInfo); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 182 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 183 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 184 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 185 | /////////////////////////////////////////////////////////////// |
| 186 | /////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 187 | /////////////////////////////////////////////////////////////// |
| 188 | // MetaInfo proxy methods |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 189 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 190 | uint32_t |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 191 | getContentType() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 193 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 194 | setContentType(uint32_t type); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 195 | |
| 196 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 197 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 198 | const time::milliseconds& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 199 | getFreshnessPeriod() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 200 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 201 | Data& |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 202 | setFreshnessPeriod(const time::milliseconds& freshnessPeriod); |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 203 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 204 | // |
| 205 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 206 | const name::Component& |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 207 | getFinalBlockId() const; |
| 208 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 209 | Data& |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 210 | setFinalBlockId(const name::Component& finalBlockId); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 211 | |
| 212 | // |
| 213 | /////////////////////////////////////////////////////////////// |
| 214 | /////////////////////////////////////////////////////////////// |
| 215 | /////////////////////////////////////////////////////////////// |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 216 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 217 | /** |
| 218 | * @brief Get content Block |
| 219 | * |
| 220 | * To access content value, one can use value()/value_size() or |
| 221 | * value_begin()/value_end() methods of the Block class |
| 222 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 223 | const Block& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 224 | getContent() const; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 225 | |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 226 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 227 | * @brief Set the content from the buffer (buffer will be copied) |
| 228 | * |
| 229 | * @param buffer Pointer to first byte of the buffer |
| 230 | * @param bufferSize Size of the buffer |
| 231 | * |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 232 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 233 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 234 | Data& |
| 235 | setContent(const uint8_t* buffer, size_t bufferSize); |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 236 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 237 | /** |
| 238 | * @brief Set the content from the block |
| 239 | * |
| 240 | * Depending on type of the supplied block, there are two cases: |
| 241 | * |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 242 | * - if block.type() == tlv::Content, then block will be used directly as Data packet's |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 243 | * content (no extra copying) |
| 244 | * |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 245 | * - if block.type() != tlv::Content, then this method will create a new Block with type |
| 246 | * tlv::Content and put block as a nested element in the content Block. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 247 | * |
| 248 | * @param block The Block containing the content to assign |
| 249 | * |
| 250 | * @return This Data so that you can chain calls to update values. |
| 251 | */ |
| 252 | Data& |
| 253 | setContent(const Block& block); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 254 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 255 | /** |
| 256 | * @brief Set the content from the pointer to immutable buffer |
| 257 | * |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 258 | * This method will create a Block with tlv::Content and set contentValue as a payload |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 259 | * for this block. Note that this method is very different from setContent(const |
| 260 | * Block&), since it does not require that payload should be a valid TLV element. |
| 261 | * |
| 262 | * @param contentValue The pointer to immutable buffer containing the content to assign |
| 263 | * |
| 264 | * @return This Data so that you can chain calls to update values. |
| 265 | */ |
| 266 | Data& |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 267 | setContent(const ConstBufferPtr& contentValue); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 268 | |
| 269 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 270 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 271 | const Signature& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 272 | getSignature() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 273 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 274 | /** |
| 275 | * @brief Set the signature to a copy of the given signature. |
| 276 | * @param signature The signature object which is cloned. |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 277 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 278 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 279 | setSignature(const Signature& signature); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 280 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 281 | Data& |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 282 | setSignatureValue(const Block& value); |
Yingdi Yu | a4e5767 | 2014-02-06 11:16:17 -0800 | [diff] [blame] | 283 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 284 | public: // EqualityComparable concept |
| 285 | bool |
| 286 | operator==(const Data& other) const; |
| 287 | |
| 288 | bool |
| 289 | operator!=(const Data& other) const; |
| 290 | |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 291 | protected: |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 292 | /** |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 293 | * @brief Clear the wire encoding. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 294 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 295 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 296 | onChanged(); |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 297 | |
| 298 | private: |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 299 | Name m_name; |
| 300 | MetaInfo m_metaInfo; |
| 301 | mutable Block m_content; |
| 302 | Signature m_signature; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 303 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 304 | mutable Block m_wire; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 305 | mutable Name m_fullName; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 306 | }; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 307 | |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 308 | std::ostream& |
| 309 | operator<<(std::ostream& os, const Data& data); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 310 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 311 | inline bool |
| 312 | Data::hasWire() const |
| 313 | { |
| 314 | return m_wire.hasWire(); |
| 315 | } |
| 316 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 317 | inline const Name& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 318 | Data::getName() const |
| 319 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 320 | return m_name; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 321 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 322 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 323 | inline const MetaInfo& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 324 | Data::getMetaInfo() const |
| 325 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 326 | return m_metaInfo; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 327 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 328 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 329 | inline uint32_t |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 330 | Data::getContentType() const |
| 331 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 332 | return m_metaInfo.getType(); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 333 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 334 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 335 | inline const time::milliseconds& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 336 | Data::getFreshnessPeriod() const |
| 337 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 338 | return m_metaInfo.getFreshnessPeriod(); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 339 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 340 | |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 341 | inline const name::Component& |
| 342 | Data::getFinalBlockId() const |
| 343 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 344 | return m_metaInfo.getFinalBlockId(); |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 347 | inline const Signature& |
| 348 | Data::getSignature() const |
| 349 | { |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 350 | return m_signature; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 351 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 352 | |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 353 | } // namespace ndn |
| 354 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 355 | #endif |