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 | |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 7 | #include <stdexcept> |
Jeff Thompson | 6cb56f9 | 2013-07-01 15:38:09 -0700 | [diff] [blame] | 8 | #include "../c/encoding/BinaryXMLName.h" |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 9 | #include "../Name.hpp" |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 10 | #include "BinaryXMLWireFormat.hpp" |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 11 | |
| 12 | namespace ndn { |
| 13 | |
| 14 | BinaryXMLWireFormat BinaryXMLWireFormat::instance_; |
| 15 | |
| 16 | void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, unsigned int inputLength) |
| 17 | { |
| 18 | struct ndn_NameComponent components[100]; |
| 19 | struct ndn_Name nameStruct; |
| 20 | ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0])); |
| 21 | |
| 22 | char *error; |
| 23 | if (error = ndn_decodeBinaryXMLName(&nameStruct, (unsigned char *)input, inputLength)) |
| 24 | throw std::runtime_error(error); |
| 25 | |
| 26 | name.clear(); |
| 27 | for (int i = 0; i < nameStruct.nComponents; ++i) |
| 28 | name.addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength); |
| 29 | } |
| 30 | |
| 31 | } |