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