Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef NDN_BINARYXMLSTRUCTUREDECODER_H |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_BINARYXMLSTRUCTUREDECODER_H |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 10 | #include "../errors.h" |
| 11 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 12 | #ifdef __cplusplus |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 13 | extern "C" { |
| 14 | #endif |
| 15 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 16 | struct ndn_BinaryXmlStructureDecoder { |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 17 | int gotElementEnd; /**< boolean */ |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 18 | unsigned int offset; |
| 19 | int level; |
| 20 | int state; |
| 21 | unsigned int headerLength; |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 22 | int useHeaderBuffer; /**< boolean */ |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 23 | // 10 bytes is enough to hold an encoded header with a type and a 64 bit value. |
| 24 | unsigned char headerBuffer[10]; |
| 25 | int nBytesToRead; |
| 26 | }; |
| 27 | |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 28 | enum { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 29 | ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE, |
| 30 | ndn_BinaryXmlStructureDecoder_READ_BYTES |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 31 | }; |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 32 | |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 33 | void ndn_BinaryXmlStructureDecoder_initialize(struct ndn_BinaryXmlStructureDecoder *self); |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 34 | |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Continue scanning input starting from self->offset to find the element end. On return, you must check |
| 37 | * self->gotElementEnd: If the end of the element which started at offset 0 is found, |
| 38 | * then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0 |
| 39 | * which means you should read more into input and call again. |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 40 | * @param self pointer to the ndn_BinaryXmlStructureDecoder struct |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 41 | * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated. |
| 42 | * @param inputLength the number of bytes in input. |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 43 | * @return 0 for success, else an error code |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 44 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 45 | ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd |
| 46 | (struct ndn_BinaryXmlStructureDecoder *self, unsigned char *input, unsigned int inputLength); |
Jeff Thompson | 9dc1073 | 2013-06-26 21:40:32 -0700 | [diff] [blame] | 47 | |
Jeff Thompson | fc53bc5 | 2013-07-14 23:25:23 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Set the offset into the input, used for the next read. |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 50 | * @param self pointer to the ndn_BinaryXmlStructureDecoder struct |
Jeff Thompson | fc53bc5 | 2013-07-14 23:25:23 -0700 | [diff] [blame] | 51 | * @param offset the new offset |
| 52 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 53 | 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] | 54 | { |
| 55 | self->offset = offset; |
| 56 | } |
| 57 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 58 | #ifdef __cplusplus |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 59 | } |
| 60 | #endif |
| 61 | |
| 62 | #endif |