blob: 603cae30d3bc6447ba957d144284129596ae72d2 [file] [log] [blame]
Jeff Thompson333c4462013-06-28 14:04:22 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#include "BinaryXMLDecoder.h"
8#include "BinaryXML.h"
9#include "BinaryXMLName.h"
10
Jeff Thompson1156ed12013-07-01 16:13:56 -070011char *ndn_encodeBinaryXMLName(struct ndn_Name *name, struct ndn_BinaryXMLEncoder *encoder)
12{
13
14}
15
Jeff Thompson333c4462013-06-28 14:04:22 -070016char *ndn_decodeBinaryXMLName(struct ndn_Name *name, unsigned char *input, unsigned int inputLength)
17{
18 struct ndn_BinaryXMLDecoder decoder;
19 ndn_BinaryXMLDecoder_init(&decoder, input, inputLength);
20
21 char *error;
Jeff Thompson1156ed12013-07-01 16:13:56 -070022 if (error = ndn_BinaryXMLDecoder_readElementStartDTag(&decoder, ndn_BinaryXML_DTag_Name))
Jeff Thompson333c4462013-06-28 14:04:22 -070023 return error;
24
25 while (1) {
26 int gotExpectedTag;
27 if (error = ndn_BinaryXMLDecoder_peekDTag(&decoder, ndn_BinaryXML_DTag_Component, &gotExpectedTag))
28 return error;
29
30 if (!gotExpectedTag)
31 // No more components.
32 break;
33
34 unsigned char *component;
35 unsigned int componentLen;
36 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement(&decoder, ndn_BinaryXML_DTag_Component, 0, &component, &componentLen))
37 return error;
38
39 // Add the component to the name.
40 if (name->nComponents >= name->maxComponents)
41 return "ndn_decodeBinaryXMLName: read a component past the maximum number of components allowed in the name";
42 ndn_NameComponent_init(name->components + name->nComponents, component, componentLen);
43 ++name->nComponents;
44 }
45
46 if (error = ndn_BinaryXMLDecoder_readElementClose(&decoder))
47 return error;
48
49 return 0;
50}