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