blob: 603ee43387310a20c9e4ee1f9bf33913275336ee [file] [log] [blame]
/**
* @author: Jeff Thompson
* See COPYING for copyright and distribution information.
*/
#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
#define NDN_BINARYXMLSTRUCTUREDECODER_H
#include "../errors.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ndn_BinaryXMLStructureDecoder {
int gotElementEnd; /**< boolean */
unsigned int offset;
int level;
int state;
unsigned int headerLength;
int useHeaderBuffer; /**< boolean */
// 10 bytes is enough to hold an encoded header with a type and a 64 bit value.
unsigned char headerBuffer[10];
int nBytesToRead;
};
enum {
ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE,
ndn_BinaryXMLStructureDecoder_READ_BYTES
};
void ndn_BinaryXMLStructureDecoder_init(struct ndn_BinaryXMLStructureDecoder *self);
/**
* Continue scanning input starting from self->offset to find the element end. On return, you must check
* self->gotElementEnd: If the end of the element which started at offset 0 is found,
* then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0
* which means you should read more into input and call again.
* @param self pointer to the ndn_BinaryXMLStructureDecoder struct
* @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
* @param inputLength the number of bytes in input.
* @return 0 for success, else an error code
*/
ndn_Error ndn_BinaryXMLStructureDecoder_findElementEnd
(struct ndn_BinaryXMLStructureDecoder *self, unsigned char *input, unsigned int inputLength);
/**
* Set the offset into the input, used for the next read.
* @param self pointer to the ndn_BinaryXMLStructureDecoder struct
* @param offset the new offset
*/
static inline void ndn_BinaryXMLStructureDecoder_seek(struct ndn_BinaryXMLStructureDecoder *self, unsigned int offset)
{
self->offset = offset;
}
#ifdef __cplusplus
}
#endif
#endif