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