blob: e56673bdd40b6a487fb6ff2ac2b084032f5ff791 [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 Thompson1f3f5172013-07-01 19:02:36 -070010#include "BinaryXMLEncoder.hpp"
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070011#include "BinaryXMLWireFormat.hpp"
Jeff Thompson4c89ad62013-06-28 12:50:13 -070012
Jeff Thompson1f3f5172013-07-01 19:02:36 -070013using namespace std;
14
Jeff Thompson4c89ad62013-06-28 12:50:13 -070015namespace ndn {
16
17BinaryXMLWireFormat BinaryXMLWireFormat::instance_;
18
Jeff Thompson1f3f5172013-07-01 19:02:36 -070019void BinaryXMLWireFormat::encodeName(Name &name, vector<unsigned char> &output)
20{
21 struct ndn_Name nameStruct;
22 struct ndn_NameComponent components[100];
23 ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
24 name.get(nameStruct);
25
26 BinaryXMLEncoder encoder;
27 ndn_encodeBinaryXMLName(&nameStruct, encoder.getEncoder());
Jeff Thompson58d798f2013-07-02 14:16:25 -070028
29 encoder.appendTo(output);
Jeff Thompson1f3f5172013-07-01 19:02:36 -070030}
31
Jeff Thompson4c89ad62013-06-28 12:50:13 -070032void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, unsigned int inputLength)
33{
34 struct ndn_NameComponent components[100];
35 struct ndn_Name nameStruct;
36 ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
37
38 char *error;
39 if (error = ndn_decodeBinaryXMLName(&nameStruct, (unsigned char *)input, inputLength))
40 throw std::runtime_error(error);
Jeff Thompson1f3f5172013-07-01 19:02:36 -070041
42 name.set(nameStruct);
Jeff Thompson4c89ad62013-06-28 12:50:13 -070043}
44
45}