blob: e953a1bf51acc48e3a73072a0e1c491ffef26e18 [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 Thompson0050abe2013-09-17 12:50:25 -070033 bool
Jeff Thompson97223af2013-09-24 17:01:27 -070034 findElementEnd(uint8_t *input, size_t inputLength)
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070035 {
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070036 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070037 if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength)))
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070038 throw std::runtime_error(ndn_getErrorString(error));
Jeff Thompson71d8f772013-06-27 14:34:11 -070039 return gotElementEnd();
40 }
41
Jeff Thompson97223af2013-09-24 17:01:27 -070042 size_t
Jeff Thompson0050abe2013-09-17 12:50:25 -070043 getOffset() const { return offset; }
44
45 bool
46 gotElementEnd() const { return gotElementEnd != 0; }
Jeff Thompson76317aa2013-06-25 19:11:48 -070047};
Jeff Thompson4e278992013-06-26 18:59:17 -070048
Jeff Thompson76317aa2013-06-25 19:11:48 -070049}
50
Jeff Thompson19f01182013-07-09 19:29:36 -070051#endif