Change the ExcludeEntry to use a name component directly.
diff --git a/ndn-cpp/c/encoding/binary-xml-interest.c b/ndn-cpp/c/encoding/binary-xml-interest.c
index a540222..b835ebd 100644
--- a/ndn-cpp/c/encoding/binary-xml-interest.c
+++ b/ndn-cpp/c/encoding/binary-xml-interest.c
@@ -26,7 +26,7 @@
if (entry->type == ndn_Exclude_COMPONENT) {
if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_Component, entry->component, entry->componentLength)))
+ (encoder, ndn_BinaryXml_DTag_Component, entry->component.value, entry->component.valueLength)))
return error;
}
else if (entry->type == ndn_Exclude_ANY) {
diff --git a/ndn-cpp/c/interest.h b/ndn-cpp/c/interest.h
index bdb28b1..c3a1647 100644
--- a/ndn-cpp/c/interest.h
+++ b/ndn-cpp/c/interest.h
@@ -23,8 +23,7 @@
*/
struct ndn_ExcludeEntry {
ndn_ExcludeType type;
- unsigned char *component; /**< pointer to the pre-allocated buffer for the component value */
- unsigned int componentLength; /**< the number of bytes in value */
+ struct ndn_NameComponent component;
};
/**
@@ -37,8 +36,7 @@
static inline void ndn_ExcludeEntry_init(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, unsigned char *component, unsigned int componentLength)
{
self->type = type;
- self->component = component;
- self->componentLength = componentLength;
+ ndn_NameComponent_init(&self->component, component, componentLength);
}
/**
diff --git a/ndn-cpp/interest.cpp b/ndn-cpp/interest.cpp
index 5417fa0..b9a4b69 100644
--- a/ndn-cpp/interest.cpp
+++ b/ndn-cpp/interest.cpp
@@ -28,7 +28,7 @@
ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
if (entry->type == ndn_Exclude_COMPONENT)
- addComponent(entry->component, entry->componentLength);
+ addComponent(entry->component.value, entry->component.valueLength);
else if (entry->type == ndn_Exclude_ANY)
addAny();
else
diff --git a/ndn-cpp/interest.hpp b/ndn-cpp/interest.hpp
index ed5835b..5d7169a 100644
--- a/ndn-cpp/interest.hpp
+++ b/ndn-cpp/interest.hpp
@@ -29,7 +29,7 @@
* Create an ExcludeEntry of type ndn_Exclude_COMPONENT
*/
ExcludeEntry(unsigned char *component, unsigned int componentLen)
- : type_(ndn_Exclude_COMPONENT), component_(component, component + componentLen)
+ : type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
{
}
@@ -41,19 +41,17 @@
void get(struct ndn_ExcludeEntry &excludeEntryStruct) const
{
excludeEntryStruct.type = type_;
- if (type_ == ndn_Exclude_COMPONENT) {
- excludeEntryStruct.componentLength = component_.size();
- excludeEntryStruct.component = (unsigned char *)&component_[0];
- }
+ if (type_ == ndn_Exclude_COMPONENT)
+ component_.get(excludeEntryStruct.component);
}
ndn_ExcludeType getType() const { return type_; }
- const std::vector<unsigned char> &getComponent() const { return component_; }
+ const Name::Component &getComponent() const { return component_; }
private:
ndn_ExcludeType type_;
- std::vector<unsigned char> component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
+ Name::Component component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
};
/**
diff --git a/ndn-cpp/name.hpp b/ndn-cpp/name.hpp
index 2baee7d..5d6fb19 100644
--- a/ndn-cpp/name.hpp
+++ b/ndn-cpp/name.hpp
@@ -50,8 +50,9 @@
*/
void get(struct ndn_NameComponent &componentStruct) const
{
- componentStruct.value = (unsigned char *)&value_[0];
componentStruct.valueLength = value_.size();
+ if (value_.size() > 0)
+ componentStruct.value = (unsigned char *)&value_[0];
}
/**