blob: 04ddd08132cbe06e793f06bc69b2e531860113bb [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
Jeff Thompson8b666002013-07-08 01:16:26 -07009#include "../errors.h"
10
Jeff Thompson76317aa2013-06-25 19:11:48 -070011#ifdef __cplusplus
12extern "C" {
13#endif
14
15struct ndn_BinaryXMLStructureDecoder {
Jeff Thompson4e278992013-06-26 18:59:17 -070016 int gotElementEnd; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070017 unsigned int offset;
18 int level;
19 int state;
20 unsigned int headerLength;
Jeff Thompson4e278992013-06-26 18:59:17 -070021 int useHeaderBuffer; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070022 // 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 Thompson9dc10732013-06-26 21:40:32 -070027enum {
28 ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE,
29 ndn_BinaryXMLStructureDecoder_READ_BYTES
30};
Jeff Thompson76317aa2013-06-25 19:11:48 -070031
32void ndn_BinaryXMLStructureDecoder_init(struct ndn_BinaryXMLStructureDecoder *self);
33
Jeff Thompson9dc10732013-06-26 21:40:32 -070034/**
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.
39 * @param self pointer to the ndn_BinaryXMLStructureDecoder struct
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 Thompson8b666002013-07-08 01:16:26 -070042 * @return 0 for success, else an error code
Jeff Thompson9dc10732013-06-26 21:40:32 -070043 */
Jeff Thompson8b666002013-07-08 01:16:26 -070044ndn_Error ndn_BinaryXMLStructureDecoder_findElementEnd
Jeff Thompsond6f13282013-06-27 17:31:50 -070045 (struct ndn_BinaryXMLStructureDecoder *self, unsigned char *input, unsigned int inputLength);
Jeff Thompson9dc10732013-06-26 21:40:32 -070046
Jeff Thompson76317aa2013-06-25 19:11:48 -070047#ifdef __cplusplus
48}
49#endif
50
51#endif