blob: b4537944b925c27999a606f44cec8aae165224c5 [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>
Jeff Thompson6cb56f92013-07-01 15:38:09 -07008#include "../c/encoding/BinaryXMLName.h"
Jeff Thompson4c89ad62013-06-28 12:50:13 -07009#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}