blob: f537935c56c2cddb5f7beb21211b3097ea869e2a [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/**
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