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 |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame^] | 7 | #define NDN_BINARYXMLDECODER_HPP |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 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" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 11 | #include "../c/encoding/binary-xml-decoder.h" |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | |
| 16 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 17 | * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions. |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 18 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 19 | class BinaryXmlDecoder : public ndn_BinaryXmlDecoder { |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 20 | public: |
| 21 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 22 | * Initialize the base ndn_BinaryXmlDecoder struct with the input. |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 23 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 24 | BinaryXmlDecoder(const unsigned char *input, unsigned int inputLength) |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 25 | { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 26 | ndn_BinaryXmlDecoder_init(this, (unsigned char *)input, inputLength); |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 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; |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 39 | if (error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)) |
Jeff Thompson | 430a77a | 2013-07-15 17:17:56 -0700 | [diff] [blame] | 40 | throw std::runtime_error(ndn_getErrorString(error)); |
| 41 | |
| 42 | return gotExpectedTag; |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | #endif |