blob: 82c28b3ddfd3f927b2d77c9e722f24c27e0d8444 [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
Jeff Thompson19f01182013-07-09 19:29:36 -07006#ifndef NDN_BINARYXMLSTRUCTUREDECODER_HPP
7#define NDN_BINARYXMLSTRUCTUREDECODER_HPP
Jeff Thompson76317aa2013-06-25 19:11:48 -07008
Jeff Thompson71d8f772013-06-27 14:34:11 -07009#include <stdexcept>
Jeff Thompson58b732c2013-07-01 16:51:36 -070010#include "../c/encoding/BinaryXMLStructureDecoder.h"
Jeff Thompson76317aa2013-06-25 19:11:48 -070011
12namespace ndn {
Jeff Thompson4e278992013-06-26 18:59:17 -070013
14/**
Jeff Thompsonc125a162013-07-15 16:32:32 -070015 * A BinaryXMLStructureDecoder extends a C ndn_BinaryXMLStructureDecoder struct and wraps related functions.
Jeff Thompson4e278992013-06-26 18:59:17 -070016 */
Jeff Thompsonc125a162013-07-15 16:32:32 -070017class BinaryXMLStructureDecoder : private ndn_BinaryXMLStructureDecoder {
Jeff Thompson76317aa2013-06-25 19:11:48 -070018public:
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070019 BinaryXMLStructureDecoder()
20 {
Jeff Thompsonc125a162013-07-15 16:32:32 -070021 ndn_BinaryXMLStructureDecoder_init(this);
Jeff Thompson76317aa2013-06-25 19:11:48 -070022 }
23
Jeff Thompson71d8f772013-06-27 14:34:11 -070024 /**
25 * Continue scanning input starting from getOffset() to find the element end.
26 * If the end of the element which started at offset 0 is found, then return true and getOffset() is the length of
27 * the element. Otherwise return false, which means you should read more into input and call again.
28 * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
29 * @param inputLength the number of bytes in input.
30 * @return true if found the element end, false if need to read more. (This is the same as returning gotElementEnd().)
31 */
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070032 bool findElementEnd(unsigned char *input, unsigned int inputLength)
33 {
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070034 ndn_Error error;
Jeff Thompsonc125a162013-07-15 16:32:32 -070035 if (error = ndn_BinaryXMLStructureDecoder_findElementEnd(this, input, inputLength))
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070036 throw std::runtime_error(ndn_getErrorString(error));
Jeff Thompson71d8f772013-06-27 14:34:11 -070037 return gotElementEnd();
38 }
39
Jeff Thompsonc125a162013-07-15 16:32:32 -070040 unsigned int getOffset() const { return offset; }
41 bool gotElementEnd() const { return gotElementEnd != 0; }
Jeff Thompson76317aa2013-06-25 19:11:48 -070042};
Jeff Thompson4e278992013-06-26 18:59:17 -070043
Jeff Thompson76317aa2013-06-25 19:11:48 -070044}
45
Jeff Thompson19f01182013-07-09 19:29:36 -070046#endif