Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Jeff Thompson | 19f0118 | 2013-07-09 19:29:36 -0700 | [diff] [blame] | 7 | #ifndef NDN_BINARYXMLSTRUCTUREDECODER_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_BINARYXMLSTRUCTUREDECODER_HPP |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 10 | #include <stdexcept> |
Jeff Thompson | 58b732c | 2013-07-01 16:51:36 -0700 | [diff] [blame] | 11 | #include "../c/encoding/BinaryXMLStructureDecoder.h" |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 16 | * A BinaryXmlStructureDecoder extends a C ndn_BinaryXmlStructureDecoder struct and wraps related functions. |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 17 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 18 | class BinaryXmlStructureDecoder : private ndn_BinaryXmlStructureDecoder { |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 19 | public: |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 20 | BinaryXmlStructureDecoder() |
Jeff Thompson | ffbe8ac | 2013-07-02 11:43:09 -0700 | [diff] [blame] | 21 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 22 | ndn_BinaryXmlStructureDecoder_initialize(this); |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 25 | /** |
| 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 Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 33 | bool |
| 34 | findElementEnd(unsigned char *input, unsigned int inputLength) |
Jeff Thompson | ffbe8ac | 2013-07-02 11:43:09 -0700 | [diff] [blame] | 35 | { |
Jeff Thompson | b0e4fad | 2013-07-08 01:16:48 -0700 | [diff] [blame] | 36 | ndn_Error error; |
Jeff Thompson | 94ddc27 | 2013-08-08 14:17:38 -0700 | [diff] [blame] | 37 | if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength))) |
Jeff Thompson | b0e4fad | 2013-07-08 01:16:48 -0700 | [diff] [blame] | 38 | throw std::runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 39 | return gotElementEnd(); |
| 40 | } |
| 41 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 42 | unsigned int |
| 43 | getOffset() const { return offset; } |
| 44 | |
| 45 | bool |
| 46 | gotElementEnd() const { return gotElementEnd != 0; } |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 47 | }; |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Jeff Thompson | 19f0118 | 2013-07-09 19:29:36 -0700 | [diff] [blame] | 51 | #endif |