Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 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. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_NAME_COMPONENT_HPP |
| 23 | #define NDN_NAME_COMPONENT_HPP |
| 24 | |
| 25 | #include "common.hpp" |
| 26 | #include "encoding/block.hpp" |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 27 | #include "encoding/block-helpers.hpp" |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 28 | #include "util/time.hpp" |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace name { |
| 32 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 33 | /// @brief Segment marker for NDN naming conventions |
| 34 | static const uint8_t SEGMENT_MARKER = 0x00; |
| 35 | /// @brief Segment offset marker for NDN naming conventions |
| 36 | static const uint8_t SEGMENT_OFFSET_MARKER = 0xFB; |
| 37 | /// @brief Version marker for NDN naming conventions |
| 38 | static const uint8_t VERSION_MARKER = 0xFD; |
| 39 | /// @brief Timestamp marker for NDN naming conventions |
| 40 | static const uint8_t TIMESTAMP_MARKER = 0xFC; |
| 41 | /// @brief Sequence number marker for NDN naming conventions |
| 42 | static const uint8_t SEQUENCE_NUMBER_MARKER = 0xFE; |
| 43 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 44 | /** @brief Represents a name component. |
| 45 | * |
| 46 | * The @c Component class provides a read-only view of a @c Block interpreted as a name component. |
| 47 | * Although it inherits mutation methods from @c Block base class, they must not be used, because |
| 48 | * the enclosing @c Name would not be updated correctly. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 49 | */ |
| 50 | class Component : public Block |
| 51 | { |
| 52 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 53 | class Error : public Block::Error |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 54 | { |
| 55 | public: |
| 56 | explicit |
| 57 | Error(const std::string& what) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 58 | : Block::Error(what) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 59 | { |
| 60 | } |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 63 | public: // constructors |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 64 | /** |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 65 | * @brief Construct a NameComponent of TLV-TYPE @p type, using empty TLV-VALUE. |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 66 | * @throw Error the NameComponent is invalid (see @c ensureValid). |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 67 | */ |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 68 | explicit |
| 69 | Component(uint32_t type = tlv::GenericNameComponent); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 71 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 72 | * @brief Construct a NameComponent from @p block. |
| 73 | * @throw Error the NameComponent is invalid (see @c ensureValid). |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 74 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 75 | * This contructor enables implicit conversion from @c Block. |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 76 | */ |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 77 | Component(const Block& wire); |
| 78 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 79 | /** |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 80 | * @brief Construct a NameComponent of TLV-TYPE @p type, using TLV-VALUE from @p buffer. |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 81 | * @throw Error the NameComponent is invalid (see @c ensureValid). |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 82 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 83 | * This constructor does not copy the underlying buffer, but retains a pointer to it. |
| 84 | * Therefore, the caller must not change the underlying buffer. |
| 85 | */ |
| 86 | Component(uint32_t type, ConstBufferPtr buffer); |
| 87 | |
| 88 | /** |
| 89 | * @brief Construct a GenericNameComponent, using TLV-VALUE from @p buffer. |
| 90 | * @throw Error the NameComponent is invalid (see @c ensureValid). |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 91 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 92 | * This constructor does not copy the underlying buffer, but retains a pointer to it. |
| 93 | * Therefore, the caller must not change the underlying buffer. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 94 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 95 | explicit |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 96 | Component(ConstBufferPtr buffer) |
| 97 | : Component(tlv::GenericNameComponent, std::move(buffer)) |
| 98 | { |
| 99 | } |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 101 | /** |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 102 | * @brief Construct a NameComponent of TLV-TYPE @p type, copying TLV-VALUE from @p buffer. |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 103 | */ |
| 104 | Component(uint32_t type, const Buffer& buffer) |
| 105 | : Component(type, buffer.data(), buffer.size()) |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @brief Construct a GenericNameComponent, copying TLV-VALUE from @p buffer. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 111 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 112 | explicit |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 113 | Component(const Buffer& buffer) |
| 114 | : Component(tlv::GenericNameComponent, buffer) |
| 115 | { |
| 116 | } |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 117 | |
| 118 | /** |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 119 | * @brief Construct a NameComponent of TLV-TYPE @p type, copying @p count bytes at @p value as |
| 120 | * TLV-VALUE. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 121 | */ |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 122 | Component(uint32_t type, const uint8_t* value, size_t count); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 123 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 124 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 125 | * @brief Construct a GenericNameComponent, copying @p count bytes at @p value as TLV-VALUE. |
| 126 | */ |
| 127 | Component(const uint8_t* value, size_t count) |
| 128 | : Component(tlv::GenericNameComponent, value, count) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | /** |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 133 | * @brief Construct a NameComponent of TLV-TYPE @p type, copying TLV-VALUE from a range. |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 134 | * @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient |
| 135 | * implementation is available when it is a @c RandomAccessIterator. |
| 136 | * @param type the TLV-TYPE. |
| 137 | * @param first beginning of the range. |
| 138 | * @param last past-end of the range. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 139 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 140 | template<class Iterator> |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 141 | Component(uint32_t type, Iterator first, Iterator last) |
| 142 | : Block(makeBinaryBlock(type, first, last)) |
| 143 | { |
| 144 | } |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 145 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 146 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 147 | * @brief Construct a GenericNameComponent, copying TLV-VALUE from a range. |
| 148 | */ |
| 149 | template<class Iterator> |
| 150 | Component(Iterator first, Iterator last) |
| 151 | : Component(tlv::GenericNameComponent, first, last) |
| 152 | { |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @brief Construct a GenericNameComponent, copying TLV-VALUE from a null-terminated string. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 157 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 158 | * Bytes from the string are copied as is, and not interpreted as URI component. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 159 | */ |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 160 | explicit |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 161 | Component(const char* str); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 162 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 163 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 164 | * @brief Construct a GenericNameComponent, copying TLV-VALUE from a string. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 165 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 166 | * Bytes from the string are copied as is, and not interpreted as URI component. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 167 | */ |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 168 | explicit |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 169 | Component(const std::string& str); |
| 170 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 171 | public: // encoding and URI |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 172 | /** |
| 173 | * @brief Fast encoding or block size estimation |
| 174 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 175 | template<encoding::Tag TAG> |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 176 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 177 | wireEncode(EncodingImpl<TAG>& encoder) const; |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 178 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 179 | /** |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 180 | * @brief Encode to a wire format |
| 181 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 182 | const Block& |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 183 | wireEncode() const; |
| 184 | |
| 185 | /** |
| 186 | * @brief Decode from the wire format |
| 187 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 188 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 189 | wireDecode(const Block& wire); |
| 190 | |
| 191 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 192 | * @brief Decode NameComponent from a URI component. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 193 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 194 | * The URI component is read from `[input+beginOffset, input+endOffset)` range. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 195 | * |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 196 | * @throw Error URI component does not represent a valid NameComponent. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 197 | */ |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 198 | static Component |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 199 | fromEscapedString(const char* input, size_t beginOffset, size_t endOffset) |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 200 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 201 | return fromEscapedString(std::string(input + beginOffset, input + endOffset)); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 205 | * @brief Decode NameComponent from a URI component. |
| 206 | * @throw Error URI component does not represent a valid NameComponent. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 207 | */ |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 208 | static Component |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 209 | fromEscapedString(const char* input) |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 210 | { |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 211 | return fromEscapedString(std::string(input)); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /** |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 215 | * @brief Decode NameComponent from a URI component. |
| 216 | * @throw Error URI component does not represent a valid NameComponent. |
| 217 | */ |
| 218 | static Component |
| 219 | fromEscapedString(std::string input); |
| 220 | |
| 221 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 222 | * @brief Write *this to the output stream, escaping characters according to the NDN URI Scheme |
| 223 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 224 | * This also adds "..." to a value with zero or more "." |
| 225 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 226 | * @param os The output stream where to write the URI escaped version of *this |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 227 | */ |
| 228 | void |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 229 | toUri(std::ostream& os) const; |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 230 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 231 | /** |
| 232 | * @brief Convert *this by escaping characters according to the NDN URI Scheme |
| 233 | * |
| 234 | * This also adds "..." to a value with zero or more "." |
| 235 | * |
| 236 | * @return The escaped string |
| 237 | */ |
| 238 | std::string |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 239 | toUri() const; |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 240 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 241 | public: // naming conventions |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 242 | /** |
| 243 | * @brief Check if the component is nonNegativeInteger |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 244 | * @sa https://named-data.net/doc/NDN-packet-spec/current/tlv.html#non-negative-integer-encoding |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 245 | */ |
| 246 | bool |
| 247 | isNumber() const; |
| 248 | |
| 249 | /** |
| 250 | * @brief Check if the component is NameComponentWithMarker per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 251 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 252 | */ |
| 253 | bool |
| 254 | isNumberWithMarker(uint8_t marker) const; |
| 255 | |
| 256 | /** |
| 257 | * @brief Check if the component is version per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 258 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 259 | */ |
| 260 | bool |
| 261 | isVersion() const; |
| 262 | |
| 263 | /** |
| 264 | * @brief Check if the component is segment number per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 265 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 266 | */ |
| 267 | bool |
| 268 | isSegment() const; |
| 269 | |
| 270 | /** |
| 271 | * @brief Check if the component is segment offset per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 272 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 273 | */ |
| 274 | bool |
| 275 | isSegmentOffset() const; |
| 276 | |
| 277 | /** |
| 278 | * @brief Check if the component is timestamp per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 279 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 280 | */ |
| 281 | bool |
| 282 | isTimestamp() const; |
| 283 | |
| 284 | /** |
| 285 | * @brief Check if the component is sequence number per NDN naming conventions |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 286 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 0f232c5 | 2014-10-23 13:07:31 -0700 | [diff] [blame] | 287 | */ |
| 288 | bool |
| 289 | isSequenceNumber() const; |
| 290 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 291 | /** |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 292 | * @brief Interpret this name component as nonNegativeInteger |
| 293 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 294 | * @sa https://named-data.net/doc/NDN-packet-spec/current/tlv.html#non-negative-integer-encoding |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 295 | * |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 296 | * @return The integer number. |
| 297 | */ |
| 298 | uint64_t |
| 299 | toNumber() const; |
| 300 | |
| 301 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 302 | * @brief Interpret this name component as NameComponentWithMarker |
| 303 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 304 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 305 | * |
| 306 | * @param marker 1-byte octet of the marker |
| 307 | * @return The integer number. |
| 308 | * @throws Error if name component does not have the specified marker. |
| 309 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
| 310 | */ |
| 311 | uint64_t |
| 312 | toNumberWithMarker(uint8_t marker) const; |
| 313 | |
| 314 | /** |
| 315 | * @brief Interpret as version component using NDN naming conventions |
| 316 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 317 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 318 | * |
| 319 | * @throws Error if name component does not have the specified marker. |
| 320 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 321 | */ |
| 322 | uint64_t |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 323 | toVersion() const; |
| 324 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 325 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 326 | * @brief Interpret as segment number component using NDN naming conventions |
| 327 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 328 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 329 | * |
| 330 | * @throws Error if name component does not have the specified marker. |
| 331 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 332 | */ |
| 333 | uint64_t |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 334 | toSegment() const; |
| 335 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 336 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 337 | * @brief Interpret as segment offset component using NDN naming conventions |
| 338 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 339 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 340 | * |
| 341 | * @throws Error if name component does not have the specified marker. |
| 342 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
| 343 | */ |
| 344 | uint64_t |
| 345 | toSegmentOffset() const; |
| 346 | |
| 347 | /** |
| 348 | * @brief Interpret as timestamp component using NDN naming conventions |
| 349 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 350 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 351 | * |
| 352 | * @throws Error if name component does not have the specified marker. |
| 353 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
| 354 | */ |
| 355 | time::system_clock::TimePoint |
| 356 | toTimestamp() const; |
| 357 | |
| 358 | /** |
| 359 | * @brief Interpret as sequence number component using NDN naming conventions |
| 360 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 361 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 362 | * |
| 363 | * @throws Error if name component does not have the specified marker. |
| 364 | * tlv::Error if format does not follow NameComponentWithMarker specification. |
| 365 | */ |
| 366 | uint64_t |
| 367 | toSequenceNumber() const; |
| 368 | |
| 369 | /** |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 370 | * @brief Create a component encoded as nonNegativeInteger |
| 371 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 372 | * @sa https://named-data.net/doc/NDN-packet-spec/current/tlv.html#non-negative-integer-encoding |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 373 | * |
| 374 | * @param number The non-negative number |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 375 | * @return The component value. |
| 376 | */ |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 377 | static Component |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 378 | fromNumber(uint64_t number); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 379 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 380 | /** |
| 381 | * @brief Create a component encoded as NameComponentWithMarker |
| 382 | * |
| 383 | * NameComponentWithMarker is defined as: |
| 384 | * |
| 385 | * NameComponentWithMarker ::= NAME-COMPONENT-TYPE TLV-LEGTH |
| 386 | * Marker |
| 387 | * includedNonNegativeInteger |
| 388 | * Marker ::= BYTE |
| 389 | * includedNonNegativeInteger ::= BYTE{1,2,4,8} |
| 390 | * NDN-TLV := TLV-TYPE TLV-LENGTH TLV-VALUE? |
| 391 | * TLV-TYPE := VAR-NUMBER |
| 392 | * TLV-LENGTH := VAR-NUMBER |
| 393 | * TLV-VALUE := BYTE+ |
| 394 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 395 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 396 | * |
| 397 | * @param marker 1-byte marker octet |
| 398 | * @param number The non-negative number |
| 399 | * @return The component value. |
| 400 | */ |
| 401 | static Component |
| 402 | fromNumberWithMarker(uint8_t marker, uint64_t number); |
| 403 | |
| 404 | /** |
| 405 | * @brief Create version component using NDN naming conventions |
| 406 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 407 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 408 | */ |
| 409 | static Component |
| 410 | fromVersion(uint64_t version); |
| 411 | |
| 412 | /** |
| 413 | * @brief Create segment number component using NDN naming conventions |
| 414 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 415 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 416 | */ |
| 417 | static Component |
| 418 | fromSegment(uint64_t segmentNo); |
| 419 | |
| 420 | /** |
| 421 | * @brief Create segment offset component using NDN naming conventions |
| 422 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 423 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 424 | */ |
| 425 | static Component |
| 426 | fromSegmentOffset(uint64_t offset); |
| 427 | |
| 428 | /** |
| 429 | * @brief Create sequence number component using NDN naming conventions |
| 430 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 431 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 432 | */ |
| 433 | static Component |
| 434 | fromTimestamp(const time::system_clock::TimePoint& timePoint); |
| 435 | |
| 436 | /** |
| 437 | * @brief Create sequence number component using NDN naming conventions |
| 438 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 439 | * @sa NDN Naming Conventions https://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 440 | */ |
| 441 | static Component |
| 442 | fromSequenceNumber(uint64_t seqNo); |
| 443 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 444 | public: // commonly used TLV-TYPEs |
Alexander Afanasyev | 6486d52 | 2014-10-23 14:14:11 -0700 | [diff] [blame] | 445 | /** |
| 446 | * @brief Check if the component is GenericComponent |
| 447 | */ |
| 448 | bool |
| 449 | isGeneric() const; |
| 450 | |
| 451 | /** |
| 452 | * @brief Check if the component is ImplicitSha256DigestComponent |
| 453 | */ |
| 454 | bool |
| 455 | isImplicitSha256Digest() const; |
| 456 | |
| 457 | /** |
| 458 | * @brief Create ImplicitSha256DigestComponent component |
| 459 | */ |
| 460 | static Component |
| 461 | fromImplicitSha256Digest(const ConstBufferPtr& digest); |
| 462 | |
| 463 | /** |
| 464 | * @brief Create ImplicitSha256DigestComponent component |
| 465 | */ |
| 466 | static Component |
| 467 | fromImplicitSha256Digest(const uint8_t* digest, size_t digestSize); |
| 468 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 469 | public: // operators |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 470 | bool |
| 471 | empty() const |
| 472 | { |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 473 | return value_size() == 0; |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 476 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 477 | * @brief Check if this is the same component as other |
| 478 | * |
| 479 | * @param other The other Component to compare with |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 480 | * @return true if the components are equal, otherwise false. |
| 481 | */ |
| 482 | bool |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 483 | equals(const Component& other) const; |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 484 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 485 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 486 | * @brief Compare this to the other Component using NDN canonical ordering |
| 487 | * |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 488 | * @param other The other Component to compare with. |
Joao Pereira | aa8fd16 | 2015-06-05 16:35:15 -0400 | [diff] [blame] | 489 | * @retval negative this comes before other in canonical ordering |
| 490 | * @retval zero this equals other |
| 491 | * @retval positive this comes after other in canonical ordering |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 492 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 493 | * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#canonical-order |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 494 | */ |
| 495 | int |
| 496 | compare(const Component& other) const; |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 497 | |
| 498 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 499 | * @brief Check if this is the same component as other |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 500 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 501 | * @param other The other Component to compare with. |
| 502 | * @return true if the components are equal, otherwise false. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 503 | */ |
| 504 | bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 505 | operator==(const Component& other) const |
| 506 | { |
| 507 | return equals(other); |
| 508 | } |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 509 | |
| 510 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 511 | * @brief Check if this is not the same component as other |
| 512 | * @param other The other Component to compare with |
| 513 | * @return true if the components are not equal, otherwise false |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 514 | */ |
| 515 | bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 516 | operator!=(const Component& other) const |
| 517 | { |
| 518 | return !equals(other); |
| 519 | } |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 520 | |
| 521 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 522 | * @brief Check if the *this is less than or equal to the other in NDN canonical ordering |
| 523 | * @param other The other Component to compare with |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 524 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 525 | * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#canonical-order |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 526 | */ |
| 527 | bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 528 | operator<=(const Component& other) const |
| 529 | { |
| 530 | return compare(other) <= 0; |
| 531 | } |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 532 | |
| 533 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 534 | * @brief Check if the *this is less than the other in NDN canonical ordering |
| 535 | * @param other The other Component to compare with |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 536 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 537 | * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#canonical-order |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 538 | */ |
| 539 | bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 540 | operator<(const Component& other) const |
| 541 | { |
| 542 | return compare(other) < 0; |
| 543 | } |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 544 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 545 | /** |
| 546 | * @brief Check if the *this is greater or equal than the other in NDN canonical ordering |
| 547 | * @param other The other Component to compare with |
| 548 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 549 | * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#canonical-order |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 550 | */ |
| 551 | bool |
| 552 | operator>=(const Component& other) const |
| 553 | { |
| 554 | return compare(other) >= 0; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * @brief Check if the *this is greater than the other in NDN canonical ordering |
| 559 | * @param other The other Component to compare with |
| 560 | * |
Junxiao Shi | a36f15d | 2018-04-04 02:22:11 +0000 | [diff] [blame] | 561 | * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#canonical-order |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 562 | */ |
| 563 | bool |
| 564 | operator>(const Component& other) const |
| 565 | { |
| 566 | return compare(other) > 0; |
| 567 | } |
| 568 | |
Junxiao Shi | cf0aff8 | 2018-07-23 06:42:13 -0600 | [diff] [blame^] | 569 | /** |
| 570 | * @brief Get the successor of this name component. |
| 571 | * |
| 572 | * The successor of a name component is defined as follows: |
| 573 | * |
| 574 | * C represents the set of name components, and X,Y ∈ C. |
| 575 | * Operator < is defined by canonical order on C. |
| 576 | * Y is the successor of X, if (a) X < Y, and (b) ∄ Z ∈ C s.t. X < Z < Y. |
| 577 | * |
| 578 | * In plain words, successor of a name component is the next possible name component. |
| 579 | * |
| 580 | * Examples: |
| 581 | * |
| 582 | * - successor of `sha256digest=0000000000000000000000000000000000000000000000000000000000000000` |
| 583 | * is `sha256digest=0000000000000000000000000000000000000000000000000000000000000001`. |
| 584 | * - successor of `sha256digest=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff` |
| 585 | * is `2=...`. |
| 586 | * - successor of `A` is `B`. |
| 587 | * - successor of `%FF` is `%00%00`. |
| 588 | */ |
Junxiao Shi | df4b24e | 2016-07-14 21:41:43 +0000 | [diff] [blame] | 589 | Component |
| 590 | getSuccessor() const; |
| 591 | |
Junxiao Shi | cf4ac5b | 2018-03-28 22:46:06 +0000 | [diff] [blame] | 592 | private: |
| 593 | /** |
| 594 | * @brief Throw @c Error if this NameComponent is invalid. |
| 595 | * |
| 596 | * A NameComponent is invalid if its TLV-TYPE is outside the 1-65535 range. |
| 597 | * Additionally, if this is an ImplicitSha256DigestComponent, the TLV-LENGTH must be 32. |
| 598 | */ |
| 599 | void |
| 600 | ensureValid() const; |
| 601 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 602 | // !!! NOTE TO IMPLEMENTOR !!! |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 603 | // |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 604 | // This class MUST NOT contain any data fields. |
| 605 | // Block can be reinterpret_cast'ed as Component type. |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 606 | }; |
| 607 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 608 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Component); |
| 609 | |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 610 | inline std::ostream& |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 611 | operator<<(std::ostream& os, const Component& component) |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 612 | { |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 613 | component.toUri(os); |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 614 | return os; |
| 615 | } |
| 616 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 617 | } // namespace name |
| 618 | } // namespace ndn |
| 619 | |
| 620 | #endif // NDN_NAME_COMPONENT_HPP |