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 | #ifndef NDN_BINARYXMLSTRUCTUREDECODER_H |
| 8 | #define NDN_BINARYXMLSTRUCTUREDECODER_H |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | struct ndn_BinaryXMLStructureDecoder { |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 15 | int gotElementEnd; /**< boolean */ |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 16 | unsigned int offset; |
| 17 | int level; |
| 18 | int state; |
| 19 | unsigned int headerLength; |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 20 | int useHeaderBuffer; /**< boolean */ |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 21 | // 10 bytes is enough to hold an encoded header with a type and a 64 bit value. |
| 22 | unsigned char headerBuffer[10]; |
| 23 | int nBytesToRead; |
| 24 | }; |
| 25 | |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame^] | 26 | enum { |
| 27 | ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE, |
| 28 | ndn_BinaryXMLStructureDecoder_READ_BYTES |
| 29 | }; |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 30 | |
| 31 | void ndn_BinaryXMLStructureDecoder_init(struct ndn_BinaryXMLStructureDecoder *self); |
| 32 | |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame^] | 33 | /** |
| 34 | * Continue scanning input starting from self->offset to find the element end. On return, you must check |
| 35 | * self->gotElementEnd: If the end of the element which started at offset 0 is found, |
| 36 | * then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0 |
| 37 | * which means you should read more into input and call again. |
| 38 | * @param self pointer to the ndn_BinaryXMLStructureDecoder struct |
| 39 | * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated. |
| 40 | * @param inputLength the number of bytes in input. |
| 41 | * @return 0 for success, else an error string |
| 42 | */ |
| 43 | const char *ndn_BinaryXMLStructureDecoder_findElementEnd |
| 44 | (struct ndn_BinaryXMLStructureDecoder *self, const unsigned char *input, unsigned int inputLength); |
| 45 | |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 46 | #ifdef __cplusplus |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | #endif |