blob: 8096393058c88bacfaf342bfc5b9891522adddf8 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson5d89cb92013-06-27 15:57:15 -07004 */
5
6#ifndef NDN_NAME_H
7#define NDN_NAME_H
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
Jeff Thompson2934a5b2013-07-03 17:45:53 -070013/**
14 * An ndn_NameComponent holds a pointer to the component value.
15 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070016struct ndn_NameComponent {
Jeff Thompson2934a5b2013-07-03 17:45:53 -070017 unsigned char *value; /**< pointer to the pre-allocated buffer for the component value */
Jeff Thompson08d56292013-06-27 18:20:44 -070018 unsigned int valueLength; /**< the number of bytes in value */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070019};
20
Jeff Thompson2934a5b2013-07-03 17:45:53 -070021/**
22 *
23 * @param self pointer to the ndn_NameComponent struct
24 * @param value the pre-allocated buffer for the component value
25 * @param valueLength the number of bytes in value
26 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070027static inline void ndn_NameComponent_init(struct ndn_NameComponent *self, unsigned char *value, unsigned int valueLength)
28{
29 self->value = value;
30 self->valueLength = valueLength;
31}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070032
Jeff Thompson2934a5b2013-07-03 17:45:53 -070033/**
34 * An ndn_Name holds an array of ndn_NameComponent.
35 */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070036struct ndn_Name {
Jeff Thompson08d56292013-06-27 18:20:44 -070037 struct ndn_NameComponent *components; /**< pointer to the array of components. */
38 unsigned int maxComponents; /**< the number of elements in the allocated components array */
39 unsigned int nComponents; /**< the number of components in the name */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070040};
41
Jeff Thompson08d56292013-06-27 18:20:44 -070042/**
43 * Initialize an ndn_Name struct with the components array.
44 * @param self pointer to the ndn_Name struct
Jeff Thompson2934a5b2013-07-03 17:45:53 -070045 * @param components the pre-allocated array of ndn_NameComponent
Jeff Thompson08d56292013-06-27 18:20:44 -070046 * @param maxComponents the number of elements in the allocated components array
47 */
48static inline void ndn_Name_init(struct ndn_Name *self, struct ndn_NameComponent *components, unsigned int maxComponents)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070049{
Jeff Thompson08d56292013-06-27 18:20:44 -070050 self->components = components;
51 self->maxComponents = maxComponents;
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070052 self->nComponents = 0;
53}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070054
55#ifdef __cplusplus
56}
57#endif
58
Jeff Thompson08d56292013-06-27 18:20:44 -070059#endif
Jeff Thompson5d89cb92013-06-27 15:57:15 -070060