blob: 5798364147aa256e68fff52d4ef46f8f4b7c465d [file] [log] [blame]
Jeff Thompson76317aa2013-06-25 19:11:48 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#include "BinaryXML.h"
8#include "BinaryXMLDecoder.h"
9
Jeff Thompson82222e82013-06-26 19:32:59 -070010const char *ndn_BinaryXMLDecoder_decodeTypeAndValue(struct ndn_BinaryXMLDecoder *self, unsigned int *type, unsigned int *valueOut)
11{
Jeff Thompson76317aa2013-06-25 19:11:48 -070012 unsigned int value = 0;
13
14 while (1) {
Jeff Thompsonf7316692013-06-26 21:31:42 -070015 if (self->offset >= self->inputLength)
Jeff Thompson76317aa2013-06-25 19:11:48 -070016 return "ndn_BinaryXMLDecoder_decodeTypeAndVal read past the end of the input";
17
18 unsigned int octet = (unsigned int)(self->input[self->offset++] & 0xff);
19
20 if (octet & ndn_BinaryXML_TT_FINAL) {
21 // Finished.
22 *type = octet & ndn_BinaryXML_TT_MASK;
23 value = (value << ndn_BinaryXML_TT_VALUE_BITS) | ((octet >> ndn_BinaryXML_TT_BITS) & ndn_BinaryXML_TT_VALUE_MASK);
24 break;
25 }
26
27 value = (value << ndn_BinaryXML_REGULAR_VALUE_BITS) | (octet & ndn_BinaryXML_REGULAR_VALUE_MASK);
28 }
29
30 *valueOut = value;
31 return (const char *)0;
32}