Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 1 | /* |
| 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 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 | 6bd3a2f | 2013-07-01 17:17:17 -0700 | [diff] [blame] | 16 | * A BinaryXMLStructureDecoder wraps a C ndn_BinaryXMLStructureDecoder struct and related functions. |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 17 | */ |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 18 | class BinaryXMLStructureDecoder { |
| 19 | public: |
| 20 | BinaryXMLStructureDecoder() { |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 21 | ndn_BinaryXMLStructureDecoder_init(&base_); |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 24 | /** |
| 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 Thompson | d6f1328 | 2013-06-27 17:31:50 -0700 | [diff] [blame] | 32 | bool findElementEnd(unsigned char *input, unsigned int inputLength) { |
| 33 | char *error; |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 34 | if (error = ndn_BinaryXMLStructureDecoder_findElementEnd(&base_, input, inputLength)) |
| 35 | throw std::runtime_error(error); |
| 36 | return gotElementEnd(); |
| 37 | } |
| 38 | |
Jeff Thompson | 6bd3a2f | 2013-07-01 17:17:17 -0700 | [diff] [blame] | 39 | unsigned int getOffset() { return base_._offset; } |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 40 | bool gotElementEnd() { return base_.gotElementEnd != 0; } |
| 41 | |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 42 | private: |
Jeff Thompson | 71d8f77 | 2013-06-27 14:34:11 -0700 | [diff] [blame] | 43 | struct ndn_BinaryXMLStructureDecoder base_; |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 44 | }; |
Jeff Thompson | 4e27899 | 2013-06-26 18:59:17 -0700 | [diff] [blame] | 45 | |
Jeff Thompson | 76317aa | 2013-06-25 19:11:48 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | #endif /* BINARYXMLSTRUCTUREDECODER_HPP */ |
| 49 | |