blob: e7583e58426be1a531e3a4774f5bb24366ea4d5c [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson430a77a2013-07-15 17:17:56 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson430a77a2013-07-15 17:17:56 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_BINARYXMLDECODER_HPP
Jeff Thompsona0d18c92013-08-06 13:55:32 -07009#define NDN_BINARYXMLDECODER_HPP
Jeff Thompson430a77a2013-07-15 17:17:56 -070010
Jeff Thompsona33913f2013-07-15 17:23:55 -070011#include <stdexcept>
Jeff Thompson430a77a2013-07-15 17:17:56 -070012#include "../c/errors.h"
Jeff Thompson53412192013-08-06 13:35:50 -070013#include "../c/encoding/binary-xml-decoder.h"
Jeff Thompson430a77a2013-07-15 17:17:56 -070014
Jeff Thompson4affbf52013-10-18 14:36:46 -070015using namespace std;
Jeff Thompson430a77a2013-07-15 17:17:56 -070016
Jeff Thompson4affbf52013-10-18 14:36:46 -070017namespace ndn {
Jeff Thompson430a77a2013-07-15 17:17:56 -070018
19/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070020 * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions.
Jeff Thompson430a77a2013-07-15 17:17:56 -070021 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070022class BinaryXmlDecoder : public ndn_BinaryXmlDecoder {
Jeff Thompson430a77a2013-07-15 17:17:56 -070023public:
24 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070025 * Initialize the base ndn_BinaryXmlDecoder struct with the input.
Jeff Thompson430a77a2013-07-15 17:17:56 -070026 */
Jeff Thompson97223af2013-09-24 17:01:27 -070027 BinaryXmlDecoder(const uint8_t *input, size_t inputLength)
Jeff Thompson430a77a2013-07-15 17:17:56 -070028 {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070029 ndn_BinaryXmlDecoder_initialize(this, (uint8_t *)input, inputLength);
Jeff Thompson430a77a2013-07-15 17:17:56 -070030 }
31
32 /**
33 * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
34 * then return true, else false. Do not update offset, including if throwing an exception.
35 * @param expectedTag the expected value for DTAG
36 * @return true if got the expected tag, else false
37 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070038 bool
39 peekDTag(unsigned int expectedTag)
Jeff Thompson430a77a2013-07-15 17:17:56 -070040 {
41 int gotExpectedTag;
42 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070043 if ((error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)))
Jeff Thompson4affbf52013-10-18 14:36:46 -070044 throw runtime_error(ndn_getErrorString(error));
Jeff Thompson430a77a2013-07-15 17:17:56 -070045
46 return gotExpectedTag;
47 }
48};
49
50}
51
52#endif