blob: 8c561a1881ef3a7f3426ae0be2e0c2422409d5b9 [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
Jeff Thompsonf0fea002013-07-30 17:22:42 -070015struct 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 {
Jeff Thompsonf0fea002013-07-30 17:22:42 -070028 ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE,
29 ndn_BinaryXmlStructureDecoder_READ_BYTES
Jeff Thompson9dc10732013-06-26 21:40:32 -070030};
Jeff Thompson76317aa2013-06-25 19:11:48 -070031
Jeff Thompsonf0fea002013-07-30 17:22:42 -070032void ndn_BinaryXmlStructureDecoder_init(struct ndn_BinaryXmlStructureDecoder *self);
Jeff Thompson76317aa2013-06-25 19:11:48 -070033
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.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070039 * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
Jeff Thompson9dc10732013-06-26 21:40:32 -070040 * @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 Thompsonf0fea002013-07-30 17:22:42 -070044ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd
45 (struct ndn_BinaryXmlStructureDecoder *self, unsigned char *input, unsigned int inputLength);
Jeff Thompson9dc10732013-06-26 21:40:32 -070046
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070047/**
48 * Set the offset into the input, used for the next read.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070049 * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070050 * @param offset the new offset
51 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070052static inline void ndn_BinaryXmlStructureDecoder_seek(struct ndn_BinaryXmlStructureDecoder *self, unsigned int offset)
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070053{
54 self->offset = offset;
55}
56
Jeff Thompson76317aa2013-06-25 19:11:48 -070057#ifdef __cplusplus
58}
59#endif
60
61#endif