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 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 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 { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 28 | ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE, |
| 29 | ndn_BinaryXmlStructureDecoder_READ_BYTES |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 30 | }; |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 31 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 32 | void ndn_BinaryXmlStructureDecoder_init(struct ndn_BinaryXmlStructureDecoder *self); |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 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. |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 39 | * @param self pointer to the ndn_BinaryXmlStructureDecoder struct |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 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 | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 44 | ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd |
| 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 | fc53bc5 | 2013-07-14 23:25:23 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Set the offset into the input, used for the next read. |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 49 | * @param self pointer to the ndn_BinaryXmlStructureDecoder struct |
Jeff Thompson | fc53bc5 | 2013-07-14 23:25:23 -0700 | [diff] [blame] | 50 | * @param offset the new offset |
| 51 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 52 | static inline void ndn_BinaryXmlStructureDecoder_seek(struct ndn_BinaryXmlStructureDecoder *self, unsigned int offset) |
Jeff Thompson | fc53bc5 | 2013-07-14 23:25:23 -0700 | [diff] [blame] | 53 | { |
| 54 | self->offset = offset; |
| 55 | } |
| 56 | |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 57 | #ifdef __cplusplus |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | #endif |