Added class BinaryXMLDecoder
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.hpp b/ndn-cpp/encoding/BinaryXMLDecoder.hpp
new file mode 100644
index 0000000..7ccfbd4
--- /dev/null
+++ b/ndn-cpp/encoding/BinaryXMLDecoder.hpp
@@ -0,0 +1,47 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_BINARYXMLDECODER_HPP
+#define NDN_BINARYXMLDECODER_HPP
+
+#include "../c/errors.h"
+#include "../c/encoding/BinaryXMLDecoder.h"
+
+namespace ndn {
+
+
+/**
+ * A BinaryXMLDecoder extends a C ndn_BinaryXMLDecoder struct and wraps related functions.
+ */
+class BinaryXMLDecoder : public ndn_BinaryXMLDecoder {
+public:
+ /**
+ * Initialize the base ndn_BinaryXMLDecoder struct with the input.
+ */
+ BinaryXMLDecoder(const unsigned char *input, unsigned int inputLength)
+ {
+ ndn_BinaryXMLDecoder_init(this, (unsigned char *)input, inputLength);
+ }
+
+ /**
+ * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
+ * then return true, else false. Do not update offset, including if throwing an exception.
+ * @param expectedTag the expected value for DTAG
+ * @return true if got the expected tag, else false
+ */
+ bool peekDTag(unsigned int expectedTag)
+ {
+ int gotExpectedTag;
+ ndn_Error error;
+ if (error = ndn_BinaryXMLDecoder_peekDTag(this, expectedTag, &gotExpectedTag))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ return gotExpectedTag;
+ }
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index df5ad35..6899924 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -10,7 +10,7 @@
#include "../Interest.hpp"
#include "../ContentObject.hpp"
#include "BinaryXMLEncoder.hpp"
-#include "../c/encoding/BinaryXMLDecoder.h"
+#include "BinaryXMLDecoder.hpp"
#include "BinaryXMLWireFormat.hpp"
using namespace std;
@@ -38,9 +38,7 @@
struct ndn_Name nameStruct;
ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
- struct ndn_BinaryXMLDecoder decoder;
- ndn_BinaryXMLDecoder_init(&decoder, (unsigned char *)input, inputLength);
-
+ BinaryXMLDecoder decoder(input, inputLength);
ndn_Error error;
if (error = ndn_decodeBinaryXMLName(&nameStruct, &decoder))
throw std::runtime_error(ndn_getErrorString(error));
@@ -73,9 +71,7 @@
(&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]));
- struct ndn_BinaryXMLDecoder decoder;
- ndn_BinaryXMLDecoder_init(&decoder, (unsigned char *)input, inputLength);
-
+ BinaryXMLDecoder decoder(input, inputLength);
ndn_Error error;
if (error = ndn_decodeBinaryXMLInterest(&interestStruct, &decoder))
throw std::runtime_error(ndn_getErrorString(error));
@@ -104,9 +100,7 @@
ndn_ContentObject_init
(&contentObjectStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
- struct ndn_BinaryXMLDecoder decoder;
- ndn_BinaryXMLDecoder_init(&decoder, (unsigned char *)input, inputLength);
-
+ BinaryXMLDecoder decoder(input, inputLength);
ndn_Error error;
if (error = ndn_decodeBinaryXMLContentObject(&contentObjectStruct, &decoder))
throw std::runtime_error(ndn_getErrorString(error));