blob: d4304b0db22bc078f2b1bba9a49fe4347703ff48 [file] [log] [blame]
Jeff Thompson430a77a2013-07-15 17:17:56 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_BINARYXMLDECODER_HPP
Jeff Thompsona0d18c92013-08-06 13:55:32 -07007#define NDN_BINARYXMLDECODER_HPP
Jeff Thompson430a77a2013-07-15 17:17:56 -07008
Jeff Thompsona33913f2013-07-15 17:23:55 -07009#include <stdexcept>
Jeff Thompson430a77a2013-07-15 17:17:56 -070010#include "../c/errors.h"
Jeff Thompson53412192013-08-06 13:35:50 -070011#include "../c/encoding/binary-xml-decoder.h"
Jeff Thompson430a77a2013-07-15 17:17:56 -070012
13namespace ndn {
14
15
16/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070017 * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions.
Jeff Thompson430a77a2013-07-15 17:17:56 -070018 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070019class BinaryXmlDecoder : public ndn_BinaryXmlDecoder {
Jeff Thompson430a77a2013-07-15 17:17:56 -070020public:
21 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070022 * Initialize the base ndn_BinaryXmlDecoder struct with the input.
Jeff Thompson430a77a2013-07-15 17:17:56 -070023 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070024 BinaryXmlDecoder(const unsigned char *input, unsigned int inputLength)
Jeff Thompson430a77a2013-07-15 17:17:56 -070025 {
Jeff Thompsonf0fea002013-07-30 17:22:42 -070026 ndn_BinaryXmlDecoder_init(this, (unsigned char *)input, inputLength);
Jeff Thompson430a77a2013-07-15 17:17:56 -070027 }
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 Thompsonf0fea002013-07-30 17:22:42 -070039 if (error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag))
Jeff Thompson430a77a2013-07-15 17:17:56 -070040 throw std::runtime_error(ndn_getErrorString(error));
41
42 return gotExpectedTag;
43 }
44};
45
46}
47
48#endif