Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef NDN_NAME_H |
| 7 | #define NDN_NAME_H |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 13 | /** |
| 14 | * An ndn_NameComponent holds a pointer to the component value. |
| 15 | */ |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 16 | struct ndn_NameComponent { |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 17 | unsigned char *value; /**< pointer to the pre-allocated buffer for the component value */ |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 18 | unsigned int valueLength; /**< the number of bytes in value */ |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 19 | }; |
| 20 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 21 | /** |
| 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 Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 27 | static 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 Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 32 | |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 33 | /** |
| 34 | * An ndn_Name holds an array of ndn_NameComponent. |
| 35 | */ |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 36 | struct ndn_Name { |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 37 | 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 Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Initialize an ndn_Name struct with the components array. |
| 44 | * @param self pointer to the ndn_Name struct |
Jeff Thompson | 2934a5b | 2013-07-03 17:45:53 -0700 | [diff] [blame] | 45 | * @param components the pre-allocated array of ndn_NameComponent |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 46 | * @param maxComponents the number of elements in the allocated components array |
| 47 | */ |
| 48 | static inline void ndn_Name_init(struct ndn_Name *self, struct ndn_NameComponent *components, unsigned int maxComponents) |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 49 | { |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 50 | self->components = components; |
| 51 | self->maxComponents = maxComponents; |
Jeff Thompson | b0fd64f | 2013-06-27 16:02:36 -0700 | [diff] [blame] | 52 | self->nComponents = 0; |
| 53 | } |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 54 | |
| 55 | #ifdef __cplusplus |
| 56 | } |
| 57 | #endif |
| 58 | |
Jeff Thompson | 08d5629 | 2013-06-27 18:20:44 -0700 | [diff] [blame] | 59 | #endif |
Jeff Thompson | 5d89cb9 | 2013-06-27 15:57:15 -0700 | [diff] [blame] | 60 | |