Fix bug in ndn_BinaryXMLStructureDecoder_findElementEnd: need to use bufferDecoder, not decoder.
diff --git a/ndn-cpp/encoding/BinaryXMLStructureDecoder.c b/ndn-cpp/encoding/BinaryXMLStructureDecoder.c
index e5668d6..0d53a3b 100644
--- a/ndn-cpp/encoding/BinaryXMLStructureDecoder.c
+++ b/ndn-cpp/encoding/BinaryXMLStructureDecoder.c
@@ -23,7 +23,8 @@
/**
* Set the state to READ_HEADER_OR_CLOSE and set up to start reading the header.
*/
-static inline void startHeader(struct ndn_BinaryXMLStructureDecoder *self) {
+static inline void startHeader(struct ndn_BinaryXMLStructureDecoder *self)
+{
self->headerLength = 0;
self->useHeaderBuffer = 0;
self->state = ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE;
@@ -94,7 +95,7 @@
// Use a local decoder just for the headerBuffer.
struct ndn_BinaryXMLDecoder bufferDecoder;
ndn_BinaryXMLDecoder_init(&bufferDecoder, self->headerBuffer, sizeof(self->headerBuffer));
- if (ndn_BinaryXMLDecoder_decodeTypeAndValue(&decoder, &type, &value))
+ if (ndn_BinaryXMLDecoder_decodeTypeAndValue(&bufferDecoder, &type, &value))
return "ndn_BinaryXMLStructureDecoder_findElementEnd: Can't read header type and value";
}
else {
diff --git a/test/test-encode-decode-interest.cpp b/test/test-encode-decode-interest.cpp
index 0ef645f..673deaf 100644
--- a/test/test-encode-decode-interest.cpp
+++ b/test/test-encode-decode-interest.cpp
@@ -8,16 +8,46 @@
#include <cstdlib>
#include <sstream>
#include <iostream>
-#include "ndn-cpp/interest.h"
-#include "ndn-cpp/encoding/ccnb.h"
+#include "../ndn-cpp/interest.h"
+#include "../ndn-cpp/encoding/ccnb.h"
+#include "../ndn-cpp/encoding/BinaryXMLStructureDecoder.hpp"
using namespace std;
using namespace ndn;
+const unsigned char Interest1[] = {
+0x01, 0xd2,
+ 0xf2, 0xfa, 0x9d, 0x6e, 0x64, 0x6e, 0x00, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0x00,
+ 0x05, 0x9a, 0x8e, 0x32, 0x00,
+ 0x05, 0xa2, 0x8e, 0x34, 0x00,
+ 0x03, 0xe2,
+ 0x02, 0x85, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x00,
+ 0x02, 0xda, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0xea, 0x00, 0x00, 0x05, 0xaa, 0x8e, 0x31, 0x00, 0x02,
+ 0xfa, 0x8e, 0x34, 0x00, 0x02, 0xd2, 0x8e, 0x32, 0x00, 0x03, 0x82, 0x9d, 0x01, 0xe0, 0x00, 0x00, 0x02, 0xca, 0xb5, 0x61,
+ 0x62, 0x61, 0x62, 0x61, 0x62, 0x00,
+0x00,
+1
+};
+
/*
*
*/
-int main(int argc, char** argv) {
+int main(int argc, char** argv)
+{
+ try {
+ BinaryXMLStructureDecoder structureDecoder;
+ for (unsigned int i = 1; i <= sizeof(Interest1); ++i) {
+ if (structureDecoder.findElementEnd(Interest1, i)) {
+ cout << "got element end at " << structureDecoder.getOffset() << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl;
+ break;
+ }
+ }
+ } catch (exception &e) {
+ cout << "exception " << e.what() << endl;
+ }
+
ndn::ptr_lib::shared_ptr<Interest> interest(new Interest());
interest->setName(Name("/test"));
interest->setMinSuffixComponents(2);
@@ -29,7 +59,7 @@
// i.setPublisherPublicKeyDigest(?);
ostringstream binary;
wire::Ccnb::appendInterest(binary, *interest);
- cout << binary.str().size() << "\n";
+ cout << binary.str().size() << endl;
return 0;
}