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