Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #ifndef NDN_BINARYXMLDECODER_HPP |
| 7 | #define NDN_BINARYXMLDECODER_HPP |
| 8 | |
Jeff Thompson | a33913f | 2013-07-15 17:23:55 -0700 | [diff] [blame^] | 9 | #include <stdexcept> |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 10 | #include "../c/errors.h" |
| 11 | #include "../c/encoding/BinaryXMLDecoder.h" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * A BinaryXMLDecoder extends a C ndn_BinaryXMLDecoder struct and wraps related functions. |
| 18 | */ |
| 19 | class BinaryXMLDecoder : public ndn_BinaryXMLDecoder { |
| 20 | public: |
| 21 | /** |
| 22 | * Initialize the base ndn_BinaryXMLDecoder struct with the input. |
| 23 | */ |
| 24 | BinaryXMLDecoder(const unsigned char *input, unsigned int inputLength) |
| 25 | { |
| 26 | ndn_BinaryXMLDecoder_init(this, (unsigned char *)input, inputLength); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag, |
| 31 | * then return true, else false. Do not update offset, including if throwing an exception. |
| 32 | * @param expectedTag the expected value for DTAG |
| 33 | * @return true if got the expected tag, else false |
| 34 | */ |
| 35 | bool peekDTag(unsigned int expectedTag) |
| 36 | { |
| 37 | int gotExpectedTag; |
| 38 | ndn_Error error; |
| 39 | if (error = ndn_BinaryXMLDecoder_peekDTag(this, expectedTag, &gotExpectedTag)) |
| 40 | throw std::runtime_error(ndn_getErrorString(error)); |
| 41 | |
| 42 | return gotExpectedTag; |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | #endif |