blob: 3e371c31b2ee38635507c5e92c63adc135c4aabc [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
15namespace ndn {
16
17
18/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070019 * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions.
Jeff Thompson430a77a2013-07-15 17:17:56 -070020 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070021class BinaryXmlDecoder : public ndn_BinaryXmlDecoder {
Jeff Thompson430a77a2013-07-15 17:17:56 -070022public:
23 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070024 * Initialize the base ndn_BinaryXmlDecoder struct with the input.
Jeff Thompson430a77a2013-07-15 17:17:56 -070025 */
Jeff Thompson97223af2013-09-24 17:01:27 -070026 BinaryXmlDecoder(const uint8_t *input, size_t inputLength)
Jeff Thompson430a77a2013-07-15 17:17:56 -070027 {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070028 ndn_BinaryXmlDecoder_initialize(this, (uint8_t *)input, inputLength);
Jeff Thompson430a77a2013-07-15 17:17:56 -070029 }
30
31 /**
32 * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
33 * then return true, else false. Do not update offset, including if throwing an exception.
34 * @param expectedTag the expected value for DTAG
35 * @return true if got the expected tag, else false
36 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070037 bool
38 peekDTag(unsigned int expectedTag)
Jeff Thompson430a77a2013-07-15 17:17:56 -070039 {
40 int gotExpectedTag;
41 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070042 if ((error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)))
Jeff Thompson430a77a2013-07-15 17:17:56 -070043 throw std::runtime_error(ndn_getErrorString(error));
44
45 return gotExpectedTag;
46 }
47};
48
49}
50
51#endif