blob: dbe59323e663b86b6f6f6e1c88dfa5361f4e9dcc [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
Jeff Thompson19f01182013-07-09 19:29:36 -07007#ifndef NDN_BINARYXMLSTRUCTUREDECODER_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_BINARYXMLSTRUCTUREDECODER_HPP
Jeff Thompson76317aa2013-06-25 19:11:48 -07009
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 Thompsonf0fea002013-07-30 17:22:42 -070016 * A BinaryXmlStructureDecoder extends a C ndn_BinaryXmlStructureDecoder struct and wraps related functions.
Jeff Thompson4e278992013-06-26 18:59:17 -070017 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070018class BinaryXmlStructureDecoder : private ndn_BinaryXmlStructureDecoder {
Jeff Thompson76317aa2013-06-25 19:11:48 -070019public:
Jeff Thompsonf0fea002013-07-30 17:22:42 -070020 BinaryXmlStructureDecoder()
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070021 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070022 ndn_BinaryXmlStructureDecoder_initialize(this);
Jeff Thompson76317aa2013-06-25 19:11:48 -070023 }
24
Jeff Thompson71d8f772013-06-27 14:34:11 -070025 /**
26 * Continue scanning input starting from getOffset() to find the element end.
27 * If the end of the element which started at offset 0 is found, then return true and getOffset() is the length of
28 * the element. Otherwise return false, which means you should read more into input and call again.
29 * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
30 * @param inputLength the number of bytes in input.
31 * @return true if found the element end, false if need to read more. (This is the same as returning gotElementEnd().)
32 */
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070033 bool findElementEnd(unsigned char *input, unsigned int inputLength)
34 {
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070035 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070036 if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength)))
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070037 throw std::runtime_error(ndn_getErrorString(error));
Jeff Thompson71d8f772013-06-27 14:34:11 -070038 return gotElementEnd();
39 }
40
Jeff Thompsonc125a162013-07-15 16:32:32 -070041 unsigned int getOffset() const { return offset; }
42 bool gotElementEnd() const { return gotElementEnd != 0; }
Jeff Thompson76317aa2013-06-25 19:11:48 -070043};
Jeff Thompson4e278992013-06-26 18:59:17 -070044
Jeff Thompson76317aa2013-06-25 19:11:48 -070045}
46
Jeff Thompson19f01182013-07-09 19:29:36 -070047#endif