blob: 7ccfbd4b0a2d09a225e05beb8ac4e02c570062f5 [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
9#include "../c/errors.h"
10#include "../c/encoding/BinaryXMLDecoder.h"
11
12namespace ndn {
13
14
15/**
16 * A BinaryXMLDecoder extends a C ndn_BinaryXMLDecoder struct and wraps related functions.
17 */
18class BinaryXMLDecoder : public ndn_BinaryXMLDecoder {
19public:
20 /**
21 * Initialize the base ndn_BinaryXMLDecoder struct with the input.
22 */
23 BinaryXMLDecoder(const unsigned char *input, unsigned int inputLength)
24 {
25 ndn_BinaryXMLDecoder_init(this, (unsigned char *)input, inputLength);
26 }
27
28 /**
29 * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
30 * then return true, else false. Do not update offset, including if throwing an exception.
31 * @param expectedTag the expected value for DTAG
32 * @return true if got the expected tag, else false
33 */
34 bool peekDTag(unsigned int expectedTag)
35 {
36 int gotExpectedTag;
37 ndn_Error error;
38 if (error = ndn_BinaryXMLDecoder_peekDTag(this, expectedTag, &gotExpectedTag))
39 throw std::runtime_error(ndn_getErrorString(error));
40
41 return gotExpectedTag;
42 }
43};
44
45}
46
47#endif