blob: e7715225e8e7a9b332ea1d716a048566e8d1d5cf [file] [log] [blame]
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
Jeff Thompson4c89ad62013-06-28 12:50:13 -07007#include <stdexcept>
8#include "BinaryXMLName.h"
9#include "../Name.hpp"
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070010#include "BinaryXMLWireFormat.hpp"
Jeff Thompson4c89ad62013-06-28 12:50:13 -070011
12namespace ndn {
13
14BinaryXMLWireFormat BinaryXMLWireFormat::instance_;
15
16void 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}