Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | const char *ndn_BinaryXMLDecoder_decodeTypeAndValue(struct ndn_BinaryXMLDecoder *self, unsigned int *type, unsigned int *valueOut) { |
| 11 | unsigned int value = 0; |
| 12 | |
| 13 | while (1) { |
| 14 | if (self->offset >= self->inputLen) |
| 15 | return "ndn_BinaryXMLDecoder_decodeTypeAndVal read past the end of the input"; |
| 16 | |
| 17 | unsigned int octet = (unsigned int)(self->input[self->offset++] & 0xff); |
| 18 | |
| 19 | if (octet & ndn_BinaryXML_TT_FINAL) { |
| 20 | // Finished. |
| 21 | *type = octet & ndn_BinaryXML_TT_MASK; |
| 22 | value = (value << ndn_BinaryXML_TT_VALUE_BITS) | ((octet >> ndn_BinaryXML_TT_BITS) & ndn_BinaryXML_TT_VALUE_MASK); |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | value = (value << ndn_BinaryXML_REGULAR_VALUE_BITS) | (octet & ndn_BinaryXML_REGULAR_VALUE_MASK); |
| 27 | } |
| 28 | |
| 29 | *valueOut = value; |
| 30 | return (const char *)0; |
| 31 | } |