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