blob: 177d1f2e0439876cb6c342a8c9789c44a2601c62 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shidb7464d2017-07-13 03:11:17 +00002/*
3 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -08004 *
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07005 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -08006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080022 */
23
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070024#ifndef NDN_ENCODING_BLOCK_HPP
25#define NDN_ENCODING_BLOCK_HPP
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080026
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080027#include "buffer.hpp"
Alexander Afanasyev74633892015-02-08 18:08:46 -080028#include "encoding-buffer-fwd.hpp"
Davide Pesavento88a0d812017-08-19 21:31:42 -040029#include "tlv.hpp"
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080030
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -070031namespace boost {
32namespace asio {
33class const_buffer;
34} // namespace asio
35} // namespace boost
36
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080037namespace ndn {
38
Junxiao Shi760cc7b2017-07-22 19:17:49 +000039/** @brief Represents a TLV element of NDN packet format
40 * @sa https://named-data.net/doc/ndn-tlv/tlv.html
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080041 */
42class Block
43{
44public:
Junxiao Shidb7464d2017-07-13 03:11:17 +000045 using element_container = std::vector<Block>;
46 using element_iterator = element_container::iterator;
47 using element_const_iterator = element_container::const_iterator;
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080048
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060049 class Error : public tlv::Error
Alexander Afanasyev937aa782014-03-21 13:17:57 -070050 {
Alexander Afanasyeva465e972014-03-22 17:21:49 -070051 public:
52 explicit
53 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060054 : tlv::Error(what)
Alexander Afanasyeva465e972014-03-22 17:21:49 -070055 {
56 }
Alexander Afanasyev937aa782014-03-21 13:17:57 -070057 };
58
Junxiao Shi81a6c5d2014-11-30 00:14:42 -070059public: // constructor, creation, assignment
60 /** @brief Create an empty Block
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080061 */
62 Block();
63
Junxiao Shidb7464d2017-07-13 03:11:17 +000064 /** @brief Parse Block from an EncodingBuffer
65 * @param buffer an EncodingBuffer containing one TLV element
66 * @throw tlv::Error Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE
Alexander Afanasyev15151312014-02-16 00:53:51 -080067 */
68 explicit
69 Block(const EncodingBuffer& buffer);
Alexander Afanasyev937aa782014-03-21 13:17:57 -070070
Junxiao Shidb7464d2017-07-13 03:11:17 +000071 /** @brief Parse Block from a wire Buffer
72 * @param buffer a Buffer containing one TLV element
73 * @note This constructor takes shared ownership of @p buffer.
74 * @throw tlv::Error Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080075 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070076 explicit
Alexander Afanasyev937aa782014-03-21 13:17:57 -070077 Block(const ConstBufferPtr& buffer);
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -080078
Junxiao Shidb7464d2017-07-13 03:11:17 +000079 /** @brief Parse Block within boundaries of a wire Buffer
80 * @param buffer a Buffer containing an TLV element at [@p begin,@p end)
81 * @param begin begin position of the TLV element within @p buffer
82 * @param end end position of the TLV element within @p buffer
83 * @param verifyLength if true, check TLV-LENGTH equals size of TLV-VALUE
84 * @throw std::invalid_argument @p buffer is empty, or [@p begin,@p end) range are not within @p buffer
85 * @throw tlv::Error Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE
86 * @note This overload automatically detects TLV-TYPE and position of TLV-VALUE.
Alexander Afanasyev187bc482014-02-06 15:04:04 -080087 */
Junxiao Shidb7464d2017-07-13 03:11:17 +000088 Block(ConstBufferPtr buffer, Buffer::const_iterator begin, Buffer::const_iterator end,
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080089 bool verifyLength = true);
Alexander Afanasyev937aa782014-03-21 13:17:57 -070090
Junxiao Shidb7464d2017-07-13 03:11:17 +000091 /** @brief Parse Block within boundaries of an existing Block, reusing underlying wire Buffer
92 * @param block a Block whose buffer contains an TLV element at [@p begin,@p end)
93 * @param begin begin position of the TLV element within @p block
94 * @param end end position of the TLV element within @p block
95 * @param verifyLength if true, check TLV-LENGTH equals size of TLV-VALUE
96 * @throw std::invalid_argument [@p begin,@p end) range are not within @p block
97 * @throw tlv::Error Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE
Alexander Afanasyev4448d292015-08-09 20:11:37 -070098 */
Junxiao Shidb7464d2017-07-13 03:11:17 +000099 Block(const Block& block, Buffer::const_iterator begin, Buffer::const_iterator end,
Alexander Afanasyev4448d292015-08-09 20:11:37 -0700100 bool verifyLength = true);
101
Junxiao Shidb7464d2017-07-13 03:11:17 +0000102 /** @brief Create a Block from a wire Buffer without parsing
103 * @param buffer a Buffer containing an TLV element at [@p begin,@p end)
104 * @param type TLV-TYPE
105 * @param begin begin position of the TLV element within @p buffer
106 * @param end end position of the TLV element within @p buffer
107 * @param valueBegin begin position of TLV-VALUE within @p buffer
108 * @param valueEnd end position of TLV-VALUE within @p buffer
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800109 */
Junxiao Shidb7464d2017-07-13 03:11:17 +0000110 Block(ConstBufferPtr buffer, uint32_t type,
111 Buffer::const_iterator begin, Buffer::const_iterator end,
112 Buffer::const_iterator valueBegin, Buffer::const_iterator valueEnd);
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800113
Junxiao Shidb7464d2017-07-13 03:11:17 +0000114 /** @brief Parse Block from a raw buffer
115 * @param buf pointer to the first octet of an TLV element
116 * @param bufSize size of the raw buffer; may be more than size of the TLV element
117 * @throw tlv::Error Type-Length parsing fails, or size of TLV-VALUE exceeds @p bufSize
118 * @note This overload copies the TLV element into an internal wire buffer.
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700119 */
Junxiao Shidb7464d2017-07-13 03:11:17 +0000120 Block(const uint8_t* buf, size_t bufSize);
Yingdi Yu27158392014-01-20 13:04:20 -0800121
Junxiao Shidb7464d2017-07-13 03:11:17 +0000122 /** @brief Parse Block from a raw buffer
123 * @deprecated use Block(const uint8_t*, size_t)
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800124 */
Junxiao Shidb7464d2017-07-13 03:11:17 +0000125 Block(const void* buf, size_t bufSize);
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800126
Junxiao Shidb7464d2017-07-13 03:11:17 +0000127 /** @brief Create an empty Block with specified TLV-TYPE
128 * @param type TLV-TYPE
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800129 */
Alexander Afanasyevf42ce132014-01-07 13:32:30 -0800130 explicit
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800131 Block(uint32_t type);
132
Junxiao Shidb7464d2017-07-13 03:11:17 +0000133 /** @brief Create a Block with specified TLV-TYPE and TLV-VALUE
134 * @param type TLV-TYPE
135 * @param value a Buffer containing the TLV-VALUE
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800136 */
Junxiao Shidb7464d2017-07-13 03:11:17 +0000137 Block(uint32_t type, ConstBufferPtr value);
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800138
Junxiao Shidb7464d2017-07-13 03:11:17 +0000139 /** @brief Create a Block with specified TLV-TYPE and TLV-VALUE
140 * @param type TLV-TYPE
141 * @param value a Block to be nested as TLV-VALUE
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800142 */
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700143 Block(uint32_t type, const Block& value);
144
Junxiao Shidb7464d2017-07-13 03:11:17 +0000145 /** @brief Parse Block from an input stream
Junxiao Shi760cc7b2017-07-22 19:17:49 +0000146 * @throw tlv::Error TLV-LENGTH is zero or exceeds upper bound
147 * @warning If decoding fails, bytes are still consumed from the input stream.
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700148 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700149 static Block
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700150 fromStream(std::istream& is);
151
Junxiao Shidb7464d2017-07-13 03:11:17 +0000152 /** @brief Try to parse Block from a wire buffer
153 * @param buffer a Buffer containing an TLV element at offset @p offset
154 * @param offset begin position of the TLV element within @p buffer
155 * @note This function does not throw exceptions upon decoding failure.
156 * @return true and the Block if parsing succeeds; otherwise false
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700157 */
Junxiao Shi02a4bf32015-02-21 21:07:46 -0700158 static std::tuple<bool, Block>
159 fromBuffer(ConstBufferPtr buffer, size_t offset);
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700160
Junxiao Shidb7464d2017-07-13 03:11:17 +0000161 /** @brief Try to parse Block from a raw buffer
162 * @param buf pointer to the first octet of an TLV element
163 * @param bufSize size of the raw buffer; may be more than size of the TLV element
164 * @note This function does not throw exceptions upon decoding failure.
165 * @note This overload copies the TLV element into an internal wire buffer.
166 * @return true and the Block if parsing succeeds; otherwise false
Junxiao Shi02a4bf32015-02-21 21:07:46 -0700167 */
168 static std::tuple<bool, Block>
Junxiao Shidb7464d2017-07-13 03:11:17 +0000169 fromBuffer(const uint8_t* buf, size_t bufSize);
Junxiao Shi02a4bf32015-02-21 21:07:46 -0700170
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700171public: // wire format
172 /** @brief Check if the Block is empty
Junxiao Shidb7464d2017-07-13 03:11:17 +0000173 *
174 * A Block is "empty" only if it is default-constructed. A Block with zero-length TLV-VALUE is
175 * not considered empty.
Alexander Afanasyev196b9aa2014-01-31 17:19:16 -0800176 */
Alexander Afanasyeva465e972014-03-22 17:21:49 -0700177 bool
Junxiao Shidb7464d2017-07-13 03:11:17 +0000178 empty() const
179 {
180 return m_type == std::numeric_limits<uint32_t>::max();
181 }
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700182
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700183 /** @brief Check if the Block has fully encoded wire
Junxiao Shidb7464d2017-07-13 03:11:17 +0000184 *
185 * A Block has fully encoded wire if the underlying buffer exists and contains full
186 * Type-Length-Value instead of just TLV-VALUE field.
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800187 */
Alexander Afanasyeva465e972014-03-22 17:21:49 -0700188 bool
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800189 hasWire() const;
190
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700191 /** @brief Reset wire buffer of the element
Junxiao Shidb7464d2017-07-13 03:11:17 +0000192 * @post empty() == true
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800193 */
Alexander Afanasyeva465e972014-03-22 17:21:49 -0700194 void
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800195 reset();
196
Junxiao Shidb7464d2017-07-13 03:11:17 +0000197 /** @brief Reset wire buffer but keep TLV-TYPE and sub elements (if any)
198 * @post hasWire() == false
199 * @post hasValue() == false
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -0800200 */
Alexander Afanasyeva465e972014-03-22 17:21:49 -0700201 void
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -0800202 resetWire();
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800203
Junxiao Shidb7464d2017-07-13 03:11:17 +0000204 /** @brief Get begin iterator of encoded wire
205 * @pre hasWire() == true
206 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700207 Buffer::const_iterator
208 begin() const;
209
Junxiao Shidb7464d2017-07-13 03:11:17 +0000210 /** @brief Get end iterator of encoded wire
211 * @pre hasWire() == true
212 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700213 Buffer::const_iterator
214 end() const;
215
Junxiao Shidb7464d2017-07-13 03:11:17 +0000216 /** @brief Get pointer to encoded wire
217 * @pre hasWire() == true
218 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700219 const uint8_t*
220 wire() const;
221
Junxiao Shidb7464d2017-07-13 03:11:17 +0000222 /** @brief Get size of encoded wire, including Type-Length-Value
223 * @pre empty() == false
224 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700225 size_t
226 size() const;
227
Junxiao Shidb7464d2017-07-13 03:11:17 +0000228 /** @brief Get underlying buffer
229 */
230 shared_ptr<const Buffer>
231 getBuffer() const
232 {
233 return m_buffer;
234 }
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700235
Junxiao Shidb7464d2017-07-13 03:11:17 +0000236public: // type and value
237 /** @brief Get TLV-TYPE
238 */
239 uint32_t
240 type() const
241 {
242 return m_type;
243 }
244
245 /** @brief Get begin iterator of TLV-VALUE
246 *
247 * This property reflects whether the underlying buffer contains TLV-VALUE. If this is false,
248 * TLV-VALUE has zero-length. If this is true, TLV-VALUE may be zero-length.
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700249 */
250 bool
Junxiao Shidb7464d2017-07-13 03:11:17 +0000251 hasValue() const
252 {
253 return m_buffer != nullptr;
254 }
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700255
Junxiao Shidb7464d2017-07-13 03:11:17 +0000256 /** @brief Get begin iterator of TLV-VALUE
257 * @pre hasValue() == true
258 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700259 Buffer::const_iterator
Junxiao Shidb7464d2017-07-13 03:11:17 +0000260 value_begin() const
261 {
262 return m_valueBegin;
263 }
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700264
Junxiao Shidb7464d2017-07-13 03:11:17 +0000265 /** @brief Get end iterator of TLV-VALUE
266 * @pre hasValue() == true
267 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700268 Buffer::const_iterator
Junxiao Shidb7464d2017-07-13 03:11:17 +0000269 value_end() const
270 {
271 return m_valueEnd;
272 }
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700273
Junxiao Shidb7464d2017-07-13 03:11:17 +0000274 /** @brief Get pointer to TLV-VALUE
275 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700276 const uint8_t*
277 value() const;
278
Junxiao Shidb7464d2017-07-13 03:11:17 +0000279 /** @brief Get size of TLV-VALUE aka TLV-LENGTH
280 */
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700281 size_t
282 value_size() const;
283
Yingdi Yu4270f202014-01-28 14:19:16 -0800284 Block
285 blockFromValue() const;
286
Junxiao Shidb7464d2017-07-13 03:11:17 +0000287public: // sub elements
288 /** @brief Parse TLV-VALUE into sub elements
289 * @post elements() reflects sub elements found in TLV-VALUE
290 * @throw tlv::Error TLV-VALUE is not a sequence of TLV elements
291 * @note This method does not perform recursive parsing.
292 * @note This method has no effect if elements() is already populated.
293 * @note This method is not really const, but it does not modify any data.
Alexander Afanasyev74633892015-02-08 18:08:46 -0800294 */
Junxiao Shidb7464d2017-07-13 03:11:17 +0000295 void
296 parse() const;
Alexander Afanasyev74633892015-02-08 18:08:46 -0800297
Junxiao Shidb7464d2017-07-13 03:11:17 +0000298 /** @brief Encode sub elements into TLV-VALUE
299 * @post TLV-VALUE contains sub elements from elements()
300 */
301 void
302 encode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700303
Junxiao Shidb7464d2017-07-13 03:11:17 +0000304 /** @brief Get the first sub element of specified TLV-TYPE
305 * @pre parse() has been executed
306 * @throw Error sub element of @p type does not exist
307 */
308 const Block&
309 get(uint32_t type) const;
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700310
Junxiao Shidb7464d2017-07-13 03:11:17 +0000311 /** @brief Find the first sub element of specified TLV-TYPE
312 * @pre parse() has been executed
313 * @return iterator in elements() to the found sub element, otherwise elements_end()
314 */
315 element_const_iterator
316 find(uint32_t type) const;
317
318 /** @brief Remove all sub elements of specified TLV-TYPE
319 * @pre parse() has been executed
320 * @post find(type) == elements_end()
321 */
322 void
323 remove(uint32_t type);
324
325 /** @brief Erase a sub element
326 */
327 element_iterator
328 erase(element_const_iterator position);
329
330 /** @brief Erase a range of sub elements
331 */
332 element_iterator
333 erase(element_const_iterator first, element_const_iterator last);
334
335 /** @brief Append a sub element
336 */
337 void
338 push_back(const Block& element);
339
340 /** @brief Insert a sub element
341 * @param pos position of new sub element
342 * @param element new sub element
343 * @return iterator in elements() to the new sub element
344 */
345 element_iterator
346 insert(element_const_iterator pos, const Block& element);
347
348 /** @brief Get container of sub elements
349 * @pre parse() has been executed
350 */
351 const element_container&
352 elements() const
353 {
354 return m_elements;
355 }
356
357 /** @brief Equivalent to elements().begin()
358 */
359 element_const_iterator
360 elements_begin() const
361 {
362 return m_elements.begin();
363 }
364
365 /** @brief Equivalent to elements().end()
366 */
367 element_const_iterator
368 elements_end() const
369 {
370 return m_elements.end();
371 }
372
373 /** @brief Equivalent to elements().size()
374 */
375 size_t
376 elements_size() const
377 {
378 return m_elements.size();
379 }
380
381public: // misc
382 /** @brief Implicit conversion to const_buffer
383 */
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -0700384 operator boost::asio::const_buffer() const;
385
Junxiao Shid2777fa2017-07-27 18:35:34 +0000386private:
387 /** @brief Estimate Block size as if sub elements are encoded into TLV-VALUE
388 */
389 size_t
390 encode(EncodingEstimator& estimator) const;
391
392 /** @brief Encode sub elements into TLV-VALUE and prepend Block to encoder
393 * @post TLV-VALUE contains sub elements from elements()
394 * @post internal buffer and iterators point to Encoder's buffer
395 */
396 size_t
397 encode(EncodingBuffer& encoder);
398
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800399protected:
Junxiao Shidb7464d2017-07-13 03:11:17 +0000400 /** @brief underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields
401 *
402 * If m_buffer is nullptr, this is an empty Block with TLV-TYPE given in m_type.
403 * Otherwise,
404 * - [m_valueBegin, m_valueEnd) point to TLV-VALUE within m_buffer.
405 * - If m_begin != m_end, [m_begin,m_end) point to Type-Length-Value of this Block within m_buffer.
406 * Otherwise, m_buffer does not contain TLV-TYPE and TLV-LENGTH fields.
407 */
Alexander Afanasyev74633892015-02-08 18:08:46 -0800408 shared_ptr<const Buffer> m_buffer;
Junxiao Shidb7464d2017-07-13 03:11:17 +0000409 Buffer::const_iterator m_begin; ///< @sa m_buffer
410 Buffer::const_iterator m_end; ///< @sa m_buffer
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800411
Junxiao Shidb7464d2017-07-13 03:11:17 +0000412 Buffer::const_iterator m_valueBegin; ///< @sa m_buffer
413 Buffer::const_iterator m_valueEnd; ///< @sa m_buffer
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700414
Junxiao Shidb7464d2017-07-13 03:11:17 +0000415 uint32_t m_type; ///< TLV-TYPE
416
417 /** @brief total size including Type-Length-Value
418 *
419 * This field is valid only if empty() is false.
420 */
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800421 uint32_t m_size;
Alexander Afanasyev937aa782014-03-21 13:17:57 -0700422
Junxiao Shidb7464d2017-07-13 03:11:17 +0000423 /** @brief sub elements
424 *
425 * This field is valid only if parse() has been executed.
426 */
427 mutable element_container m_elements;
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800428};
429
Junxiao Shidb7464d2017-07-13 03:11:17 +0000430/** @brief Compare whether two Blocks have same TLV-TYPE, TLV-LENGTH, and TLV-VALUE
431 */
432bool
433operator==(const Block& lhs, const Block& rhs);
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800434
Junxiao Shidb7464d2017-07-13 03:11:17 +0000435inline bool
436operator!=(const Block& lhs, const Block& rhs)
Alexander Afanasyev74633892015-02-08 18:08:46 -0800437{
Junxiao Shidb7464d2017-07-13 03:11:17 +0000438 return !(lhs == rhs);
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -0800439}
440
Junxiao Shi81a6c5d2014-11-30 00:14:42 -0700441} // namespace ndn
Alexander Afanasyev13bb51a2014-01-02 19:13:26 -0800442
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700443#endif // NDN_ENCODING_BLOCK_HPP