binary-xml-wire-format: Partial enabling of binary-xml-wire-format
Due to significant changes, Data abstraction conversion (from and to
wire format) is currently disabled, using empty placeholders instead.
Other data structures should have working conversion (minus
PublisherPublicKeyDigest, which is not part of Interest and
ForwardingEntry data structure anymore).
Change-Id: I51c47495808c35b500fc6b1fcc0c46db217e6598
diff --git a/src/c/encoding/binary-xml-decoder.c b/src/c/encoding/binary-xml-decoder.c
index d3b4d22..110ce51 100644
--- a/src/c/encoding/binary-xml-decoder.c
+++ b/src/c/encoding/binary-xml-decoder.c
@@ -293,7 +293,7 @@
}
ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds)
+ (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
{
ndn_Error error;
struct ndn_Blob bytes;
@@ -305,7 +305,7 @@
}
ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds)
+ (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
{
int gotExpectedTag;
ndn_Error error;
diff --git a/src/c/encoding/binary-xml-decoder.h b/src/c/encoding/binary-xml-decoder.h
index 5072b97..3f427c1 100644
--- a/src/c/encoding/binary-xml-decoder.h
+++ b/src/c/encoding/binary-xml-decoder.h
@@ -156,7 +156,7 @@
* @return 0 for success, else an error code, including an error if not the expected tag
*/
ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds);
+ (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
/**
* Peek at the next element, and if it has the expectedTag then call ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement.
@@ -167,7 +167,7 @@
* @return 0 for success, else an error code
*/
ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds);
+ (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
/**
* Interpret the bytes as an unsigned big endian integer and convert to a double. Don't check for overflow.
diff --git a/src/encoding/binary-xml-wire-format.cpp b/src/encoding/binary-xml-wire-format.cpp
index e463e91..73d8fd6 100644
--- a/src/encoding/binary-xml-wire-format.cpp
+++ b/src/encoding/binary-xml-wire-format.cpp
@@ -20,6 +20,204 @@
namespace ndn {
+namespace c {
+
+class Exclude : public ndn::Exclude
+{
+public:
+ void
+ get(struct ndn_Exclude& excludeStruct) const
+ {
+ if (excludeStruct.maxEntries < size())
+ throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
+
+ int entries = 0;
+ for (Exclude::const_reverse_iterator i = rbegin (); i != rend (); i++)
+ {
+ if (!i->first.empty())
+ {
+ excludeStruct.entries[entries].type = ndn_Exclude_COMPONENT;
+ excludeStruct.entries[entries].component.value.value = const_cast<uint8_t*>(i->first.getValue().buf());
+ excludeStruct.entries[entries].component.value.length = i->first.getValue().size();
+ ++entries;
+ }
+ if (i->second)
+ {
+ excludeStruct.entries[entries].type = ndn_Exclude_ANY;
+ ++entries;
+ }
+ }
+
+ excludeStruct.nEntries = entries;
+ }
+
+ void
+ set(const struct ndn_Exclude& excludeStruct)
+ {
+ clear();
+
+ if (excludeStruct.nEntries == 0)
+ return;
+
+ int i = 0;
+ if (excludeStruct.entries[i].type == ndn_Exclude_ANY) {
+ appendExclude("/", true);
+ i++;
+ }
+
+ while (i < excludeStruct.nEntries) {
+ ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
+
+ if (entry->type != ndn_Exclude_COMPONENT)
+ throw runtime_error("unrecognized ndn_ExcludeType");
+
+ Name::Component excludedComponent (entry->component.value.value, entry->component.value.length);
+ ++i;
+ entry = &excludeStruct.entries[i];
+
+ if (i < excludeStruct.nEntries) {
+ if (entry->type == ndn_Exclude_ANY) {
+ appendExclude(excludedComponent, true);
+ ++i;
+ }
+ else
+ appendExclude(excludedComponent, false);
+ }
+ else
+ appendExclude(excludedComponent, false);
+ }
+ }
+};
+
+class Name : public ndn::Name
+{
+public:
+ void
+ get(struct ndn_Name& nameStruct) const
+ {
+ if (nameStruct.maxComponents < size())
+ throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
+
+ nameStruct.nComponents = size();
+ for (size_t i = 0; i < nameStruct.nComponents; ++i) {
+ nameStruct.components[i].value.value = const_cast<uint8_t*>(ndn::Name::get(i).getValue().buf());
+ nameStruct.components[i].value.length = ndn::Name::get(i).getValue().size();
+ }
+ }
+
+ void
+ set(const struct ndn_Name& nameStruct)
+ {
+ clear();
+ for (size_t i = 0; i < nameStruct.nComponents; ++i)
+ append(nameStruct.components[i].value.value, nameStruct.components[i].value.length);
+ }
+};
+
+class Interest : public ndn::Interest
+{
+public:
+ void
+ get(struct ndn_Interest& interestStruct) const
+ {
+ reinterpret_cast<const c::Name&>(getName()).get(interestStruct.name);
+ interestStruct.minSuffixComponents = getMinSuffixComponents();
+ interestStruct.maxSuffixComponents = getMaxSuffixComponents();
+ // publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
+ reinterpret_cast<const c::Exclude&>(getExclude()).get(interestStruct.exclude);
+ interestStruct.childSelector = getChildSelector();
+ interestStruct.answerOriginKind = getMustBeFresh() ?
+ (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED)
+ :
+ (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED | ndn_Interest_ANSWER_STALE);
+ interestStruct.scope = getScope();
+ interestStruct.interestLifetimeMilliseconds = getInterestLifetime();
+
+ interestStruct.nonce.length = 4;
+ interestStruct.nonce.value = const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(getNonce()));
+ }
+
+ void
+ set(const struct ndn_Interest& interestStruct)
+ {
+ reinterpret_cast<c::Name&>(getName()).set(interestStruct.name);
+ setMinSuffixComponents(interestStruct.minSuffixComponents);
+ setMaxSuffixComponents(interestStruct.maxSuffixComponents);
+
+ // publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
+
+ reinterpret_cast<c::Exclude&>(getExclude()).set(interestStruct.exclude);
+ setChildSelector(interestStruct.childSelector);
+ // answerOriginKind_ = interestStruct.answerOriginKind;
+ setScope(interestStruct.scope);
+ setInterestLifetime(interestStruct.interestLifetimeMilliseconds);
+
+ setNonce(*reinterpret_cast<uint32_t*>(interestStruct.nonce.value));
+ }
+};
+
+class Data : public ndn::Data
+{
+public:
+ void
+ get(struct ndn_Data& dataStruct) const
+ {
+ // signature_->get(dataStruct.signature);
+ // name_.get(dataStruct.name);
+ // metaInfo_.get(dataStruct.metaInfo);
+ // content_.get(dataStruct.content);
+ }
+
+ void
+ set(const struct ndn_Data& dataStruct)
+ {
+ // signature_->set(dataStruct.signature);
+ // name_.set(dataStruct.name);
+ // metaInfo_.set(dataStruct.metaInfo);
+ // content_ = Blob(dataStruct.content);
+ }
+};
+
+class ForwardingEntry : public ndn::ForwardingEntry
+{
+public:
+ void
+ get(struct ndn_ForwardingEntry& forwardingEntryStruct) const
+ {
+ reinterpret_cast<const c::Name&>(getPrefix()).get(forwardingEntryStruct.prefix);
+ // publisherPublicKeyDigest_.get(forwardingEntryStruct.publisherPublicKeyDigest);
+ forwardingEntryStruct.faceId = getFaceId();
+ // forwardingEntryStruct.forwardingFlags = getForwardingFlags();
+ forwardingEntryStruct.freshnessSeconds = getFreshnessPeriod() / 1000;
+
+ forwardingEntryStruct.action.length = getAction().size();
+ if (getAction().size() > 0)
+ forwardingEntryStruct.action.value = (uint8_t *)&getAction();
+ else
+ forwardingEntryStruct.action.value = 0;
+ }
+
+ void
+ set(const struct ndn_ForwardingEntry& forwardingEntryStruct)
+ {
+ if (forwardingEntryStruct.action.value && forwardingEntryStruct.action.length > 0)
+ setAction(string(forwardingEntryStruct.action.value, forwardingEntryStruct.action.value + forwardingEntryStruct.action.length));
+ else
+ setAction("");
+
+ Name prefix;
+ reinterpret_cast<c::Name&>(prefix).set(forwardingEntryStruct.prefix);
+ setPrefix(prefix);
+ // publisherPublicKeyDigest_.set(forwardingEntryStruct.publisherPublicKeyDigest);
+ setFaceId(forwardingEntryStruct.faceId);
+ // setForwardingFlags(forwardingEntryStruct.forwardingFlags);
+ setFreshnessPeriod(forwardingEntryStruct.freshnessSeconds * 1000);
+ }
+};
+
+}
+
+
// This is declared in the WireFormat class.
WireFormat*
WireFormat::newInitialDefaultWireFormat()
@@ -36,7 +234,7 @@
ndn_Interest_initialize
(&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]));
- interest.get(interestStruct);
+ reinterpret_cast<const c::Interest&>(interest).get(interestStruct);
BinaryXmlEncoder encoder;
ndn_Error error;
@@ -61,7 +259,7 @@
if ((error = ndn_decodeBinaryXmlInterest(&interestStruct, &decoder)))
throw runtime_error(ndn_getErrorString(error));
- interest.set(interestStruct);
+ reinterpret_cast<c::Interest&>(interest).set(interestStruct);
}
Blob
@@ -73,7 +271,7 @@
ndn_Data_initialize
(&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
- data.get(dataStruct);
+ reinterpret_cast<const c::Data&>(data).get(dataStruct);
BinaryXmlEncoder encoder(1500);
ndn_Error error;
@@ -99,7 +297,7 @@
if ((error = ndn_decodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &decoder)))
throw runtime_error(ndn_getErrorString(error));
- data.set(dataStruct);
+ reinterpret_cast<c::Data&>(data).set(dataStruct);
}
Blob
@@ -109,7 +307,7 @@
struct ndn_ForwardingEntry forwardingEntryStruct;
ndn_ForwardingEntry_initialize
(&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
- forwardingEntry.get(forwardingEntryStruct);
+ reinterpret_cast<const c::ForwardingEntry&>(forwardingEntry).get(forwardingEntryStruct);
BinaryXmlEncoder encoder;
ndn_Error error;
@@ -132,7 +330,7 @@
if ((error = ndn_decodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &decoder)))
throw runtime_error(ndn_getErrorString(error));
- forwardingEntry.set(forwardingEntryStruct);
+ reinterpret_cast<c::ForwardingEntry&>(forwardingEntry).set(forwardingEntryStruct);
}
}
diff --git a/src/interest.cpp b/src/interest.cpp
index 85ce0c1..b9048ed 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -9,13 +9,26 @@
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/interest.hpp>
+#if __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreorder"
+#pragma clang diagnostic ignored "-Wtautological-compare"
+#pragma clang diagnostic ignored "-Wunused-variable"
+#pragma clang diagnostic ignored "-Wunused-function"
+#elif __GNUC__
+#pragma GCC diagnostic ignored "-Wreorder"
+#pragma GCC diagnostic ignored "-Wtautological-compare"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
#include <cryptopp/osrng.h>
using namespace std;
namespace ndn {
-uint32_t
+const uint32_t&
Interest::getNonce() const
{
static CryptoPP::AutoSeededRandomPool rng;