Jeff Thompson | 333c446 | 2013-06-28 14:04:22 -0700 | [diff] [blame] | 1 | /* |
| 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 Thompson | 1156ed1 | 2013-07-01 16:13:56 -0700 | [diff] [blame] | 11 | char *ndn_encodeBinaryXMLName(struct ndn_Name *name, struct ndn_BinaryXMLEncoder *encoder) |
| 12 | { |
| 13 | |
| 14 | } |
| 15 | |
Jeff Thompson | 333c446 | 2013-06-28 14:04:22 -0700 | [diff] [blame] | 16 | char *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 Thompson | 1156ed1 | 2013-07-01 16:13:56 -0700 | [diff] [blame] | 22 | if (error = ndn_BinaryXMLDecoder_readElementStartDTag(&decoder, ndn_BinaryXML_DTag_Name)) |
Jeff Thompson | 333c446 | 2013-06-28 14:04:22 -0700 | [diff] [blame] | 23 | 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 | } |