blob: e58471ede99163df162650bcac8d7539394e1623 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompson76317aa2013-06-25 19:11:48 -07005 */
6
7#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_BINARYXMLSTRUCTUREDECODER_H
Jeff Thompson76317aa2013-06-25 19:11:48 -07009
Jeff Thompson8b666002013-07-08 01:16:26 -070010#include "../errors.h"
11
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompson76317aa2013-06-25 19:11:48 -070013extern "C" {
14#endif
15
Jeff Thompsonf0fea002013-07-30 17:22:42 -070016struct ndn_BinaryXmlStructureDecoder {
Jeff Thompson4e278992013-06-26 18:59:17 -070017 int gotElementEnd; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070018 unsigned int offset;
19 int level;
20 int state;
21 unsigned int headerLength;
Jeff Thompson4e278992013-06-26 18:59:17 -070022 int useHeaderBuffer; /**< boolean */
Jeff Thompson76317aa2013-06-25 19:11:48 -070023 // 10 bytes is enough to hold an encoded header with a type and a 64 bit value.
24 unsigned char headerBuffer[10];
25 int nBytesToRead;
26};
27
Jeff Thompson9dc10732013-06-26 21:40:32 -070028enum {
Jeff Thompsonf0fea002013-07-30 17:22:42 -070029 ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE,
30 ndn_BinaryXmlStructureDecoder_READ_BYTES
Jeff Thompson9dc10732013-06-26 21:40:32 -070031};
Jeff Thompson76317aa2013-06-25 19:11:48 -070032
Jeff Thompsond1427fb2013-08-29 17:20:32 -070033void ndn_BinaryXmlStructureDecoder_initialize(struct ndn_BinaryXmlStructureDecoder *self);
Jeff Thompson76317aa2013-06-25 19:11:48 -070034
Jeff Thompson9dc10732013-06-26 21:40:32 -070035/**
36 * Continue scanning input starting from self->offset to find the element end. On return, you must check
37 * self->gotElementEnd: If the end of the element which started at offset 0 is found,
38 * then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0
39 * which means you should read more into input and call again.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070040 * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
Jeff Thompson9dc10732013-06-26 21:40:32 -070041 * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
42 * @param inputLength the number of bytes in input.
Jeff Thompson8b666002013-07-08 01:16:26 -070043 * @return 0 for success, else an error code
Jeff Thompson9dc10732013-06-26 21:40:32 -070044 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070045ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd
46 (struct ndn_BinaryXmlStructureDecoder *self, unsigned char *input, unsigned int inputLength);
Jeff Thompson9dc10732013-06-26 21:40:32 -070047
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070048/**
49 * Set the offset into the input, used for the next read.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070050 * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070051 * @param offset the new offset
52 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070053static inline void ndn_BinaryXmlStructureDecoder_seek(struct ndn_BinaryXmlStructureDecoder *self, unsigned int offset)
Jeff Thompsonfc53bc52013-07-14 23:25:23 -070054{
55 self->offset = offset;
56}
57
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070058#ifdef __cplusplus
Jeff Thompson76317aa2013-06-25 19:11:48 -070059}
60#endif
61
62#endif