blob: 969880d4639367ef0478e25703d5da95d3c333a7 [file] [log] [blame]
Jeff Thompson5d89cb92013-06-27 15:57:15 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef NDN_NAME_H
8#define NDN_NAME_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
Jeff Thompson2934a5b2013-07-03 17:45:53 -070014/**
15 * An ndn_NameComponent holds a pointer to the component value.
16 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070017struct ndn_NameComponent {
Jeff Thompson2934a5b2013-07-03 17:45:53 -070018 unsigned char *value; /**< pointer to the pre-allocated buffer for the component value */
Jeff Thompson08d56292013-06-27 18:20:44 -070019 unsigned int valueLength; /**< the number of bytes in value */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070020};
21
Jeff Thompson2934a5b2013-07-03 17:45:53 -070022/**
23 *
24 * @param self pointer to the ndn_NameComponent struct
25 * @param value the pre-allocated buffer for the component value
26 * @param valueLength the number of bytes in value
27 */
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070028static inline void ndn_NameComponent_init(struct ndn_NameComponent *self, unsigned char *value, unsigned int valueLength)
29{
30 self->value = value;
31 self->valueLength = valueLength;
32}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070033
Jeff Thompson2934a5b2013-07-03 17:45:53 -070034/**
35 * An ndn_Name holds an array of ndn_NameComponent.
36 */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070037struct ndn_Name {
Jeff Thompson08d56292013-06-27 18:20:44 -070038 struct ndn_NameComponent *components; /**< pointer to the array of components. */
39 unsigned int maxComponents; /**< the number of elements in the allocated components array */
40 unsigned int nComponents; /**< the number of components in the name */
Jeff Thompson5d89cb92013-06-27 15:57:15 -070041};
42
Jeff Thompson08d56292013-06-27 18:20:44 -070043/**
44 * Initialize an ndn_Name struct with the components array.
45 * @param self pointer to the ndn_Name struct
Jeff Thompson2934a5b2013-07-03 17:45:53 -070046 * @param components the pre-allocated array of ndn_NameComponent
Jeff Thompson08d56292013-06-27 18:20:44 -070047 * @param maxComponents the number of elements in the allocated components array
48 */
49static inline void ndn_Name_init(struct ndn_Name *self, struct ndn_NameComponent *components, unsigned int maxComponents)
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070050{
Jeff Thompson08d56292013-06-27 18:20:44 -070051 self->components = components;
52 self->maxComponents = maxComponents;
Jeff Thompsonb0fd64f2013-06-27 16:02:36 -070053 self->nComponents = 0;
54}
Jeff Thompson5d89cb92013-06-27 15:57:15 -070055
56#ifdef __cplusplus
57}
58#endif
59
Jeff Thompson08d56292013-06-27 18:20:44 -070060#endif
Jeff Thompson5d89cb92013-06-27 15:57:15 -070061