blob: a02e75350ab10d449148e04359a794e6f687d749 [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
7#define NDN_BINARYXMLDECODER_HPP
8
Jeff Thompsona33913f2013-07-15 17:23:55 -07009#include <stdexcept>
Jeff Thompson430a77a2013-07-15 17:17:56 -070010#include "../c/errors.h"
11#include "../c/encoding/BinaryXMLDecoder.h"
12
13namespace ndn {
14
15
16/**
17 * A BinaryXMLDecoder extends a C ndn_BinaryXMLDecoder struct and wraps related functions.
18 */
19class BinaryXMLDecoder : public ndn_BinaryXMLDecoder {
20public:
21 /**
22 * Initialize the base ndn_BinaryXMLDecoder struct with the input.
23 */
24 BinaryXMLDecoder(const unsigned char *input, unsigned int inputLength)
25 {
26 ndn_BinaryXMLDecoder_init(this, (unsigned char *)input, inputLength);
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;
39 if (error = ndn_BinaryXMLDecoder_peekDTag(this, expectedTag, &gotExpectedTag))
40 throw std::runtime_error(ndn_getErrorString(error));
41
42 return gotExpectedTag;
43 }
44};
45
46}
47
48#endif