blob: 0a556f49e1830a9f1ee9f37500724c065ca3f7df [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 Thompsonf0fea002013-07-30 17:22:42 -070025 BinaryXmlDecoder(const unsigned char *input, unsigned int inputLength)
Jeff Thompson430a77a2013-07-15 17:17:56 -070026 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070027 ndn_BinaryXmlDecoder_initialize(this, (unsigned char *)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 */
36 bool peekDTag(unsigned int expectedTag)
37 {
38 int gotExpectedTag;
39 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070040 if ((error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)))
Jeff Thompson430a77a2013-07-15 17:17:56 -070041 throw std::runtime_error(ndn_getErrorString(error));
42
43 return gotExpectedTag;
44 }
45};
46
47}
48
49#endif