blob: 54c8648404279df7cf0e9be1d6c22821a96e5d8b [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
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_BINARYXMLSTRUCTUREDECODER_H
Jeff Thompson76317aa2013-06-25 19:11:48 -07008
Jeff Thompson8b666002013-07-08 01:16:26 -07009#include "../errors.h"
10
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070011#ifdef __cplusplus
Jeff Thompson76317aa2013-06-25 19:11:48 -070012extern "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 Thompson2d27e2f2013-08-09 12:55:00 -070057#ifdef __cplusplus
Jeff Thompson76317aa2013-06-25 19:11:48 -070058}
59#endif
60
61#endif