blob: 58a595fcb68bf95b26459abb083af6ff930bd0c4 [file] [log] [blame]
Jeff Thompson76317aa2013-06-25 19:11:48 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
8#define NDN_BINARYXMLSTRUCTUREDECODER_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14struct ndn_BinaryXMLStructureDecoder {
Jeff Thompson4e278992013-06-26 18:59:17 -070015 int gotElementEnd; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070016 unsigned int offset;
17 int level;
18 int state;
19 unsigned int headerLength;
Jeff Thompson4e278992013-06-26 18:59:17 -070020 int useHeaderBuffer; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070021 // 10 bytes is enough to hold an encoded header with a type and a 64 bit value.
22 unsigned char headerBuffer[10];
23 int nBytesToRead;
24};
25
Jeff Thompson9dc10732013-06-26 21:40:32 -070026enum {
27 ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE,
28 ndn_BinaryXMLStructureDecoder_READ_BYTES
29};
Jeff Thompson76317aa2013-06-25 19:11:48 -070030
31void ndn_BinaryXMLStructureDecoder_init(struct ndn_BinaryXMLStructureDecoder *self);
32
Jeff Thompson9dc10732013-06-26 21:40:32 -070033/**
34 * Continue scanning input starting from self->offset to find the element end. On return, you must check
35 * self->gotElementEnd: If the end of the element which started at offset 0 is found,
36 * then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0
37 * which means you should read more into input and call again.
38 * @param self pointer to the ndn_BinaryXMLStructureDecoder struct
39 * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
40 * @param inputLength the number of bytes in input.
41 * @return 0 for success, else an error string
42 */
43const char *ndn_BinaryXMLStructureDecoder_findElementEnd
44 (struct ndn_BinaryXMLStructureDecoder *self, const unsigned char *input, unsigned int inputLength);
45
Jeff Thompson76317aa2013-06-25 19:11:48 -070046#ifdef __cplusplus
47}
48#endif
49
50#endif