Implement ndn_decodeBinaryXMLInterest (except for Exclude)
diff --git a/ndn-cpp/Interest.hpp b/ndn-cpp/Interest.hpp
index a1f045f..f5a59ea 100644
--- a/ndn-cpp/Interest.hpp
+++ b/ndn-cpp/Interest.hpp
@@ -42,6 +42,8 @@
Name &getName() { return name_; }
+ int getInterestLifetime() { return interestLifetime_; }
+
/**
* Clear this interest, and set the values by copying from the interest struct.
* @param interestStruct a C ndn_Interest struct
diff --git a/ndn-cpp/c/encoding/BinaryXMLInterest.c b/ndn-cpp/c/encoding/BinaryXMLInterest.c
index 0eea400..96077d3 100644
--- a/ndn-cpp/c/encoding/BinaryXMLInterest.c
+++ b/ndn-cpp/c/encoding/BinaryXMLInterest.c
@@ -6,9 +6,80 @@
#include "BinaryXMLEncoder.h"
#include "BinaryXMLDecoder.h"
+#include "BinaryXMLName.h"
#include "BinaryXMLInterest.h"
-char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, unsigned char *input, unsigned int inputLength)
+char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_BinaryXMLDecoder *decoder)
{
+ char *error;
+ if (error = ndn_BinaryXMLDecoder_readElementStartDTag(decoder, ndn_BinaryXML_DTag_Interest))
+ return error;
+
+ if (error = ndn_decodeBinaryXMLName(&interest->name, decoder))
+ return error;
+
+ if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ (decoder, ndn_BinaryXML_DTag_MinSuffixComponents, &interest->minSuffixComponents))
+ return error;
+ if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ (decoder, ndn_BinaryXML_DTag_MaxSuffixComponents, &interest->maxSuffixComponents))
+ return error;
+ int gotExpectedTag;
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &interest->publisherPublicKeyDigest,
+ &interest->publisherPublicKeyDigestLength))
+ return error;
+ }
+ else {
+ interest->publisherPublicKeyDigest = 0;
+ interest->publisherPublicKeyDigestLength = 0;
+ }
+
+ // TODO: Implement exclude
+
+ if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ (decoder, ndn_BinaryXML_DTag_ChildSelector, &interest->childSelector))
+ return error;
+ if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ (decoder, ndn_BinaryXML_DTag_AnswerOriginKind, &interest->answerOriginKind))
+ return error;
+ if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ (decoder, ndn_BinaryXML_DTag_Scope, &interest->scope))
+ return error;
+
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_InterestLifetime, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ unsigned char *interestLifetime;
+ unsigned int interestLifetimeLength;
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_InterestLifetime, 0, &interestLifetime, &interestLifetimeLength))
+ return error;
+
+ interest->interestLifetime = 1000 *
+ ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(interestLifetime, interestLifetimeLength) / 4096;
+ }
+ else
+ interest->interestLifetime = -1;
+
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Nonce, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_Nonce, 0, &interest->nonce, &interest->nonceLength))
+ return error;
+ }
+ else {
+ interest->nonce = 0;
+ interest->nonceLength = 0;
+ }
+
+ if (error = ndn_BinaryXMLDecoder_readElementClose(decoder))
+ return error;
+
+ return 0;
}
\ No newline at end of file
diff --git a/test/test-encode-decode-interest.cpp b/test/test-encode-decode-interest.cpp
index 448f413..d28a264 100644
--- a/test/test-encode-decode-interest.cpp
+++ b/test/test-encode-decode-interest.cpp
@@ -8,28 +8,29 @@
#include <cstdlib>
#include <sstream>
#include <iostream>
-#include <ndn-cpp/Name.hpp>
+#include <ndn-cpp/Interest.hpp>
using namespace std;
using namespace ndn;
-unsigned char Name1[] = {
-#if 0
+unsigned char Interest1[] = {
0x01, 0xd2,
-#endif
0xf2, 0xfa, 0x9d, 0x6e, 0x64, 0x6e, 0x00, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0x00,
-#if 0
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,
+#if 0
+ 0x02, 0xda, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0xea, 0x00, 0x00,
#endif
+ 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
};
@@ -39,15 +40,18 @@
int main(int argc, char** argv)
{
try {
- Name name;
- name.decode(Name1, sizeof(Name1));
- cout << "Name " << name.to_uri() << endl;
+ Interest interest;
+ interest.decode(Interest1, sizeof(Interest1));
+ cout << "Interest name " << interest.getName().to_uri() << endl;
+ cout << "InterestLifetime " << interest.getInterestLifetime() << endl;
+#if 0
vector<unsigned char> encoding;
- name.encode(encoding);
+ interest.encode(encoding);
unsigned char *encodingBuffer = &encoding[0];
unsigned int encodingLength = encoding.size();
- cout << "Name encoding length " << encodingLength << " vs. sizeof(Name1) " << sizeof(Name1) << endl;
+ cout << "Interest encoding length " << encodingLength << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl;
+#endif
} catch (exception &e) {
cout << "exception " << e.what() << endl;
}