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