Browse Source

Interest: Added Interest::toUri().

pull/1/head
Jeff Thompson 12 years ago
parent
commit
13e280bef7
  1. 8
      include/ndn-cpp/interest.hpp
  2. 41
      src/interest.cpp

8
include/ndn-cpp/interest.hpp

@ -302,6 +302,14 @@ public:
wireDecode(&input[0], input.size(), wireFormat);
}
/**
* Encode the name according to the "NDN URI Scheme". If there are interest selectors, append "?" and
* added the selectors as a query string. For example "/test/name?ndn.ChildSelector=1".
* @return The URI string.
*/
std::string
toUri() const;
/**
* Set the interestStruct to point to the components in this interest, without copying any memory.
* WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory.

41
src/interest.cpp

@ -100,6 +100,47 @@ Interest::get(struct ndn_Interest& interestStruct) const
interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
nonce_.get(interestStruct.nonce);
}
string
Interest::toUri() const
{
ostringstream selectors;
if (minSuffixComponents_ >= 0)
selectors << "&ndn.MinSuffixComponents=" << minSuffixComponents_;
if (maxSuffixComponents_ >= 0)
selectors << "&ndn.MaxSuffixComponents=" << maxSuffixComponents_;
if (childSelector_ >= 0)
selectors << "&ndn.ChildSelector=" << childSelector_;
if (answerOriginKind_ >= 0)
selectors << "&ndn.AnswerOriginKind=" << answerOriginKind_;
if (scope_ >= 0)
selectors << "&ndn.Scope=" << scope_;
if (interestLifetimeMilliseconds_ >= 0)
selectors << "&ndn.InterestLifetime=" << interestLifetimeMilliseconds_;
if (publisherPublicKeyDigest_.getPublisherPublicKeyDigest().size() > 0) {
selectors << "&ndn.PublisherPublicKeyDigest=";
Name::toEscapedString(*publisherPublicKeyDigest_.getPublisherPublicKeyDigest(), selectors);
}
if (nonce_.size() > 0) {
selectors << "&ndn.Nonce=";
Name::toEscapedString(*nonce_, selectors);
}
if (exclude_.size() > 0)
selectors << "&ndn.Exclude=" << exclude_.toUri();
ostringstream result;
result << name_.toUri();
string selectorsString(selectors.str());
if (selectorsString.size() > 0) {
// Replace the first & with ?.
result << "?";
result.write(&selectorsString[1], selectorsString.size() - 1);
}
return result.str();
}
}

Loading…
Cancel
Save