Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Author: Jeff Thompson |
| 3 | * |
| 4 | * BSD license, See the LICENSE file for more information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_NAME_HPP |
| 8 | #define NDN_NAME_HPP |
| 9 | |
| 10 | #include <vector> |
| 11 | #include "common.h" |
| 12 | #include "encoding/BinaryXMLWireFormat.hpp" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | class Name { |
| 17 | public: |
| 18 | Name(); |
| 19 | Name(const char *uri); |
| 20 | |
| 21 | void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) { |
| 22 | wireFormat.encodeName(*this, output); |
| 23 | } |
| 24 | void encode(std::vector<unsigned char> &output) { |
| 25 | encode(output, BinaryXMLWireFormat::instance()); |
| 26 | } |
Jeff Thompson | 4238071 | 2013-06-28 10:59:33 -0700 | [diff] [blame] | 27 | void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) { |
| 28 | wireFormat.decodeName(*this, input, inputLength); |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 29 | } |
Jeff Thompson | 4238071 | 2013-06-28 10:59:33 -0700 | [diff] [blame] | 30 | void decode(const unsigned char *input, unsigned int inputLength) { |
| 31 | decode(input, inputLength, BinaryXMLWireFormat::instance()); |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Add a new component, copying from value of length valueLength. |
| 36 | */ |
| 37 | void addComponent(unsigned char *value, unsigned int valueLength) { |
| 38 | components_.push_back(std::vector<unsigned char>(value, value + valueLength)); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Clear all the components. |
| 43 | */ |
| 44 | void clear() { |
| 45 | components_.clear(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the number of components. |
| 50 | * @return the number of components |
| 51 | */ |
| 52 | unsigned int getComponentCount() { |
| 53 | return components_.size(); |
| 54 | } |
| 55 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 56 | private: |
| 57 | std::vector<std::vector<unsigned char> > components_; |
| 58 | }; |
| 59 | |
| 60 | } |
| 61 | |
| 62 | #endif |
| 63 | |