blob: 9ffd72b6a072dcdb23c547c59538a197e6df70a5 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07005 * See COPYING for copyright and distribution information.
Jeff Thompson76317aa2013-06-25 19:11:48 -07006 */
7
Jeff Thompson19f01182013-07-09 19:29:36 -07008#ifndef NDN_BINARYXMLSTRUCTUREDECODER_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07009#define NDN_BINARYXMLSTRUCTUREDECODER_HPP
Jeff Thompson76317aa2013-06-25 19:11:48 -070010
Jeff Thompson71d8f772013-06-27 14:34:11 -070011#include <stdexcept>
Jeff Thompson58b732c2013-07-01 16:51:36 -070012#include "../c/encoding/BinaryXMLStructureDecoder.h"
Jeff Thompson76317aa2013-06-25 19:11:48 -070013
14namespace ndn {
Jeff Thompson4e278992013-06-26 18:59:17 -070015
16/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070017 * A BinaryXmlStructureDecoder extends a C ndn_BinaryXmlStructureDecoder struct and wraps related functions.
Jeff Thompson4e278992013-06-26 18:59:17 -070018 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070019class BinaryXmlStructureDecoder : private ndn_BinaryXmlStructureDecoder {
Jeff Thompson76317aa2013-06-25 19:11:48 -070020public:
Jeff Thompsonf0fea002013-07-30 17:22:42 -070021 BinaryXmlStructureDecoder()
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070022 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070023 ndn_BinaryXmlStructureDecoder_initialize(this);
Jeff Thompson76317aa2013-06-25 19:11:48 -070024 }
25
Jeff Thompson71d8f772013-06-27 14:34:11 -070026 /**
27 * Continue scanning input starting from getOffset() to find the element end.
28 * If the end of the element which started at offset 0 is found, then return true and getOffset() is the length of
29 * the element. Otherwise return false, which means you should read more into input and call again.
30 * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
31 * @param inputLength the number of bytes in input.
32 * @return true if found the element end, false if need to read more. (This is the same as returning gotElementEnd().)
33 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070034 bool
Jeff Thompson97223af2013-09-24 17:01:27 -070035 findElementEnd(uint8_t *input, size_t inputLength)
Jeff Thompsonffbe8ac2013-07-02 11:43:09 -070036 {
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070037 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070038 if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength)))
Jeff Thompsonb0e4fad2013-07-08 01:16:48 -070039 throw std::runtime_error(ndn_getErrorString(error));
Jeff Thompson71d8f772013-06-27 14:34:11 -070040 return gotElementEnd();
41 }
42
Jeff Thompson97223af2013-09-24 17:01:27 -070043 size_t
Jeff Thompson0050abe2013-09-17 12:50:25 -070044 getOffset() const { return offset; }
45
46 bool
47 gotElementEnd() const { return gotElementEnd != 0; }
Jeff Thompson76317aa2013-06-25 19:11:48 -070048};
Jeff Thompson4e278992013-06-26 18:59:17 -070049
Jeff Thompson76317aa2013-06-25 19:11:48 -070050}
51
Jeff Thompson19f01182013-07-09 19:29:36 -070052#endif