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