blob: 1bbca340f6deb76679e48f6202fd1138a2d6dcc6 [file] [log] [blame]
Jeff Thompson430a77a2013-07-15 17:17:56 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson430a77a2013-07-15 17:17:56 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_BINARYXMLDECODER_HPP
Jeff Thompsona0d18c92013-08-06 13:55:32 -07008#define NDN_BINARYXMLDECODER_HPP
Jeff Thompson430a77a2013-07-15 17:17:56 -07009
Jeff Thompsona33913f2013-07-15 17:23:55 -070010#include <stdexcept>
Jeff Thompson430a77a2013-07-15 17:17:56 -070011#include "../c/errors.h"
Jeff Thompson53412192013-08-06 13:35:50 -070012#include "../c/encoding/binary-xml-decoder.h"
Jeff Thompson430a77a2013-07-15 17:17:56 -070013
14namespace ndn {
15
16
17/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070018 * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions.
Jeff Thompson430a77a2013-07-15 17:17:56 -070019 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070020class BinaryXmlDecoder : public ndn_BinaryXmlDecoder {
Jeff Thompson430a77a2013-07-15 17:17:56 -070021public:
22 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070023 * Initialize the base ndn_BinaryXmlDecoder struct with the input.
Jeff Thompson430a77a2013-07-15 17:17:56 -070024 */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070025 BinaryXmlDecoder(const uint8_t *input, unsigned int inputLength)
Jeff Thompson430a77a2013-07-15 17:17:56 -070026 {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070027 ndn_BinaryXmlDecoder_initialize(this, (uint8_t *)input, inputLength);
Jeff Thompson430a77a2013-07-15 17:17:56 -070028 }
29
30 /**
31 * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
32 * then return true, else false. Do not update offset, including if throwing an exception.
33 * @param expectedTag the expected value for DTAG
34 * @return true if got the expected tag, else false
35 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070036 bool
37 peekDTag(unsigned int expectedTag)
Jeff Thompson430a77a2013-07-15 17:17:56 -070038 {
39 int gotExpectedTag;
40 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070041 if ((error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)))
Jeff Thompson430a77a2013-07-15 17:17:56 -070042 throw std::runtime_error(ndn_getErrorString(error));
43
44 return gotExpectedTag;
45 }
46};
47
48}
49
50#endif