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