blob: 18d4252da5d5adc71499662ccad9566d494ad21b [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonec39fbd2013-10-04 10:56:23 -07005 * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
6 * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07007 * See COPYING for copyright and distribution information.
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07008 */
9
10#ifndef NDN_NAME_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070011#define NDN_NAME_HPP
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070012
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080013#include "common.hpp"
14#include "name-component.hpp"
15
Alexander Afanasyevaf283d82014-01-03 13:23:34 -080016#include "encoding/block.hpp"
Wentao Shang77949212014-02-01 23:42:24 -080017#include "encoding/encoding-buffer.hpp"
Jeff Thompson25b4e612013-10-10 16:03:24 -070018
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080019#include <boost/iterator/reverse_iterator.hpp>
20
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070021namespace ndn {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080022
Jeff Thompsonc7d65502013-11-06 17:22:26 -080023/**
24 * A Name holds an array of Name::Component and represents an NDN name.
25 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -080026class Name : public ptr_lib::enable_shared_from_this<Name> {
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070027public:
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080028 /// @brief Error that can be thrown from the block
29 struct Error : public name::Component::Error { Error(const std::string &what) : name::Component::Error(what) {} };
Alexander Afanasyevaf283d82014-01-03 13:23:34 -080030
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080031 typedef name::Component Component;
32
33 typedef std::vector<Component> component_container;
34
35 typedef Component value_type;
36 typedef void allocator_type;
37 typedef Component& reference;
38 typedef const Component const_reference;
39 typedef Component* pointer;
40 typedef const Component* const_pointer;
41 typedef Component* iterator;
42 typedef const Component* const_iterator;
Alexander Afanasyevaf283d82014-01-03 13:23:34 -080043
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080044 typedef boost::reverse_iterator<iterator> reverse_iterator;
45 typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
46
47 typedef component_container::difference_type difference_type;
48 typedef component_container::size_type size_type;
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070049
Jeff Thompson443398d2013-07-02 19:45:46 -070050 /**
51 * Create a new Name with no components.
52 */
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -080053 Name()
54 : m_nameBlock(Tlv::Name)
55 {
Jeff Thompson016ed642013-07-02 14:39:06 -070056 }
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080057
58 /**
59 * @brief Create Name object from wire block
60 *
61 * This is a more efficient equivalent for
62 * @code
63 * Name name;
64 * name.wireDecode(wire);
65 * @endcode
66 */
67 Name(const Block &wire)
68 {
69 m_nameBlock = wire;
70 m_nameBlock.parse();
71 }
Jeff Thompson3f2175b2013-07-31 17:12:47 -070072
73 /**
Jeff Thompson443398d2013-07-02 19:45:46 -070074 * Parse the uri according to the NDN URI Scheme and create the name with the components.
Jeff Thompson3f2175b2013-07-31 17:12:47 -070075 * @param uri The URI string.
Jeff Thompson443398d2013-07-02 19:45:46 -070076 */
Jeff Thompson3549ef32013-09-25 14:05:17 -070077 Name(const char* uri)
Jeff Thompson67515bd2013-08-15 17:43:22 -070078 {
79 set(uri);
80 }
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070081
Jeff Thompsone5f839b2013-06-28 12:50:38 -070082 /**
Jeff Thompson3549ef32013-09-25 14:05:17 -070083 * Parse the uri according to the NDN URI Scheme and create the name with the components.
84 * @param uri The URI string.
85 */
86 Name(const std::string& uri)
87 {
88 set(uri.c_str());
89 }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -070090
Wentao Shang77949212014-02-01 23:42:24 -080091 size_t
92 wireEncode (EncodingBuffer& blk);
93
Alexander Afanasyevaf283d82014-01-03 13:23:34 -080094 const Block &
95 wireEncode() const;
Alexander Afanasyev848c61a2014-01-03 13:52:04 -080096
97 void
98 wireDecode(const Block &wire);
Jeff Thompsonb468c312013-07-01 17:50:14 -070099
100 /**
Jeff Thompson67515bd2013-08-15 17:43:22 -0700101 * Parse the uri according to the NDN URI Scheme and set the name with the components.
Jeff Thompson7781b392013-12-17 11:45:59 -0800102 * @param uri The null-terminated URI string.
Jeff Thompson67515bd2013-08-15 17:43:22 -0700103 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700104 void
105 set(const char *uri);
Jeff Thompson67515bd2013-08-15 17:43:22 -0700106
107 /**
Jeff Thompson7781b392013-12-17 11:45:59 -0800108 * Parse the uri according to the NDN URI Scheme and set the name with the components.
109 * @param uri The URI string.
110 */
111 void
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800112 set(const std::string& uri)
113 {
114 set(uri.c_str());
115 }
Jeff Thompson7781b392013-12-17 11:45:59 -0800116
117 /**
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700118 * Append a new component, copying from value of length valueLength.
Jeff Thompson26b0d792013-09-23 16:19:01 -0700119 * @return This name so that you can chain calls to append.
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700120 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700121 Name&
Jeff Thompson97223af2013-09-24 17:01:27 -0700122 append(const uint8_t *value, size_t valueLength)
Jeff Thompson0f743452013-09-12 14:23:18 -0700123 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800124 m_nameBlock.elements().push_back(Component(value, valueLength));
Jeff Thompson26b0d792013-09-23 16:19:01 -0700125 return *this;
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700126 }
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700127
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800128 // /**
129 // * Append a new component, copying from value.
130 // * @return This name so that you can chain calls to append.
131 // */
132 // Name&
133 // append(const Buffer& value)
134 // {
135 // m_nameBlock.elements().push_back(value);
136 // return *this;
137 // }
Jeff Thompson0f743452013-09-12 14:23:18 -0700138
Jeff Thompson26b0d792013-09-23 16:19:01 -0700139 Name&
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800140 append(const ConstBufferPtr &value)
Jeff Thompson0f743452013-09-12 14:23:18 -0700141 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800142 m_nameBlock.elements().push_back(value);
Jeff Thompson26b0d792013-09-23 16:19:01 -0700143 return *this;
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700144 }
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700145
Jeff Thompson21eb7212013-09-26 09:05:40 -0700146 Name&
147 append(const Component &value)
148 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800149 m_nameBlock.elements().push_back(value);
Jeff Thompson21eb7212013-09-26 09:05:40 -0700150 return *this;
151 }
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800152
Alexander Afanasyev594cdb22014-01-03 15:11:33 -0800153 /**
154 * @brief Append name component that represented as a string
155 *
156 * Note that this method is necessary to ensure correctness and unambiguity of
157 * ``append("string")`` operations (both Component and Name can be implicitly
158 * converted from string, each having different outcomes
159 */
160 Name&
161 append(const char *value)
162 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800163 m_nameBlock.elements().push_back(Component(value));
Alexander Afanasyev594cdb22014-01-03 15:11:33 -0800164 return *this;
165 }
166
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800167 Name&
168 append(const Block &value)
169 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800170 m_nameBlock.elements().push_back(Component(value.begin(), value.end()));
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800171 return *this;
172 }
Jeff Thompson21eb7212013-09-26 09:05:40 -0700173
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700174 /**
Jeff Thompson26b0d792013-09-23 16:19:01 -0700175 * Append the components of the given name to this name.
176 * @param name The Name with components to append.
177 * @return This name so that you can chain calls to append.
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700178 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700179 Name&
180 append(const Name& name);
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800181
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700182 /**
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700183 * Clear all the components.
184 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700185 void
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800186 clear()
187 {
188 m_nameBlock = Block(Tlv::Name);
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700189 }
190
191 /**
Jeff Thompsond0159d72013-09-23 13:34:15 -0700192 * Get a new name, constructed as a subset of components.
193 * @param iStartComponent The index if the first component to get.
194 * @param nComponents The number of components starting at iStartComponent.
195 * @return A new name.
196 */
197 Name
198 getSubName(size_t iStartComponent, size_t nComponents) const;
199
200 /**
201 * Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name.
202 * @param iStartComponent The index if the first component to get.
203 * @return A new name.
204 */
205 Name
206 getSubName(size_t iStartComponent) const;
207
208 /**
209 * Return a new Name with the first nComponents components of this Name.
Jeff Thompsoneb0358f2013-12-17 10:59:53 -0800210 * @param nComponents The number of prefix components. If nComponents is -N then return the prefix up
211 * to name.size() - N. For example getPrefix(-1) returns the name without the final component.
Jeff Thompsond0159d72013-09-23 13:34:15 -0700212 * @return A new Name.
213 */
214 Name
Jeff Thompsoneb0358f2013-12-17 10:59:53 -0800215 getPrefix(int nComponents) const
Jeff Thompsond0159d72013-09-23 13:34:15 -0700216 {
Jeff Thompsoneb0358f2013-12-17 10:59:53 -0800217 if (nComponents < 0)
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800218 return getSubName(0, m_nameBlock.elements().size() + nComponents);
Jeff Thompsoneb0358f2013-12-17 10:59:53 -0800219 else
220 return getSubName(0, nComponents);
Jeff Thompsond0159d72013-09-23 13:34:15 -0700221 }
222
223 /**
Jeff Thompsone6063512013-07-01 15:11:28 -0700224 * Encode this name as a URI.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700225 * @return The encoded URI.
Jeff Thompsone6063512013-07-01 15:11:28 -0700226 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700227 std::string
228 toUri() const;
Jeff Thompsone6063512013-07-01 15:11:28 -0700229
Jeff Thompson21844fc2013-08-08 14:52:51 -0700230 /**
Jeff Thompson8aac1992013-08-12 17:26:02 -0700231 * Append a component with the encoded segment number.
232 * @param segment The segment number.
Jeff Thompson26b0d792013-09-23 16:19:01 -0700233 * @return This name so that you can chain calls to append.
234 */
235 Name&
Jeff Thompsond129ac12013-10-11 14:30:12 -0700236 appendSegment(uint64_t segment)
Jeff Thompson8aac1992013-08-12 17:26:02 -0700237 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800238 m_nameBlock.elements().push_back(Component::fromNumberWithMarker(segment, 0x00));
Jeff Thompsond129ac12013-10-11 14:30:12 -0700239 return *this;
240 }
241
242 /**
243 * Append a component with the encoded version number.
244 * Note that this encodes the exact value of version without converting from a time representation.
245 * @param version The version number.
246 * @return This name so that you can chain calls to append.
247 */
248 Name&
249 appendVersion(uint64_t version)
250 {
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800251 m_nameBlock.elements().push_back(Component::fromNumberWithMarker(version, 0xFD));
Jeff Thompson26b0d792013-09-23 16:19:01 -0700252 return *this;
Jeff Thompson8aac1992013-08-12 17:26:02 -0700253 }
Alexander Afanasyev594cdb22014-01-03 15:11:33 -0800254
255 /**
256 * @brief Append a component with the encoded version number.
257 *
258 * This version of the method creates version number based on the current timestamp
259 * @return This name so that you can chain calls to append.
260 */
261 Name&
262 appendVersion();
Jeff Thompsoncc35cd42013-08-20 12:23:14 -0700263
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700264 /**
Jeff Thompson3c2ab012013-10-02 14:18:16 -0700265 * Check if this name has the same component count and components as the given name.
266 * @param name The Name to check.
267 * @return true if the names are equal, otherwise false.
268 */
269 bool
270 equals(const Name& name) const;
271
272 /**
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700273 * Check if the N components of this name are the same as the first N components of the given name.
274 * @param name The Name to check.
275 * @return true if this matches the given name, otherwise false. This always returns true if this name is empty.
276 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700277 bool
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800278 isPrefixOf(const Name& name) const;
279
280 bool
281 match(const Name& name) const
282 {
283 return isPrefixOf(name);
284 }
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700285
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700286 //
287 // vector equivalent interface.
288 //
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800289
290 /**
291 * @brief Check if name is emtpy
292 */
293 bool
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800294 empty() const { return m_nameBlock.elements().empty(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700295
296 /**
297 * Get the number of components.
298 * @return The number of components.
299 */
300 size_t
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800301 size() const { return m_nameBlock.elements().size(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700302
303 /**
304 * Get the component at the given index.
305 * @param i The index of the component, starting from 0.
306 * @return The name component at the index.
307 */
308 const Component&
Alexander Afanasyev8f9aa8bed2013-12-30 15:58:57 -0800309 get(ssize_t i) const
310 {
311 if (i >= 0)
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800312 return reinterpret_cast<const Component&>(m_nameBlock.elements()[i]);
Alexander Afanasyev8f9aa8bed2013-12-30 15:58:57 -0800313 else
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800314 return reinterpret_cast<const Component&>(m_nameBlock.elements()[size() + i]);
315 }
316
317 const Component&
318 operator [] (ssize_t i) const
319 {
320 return get(i);
Alexander Afanasyev8f9aa8bed2013-12-30 15:58:57 -0800321 }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700322
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800323 const Component&
324 at(ssize_t i) const
325 {
326 return get(i);
327 }
328
Jeff Thompsonafc45a92014-01-15 12:42:45 -0800329 /**
330 * Compare this to the other Name using NDN canonical ordering. If the first components of each name are not equal,
331 * this returns -1 if the first comes before the second using the NDN canonical ordering for name components, or 1 if it comes after.
332 * If they are equal, this compares the second components of each name, etc. If both names are the same up to
333 * the size of the shorter name, this returns -1 if the first name is shorter than the second or 1 if it is longer.
334 * For example, if you std::sort gives: /a/b/d /a/b/cc /c /c/a /bb . This is intuitive because all names
335 * with the prefix /a are next to each other. But it may be also be counter-intuitive because /c comes before /bb
336 * according to NDN canonical ordering since it is shorter.
337 * @param other The other Name to compare with.
338 * @return 0 If they compare equal, -1 if *this comes before other in the canonical ordering, or
339 * 1 if *this comes after other in the canonical ordering.
340 *
341 * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html
342 */
343 int
344 compare(const Name& other) const;
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700345
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700346 /**
347 * Append the component
348 * @param component The component of type T.
349 */
350 template<class T> void
351 push_back(const T &component)
352 {
353 append(component);
354 }
355
Jeff Thompson91737f52013-10-04 11:07:24 -0700356 /**
357 * Check if this name has the same component count and components as the given name.
358 * @param name The Name to check.
359 * @return true if the names are equal, otherwise false.
360 */
361 bool
362 operator == (const Name &name) const { return equals(name); }
363
364 /**
365 * Check if this name has the same component count and components as the given name.
366 * @param name The Name to check.
367 * @return true if the names are not equal, otherwise false.
368 */
369 bool
370 operator != (const Name &name) const { return !equals(name); }
Jeff Thompson82568ad2013-12-17 15:17:40 -0800371
372 /**
Jeff Thompsonafc45a92014-01-15 12:42:45 -0800373 * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
374 * @param other The other Name to compare with.
375 *
376 * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html
Jeff Thompson82568ad2013-12-17 15:17:40 -0800377 */
Jeff Thompsonafc45a92014-01-15 12:42:45 -0800378 bool
379 operator <= (const Name& other) const { return compare(other) <= 0; }
380
381 /**
382 * Return true if this is less than the other Name in the NDN canonical ordering.
383 * @param other The other Name to compare with.
384 *
385 * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html
386 */
387 bool
388 operator < (const Name& other) const { return compare(other) < 0; }
389
390 /**
391 * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
392 * @param other The other Name to compare with.
393 *
394 * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html
395 */
396 bool
397 operator >= (const Name& other) const { return compare(other) >= 0; }
398
399 /**
400 * Return true if this is greater than the other Name in the NDN canonical ordering.
401 * @param other The other Name to compare with.
402 *
403 * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html
404 */
405 bool
406 operator > (const Name& other) const { return compare(other) > 0; }
Jeff Thompson82568ad2013-12-17 15:17:40 -0800407
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700408 //
409 // Iterator interface to name components.
410 //
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700411
412 /**
413 * Begin iterator (const).
414 */
415 const_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800416 begin() const
417 {
418 return reinterpret_cast<const_iterator>(&*m_nameBlock.elements().begin());
419 }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700420
421 /**
422 * Begin iterator.
423 */
424 iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800425 begin() { return reinterpret_cast<iterator>(&*m_nameBlock.elements().begin()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700426
427 /**
428 * End iterator (const).
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800429 *
430 * @todo Check if this crash when there are no elements in the buffer
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700431 */
432 const_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800433 end() const { return reinterpret_cast<const_iterator>(&*m_nameBlock.elements().end()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700434
435 /**
436 * End iterator.
437 */
438 iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800439 end() { return reinterpret_cast<iterator>(&*m_nameBlock.elements().end()); }
440
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700441 /**
442 * Reverse begin iterator (const).
443 */
444 const_reverse_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800445 rbegin() const { return const_reverse_iterator(end()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700446
447 /**
448 * Reverse begin iterator.
449 */
450 reverse_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800451 rbegin() { return reverse_iterator(end()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700452
453 /**
454 * Reverse end iterator (const).
455 */
456 const_reverse_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800457 rend() const { return const_reverse_iterator(begin()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700458
459 /**
460 * Reverse end iterator.
461 */
462 reverse_iterator
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800463 rend() { return reverse_iterator(begin()); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700464
Jeff Thompson9c41dfe2013-06-27 12:10:25 -0700465private:
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800466 mutable Block m_nameBlock;
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800467};
468
469std::ostream &
470operator << (std::ostream &os, const Name &name);
471
472inline std::string
473Name::toUri() const
Jeff Thompson49e321a2013-10-04 17:35:59 -0700474{
Alexander Afanasyevaf283d82014-01-03 13:23:34 -0800475 std::ostringstream os;
476 os << *this;
477 return os.str();
Jeff Thompson49e321a2013-10-04 17:35:59 -0700478}
479
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800480inline const Block &
481Name::wireEncode() const
482{
483 if (m_nameBlock.hasWire())
484 return m_nameBlock;
485
486 for (Block::element_iterator i = m_nameBlock.element_begin();
487 i != m_nameBlock.element_end();
488 ++i)
489 {
490 i->encode();
491 }
492
493 m_nameBlock.encode();
494 return m_nameBlock;
495}
496
497inline void
498Name::wireDecode(const Block &wire)
499{
500 m_nameBlock = wire;
501 m_nameBlock.parse();
502}
503
504inline size_t
505Name::wireEncode (EncodingBuffer& blk)
506{
507 size_t total_len = 0;
508
509 for (reverse_iterator i = rbegin ();
510 i != rend ();
511 ++i)
512 {
513 total_len += i->wireEncode (blk);
514 }
515
516 total_len += blk.prependVarNumber (total_len);
517 total_len += blk.prependVarNumber (Tlv::Name);
518 return total_len;
519}
520
521
Alexander Afanasyev95e8c2f2014-02-06 17:29:30 -0800522} // namespace ndn
Jeff Thompson9c41dfe2013-06-27 12:10:25 -0700523
524#endif
525