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