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 | |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 14 | extern "C" { struct ndn_Name; } |
| 15 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 16 | namespace ndn { |
| 17 | |
| 18 | class Name { |
| 19 | public: |
| 20 | Name(); |
| 21 | Name(const char *uri); |
| 22 | |
| 23 | void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) { |
| 24 | wireFormat.encodeName(*this, output); |
| 25 | } |
| 26 | void encode(std::vector<unsigned char> &output) { |
| 27 | encode(output, BinaryXMLWireFormat::instance()); |
| 28 | } |
Jeff Thompson | 4238071 | 2013-06-28 10:59:33 -0700 | [diff] [blame] | 29 | void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) { |
| 30 | wireFormat.decodeName(*this, input, inputLength); |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 31 | } |
Jeff Thompson | 4238071 | 2013-06-28 10:59:33 -0700 | [diff] [blame] | 32 | void decode(const unsigned char *input, unsigned int inputLength) { |
| 33 | decode(input, inputLength, BinaryXMLWireFormat::instance()); |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 36 | /** |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 37 | * Clear the name, and set the components by copying from the name struct. |
| 38 | * @param name a C ndn_Name struct |
| 39 | */ |
| 40 | void set(struct ndn_Name &nameStruct); |
| 41 | |
| 42 | /** |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 43 | * Add a new component, copying from value of length valueLength. |
| 44 | */ |
| 45 | void addComponent(unsigned char *value, unsigned int valueLength) { |
| 46 | components_.push_back(std::vector<unsigned char>(value, value + valueLength)); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Clear all the components. |
| 51 | */ |
| 52 | void clear() { |
| 53 | components_.clear(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the number of components. |
| 58 | * @return the number of components |
| 59 | */ |
| 60 | unsigned int getComponentCount() { |
| 61 | return components_.size(); |
| 62 | } |
| 63 | |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Encode this name as a URI. |
| 66 | * @return the encoded URI. |
| 67 | */ |
| 68 | std::string to_uri(); |
| 69 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 70 | private: |
| 71 | std::vector<std::vector<unsigned char> > components_; |
| 72 | }; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | #endif |
| 77 | |