Name: In C ndn_Name, added appendComponent, appendBlob and appendString.
diff --git a/src/c/errors.c b/src/c/errors.c
index 152a295..3b6b8bb 100644
--- a/src/c/errors.c
+++ b/src/c/errors.c
@@ -29,8 +29,8 @@
return "Header type is out of range";
case NDN_ERROR_encodeTypeAndValue_miscalculated_N_encoding_bytes:
return "EncodeTypeAndValue miscalculated N encoding bytes";
- case NDN_ERROR_read_a_component_past_the_maximum_number_of_components_allowed_in_the_name:
- return "Read a component past the maximum number of components allowed in the name";
+ case NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name:
+ return "Attempt to add a component past the maximum number of components allowed in the name";
case NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude:
return "Read an entry past the maximum number of entries allowed in the exclude";
case NDN_ERROR_findElementEnd_unexpected_close_tag:
diff --git a/src/c/errors.h b/src/c/errors.h
index 852c892..5906aa3 100644
--- a/src/c/errors.h
+++ b/src/c/errors.h
@@ -23,7 +23,7 @@
NDN_ERROR_item_is_not_UDATA,
NDN_ERROR_header_type_is_out_of_range,
NDN_ERROR_encodeTypeAndValue_miscalculated_N_encoding_bytes,
- NDN_ERROR_read_a_component_past_the_maximum_number_of_components_allowed_in_the_name,
+ NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name,
NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude,
NDN_ERROR_findElementEnd_unexpected_close_tag,
NDN_ERROR_cannot_store_more_header_bytes_than_the_size_of_headerBuffer,
diff --git a/src/c/name.c b/src/c/name.c
index 355636d..147d583 100644
--- a/src/c/name.c
+++ b/src/c/name.c
@@ -4,6 +4,7 @@
* See COPYING for copyright and distribution information.
*/
+#include <string.h>
#include "util/ndn_memory.h"
#include "name.h"
@@ -54,3 +55,18 @@
return 1;
}
+
+ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, uint8_t* value, size_t valueLength)
+{
+ if (self->nComponents >= self->maxComponents)
+ return NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name;
+ ndn_NameComponent_initialize(self->components + self->nComponents, value, valueLength);
+ ++self->nComponents;
+
+ return NDN_ERROR_success;
+}
+
+ndn_Error ndn_Name_appendString(struct ndn_Name *self, char* value)
+{
+ return ndn_Name_appendComponent(self, (uint8_t*)value, strlen(value));
+}
diff --git a/src/c/name.h b/src/c/name.h
index 68c3b6d..3a0ba31 100644
--- a/src/c/name.h
+++ b/src/c/name.h
@@ -79,6 +79,34 @@
*/
int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name);
+/**
+ * Append a component to this name with the bytes in the given array.
+ * @param self pointer to the ndn_Name struct.
+ * @param value The bytes of the component. This does not copy the bytes.
+ * @param valueLength The number of bytes in value.
+ * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
+ */
+ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, uint8_t* value, size_t valueLength);
+
+/**
+ * Append a component to this name with the bytes in the given blob.
+ * @param self pointer to the ndn_Name struct.
+ * @param value An ndn_Blob with the bytes of the component. This does not copy the bytes.
+ * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
+ */
+static inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
+{
+ return ndn_Name_appendComponent(self, value->value, value->length);
+}
+
+/**
+ * Append a component to this name with the bytes in raw string value.
+ * @param self pointer to the ndn_Name struct.
+ * @param value The null-terminated string, treated as a byte array. This does not copy the bytes.
+ * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
+ */
+ndn_Error ndn_Name_appendString(struct ndn_Name *self, char* value);
+
#ifdef __cplusplus
}
#endif