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