blob: 99556f66c00728c367d64f8a7b5688715c8dc5e2 [file] [log] [blame]
Jeff Thompson76317aa2013-06-25 19:11:48 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef BINARYXMLSTRUCTUREDECODER_HPP
8#define BINARYXMLSTRUCTUREDECODER_HPP
9
Jeff Thompson71d8f772013-06-27 14:34:11 -070010#include <stdexcept>
Jeff Thompson58b732c2013-07-01 16:51:36 -070011#include "../c/encoding/BinaryXMLStructureDecoder.h"
Jeff Thompson76317aa2013-06-25 19:11:48 -070012
13namespace ndn {
Jeff Thompson4e278992013-06-26 18:59:17 -070014
15/**
Jeff Thompson6bd3a2f2013-07-01 17:17:17 -070016 * A BinaryXMLStructureDecoder wraps a C ndn_BinaryXMLStructureDecoder struct and related functions.
Jeff Thompson4e278992013-06-26 18:59:17 -070017 */
Jeff Thompson76317aa2013-06-25 19:11:48 -070018class BinaryXMLStructureDecoder {
19public:
20 BinaryXMLStructureDecoder() {
Jeff Thompson71d8f772013-06-27 14:34:11 -070021 ndn_BinaryXMLStructureDecoder_init(&base_);
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 Thompsond6f13282013-06-27 17:31:50 -070032 bool findElementEnd(unsigned char *input, unsigned int inputLength) {
33 char *error;
Jeff Thompson71d8f772013-06-27 14:34:11 -070034 if (error = ndn_BinaryXMLStructureDecoder_findElementEnd(&base_, input, inputLength))
35 throw std::runtime_error(error);
36 return gotElementEnd();
37 }
38
Jeff Thompson6bd3a2f2013-07-01 17:17:17 -070039 unsigned int getOffset() { return base_._offset; }
Jeff Thompson71d8f772013-06-27 14:34:11 -070040 bool gotElementEnd() { return base_.gotElementEnd != 0; }
41
Jeff Thompson76317aa2013-06-25 19:11:48 -070042private:
Jeff Thompson71d8f772013-06-27 14:34:11 -070043 struct ndn_BinaryXMLStructureDecoder base_;
Jeff Thompson76317aa2013-06-25 19:11:48 -070044};
Jeff Thompson4e278992013-06-26 18:59:17 -070045
Jeff Thompson76317aa2013-06-25 19:11:48 -070046}
47
48#endif /* BINARYXMLSTRUCTUREDECODER_HPP */
49