blob: 432953f7e90a56a441b32ba28f997aa56d55edea [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
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#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 Thompsonf0fea002013-07-30 17:22:42 -070015 * A BinaryXmlStructureDecoder extends a C ndn_BinaryXmlStructureDecoder struct and wraps related functions.
Jeff Thompson4e278992013-06-26 18:59:17 -070016 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070017class BinaryXmlStructureDecoder : private ndn_BinaryXmlStructureDecoder {
Jeff Thompson76317aa2013-06-25 19:11:48 -070018public:
Jeff Thompsonf0fea002013-07-30 17:22:42 -070019 BinaryXmlStructureDecoder()
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070020 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070021 ndn_BinaryXmlStructureDecoder_initialize(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 Thompson94ddc272013-08-08 14:17:38 -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