name.h
1 
21 #ifndef NDN_NAME_H
22 #define NDN_NAME_H
23 
24 #include <ndn-cpp/c/name-types.h>
25 #include <ndn-cpp/c/errors.h>
26 #include "util/blob.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
38 static __inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, const uint8_t *value, size_t valueLength)
39 {
40  ndn_Blob_initialize(&self->value, value, valueLength);
41 }
42 
48 uint64_t ndn_NameComponent_toNumber(const struct ndn_NameComponent *self);
49 
57 ndn_Error ndn_NameComponent_toNumberWithMarker
58  (const struct ndn_NameComponent *self, uint8_t marker, uint64_t *result);
59 
69 static __inline ndn_Error
70 ndn_NameComponent_toSegment
71  (const struct ndn_NameComponent *self, uint64_t *result)
72 {
73  return ndn_NameComponent_toNumberWithMarker(self, 0x00, result);
74 }
75 
85 static __inline ndn_Error
86 ndn_NameComponent_toSegmentOffset
87  (const struct ndn_NameComponent *self, uint64_t *result)
88 {
89  return ndn_NameComponent_toNumberWithMarker(self, 0xFB, result);
90 }
91 
103 static __inline ndn_Error
104 ndn_NameComponent_toVersion
105  (const struct ndn_NameComponent *self, uint64_t *result)
106 {
107  return ndn_NameComponent_toNumberWithMarker(self, 0xFD, result);
108 }
109 
120 static __inline ndn_Error
121 ndn_NameComponent_toTimestamp
122  (const struct ndn_NameComponent *self, uint64_t *result)
123 {
124  return ndn_NameComponent_toNumberWithMarker(self, 0xFC, result);
125 }
126 
136 static __inline ndn_Error
137 ndn_NameComponent_toSequenceNumber
138  (const struct ndn_NameComponent *self, uint64_t *result)
139 {
140  return ndn_NameComponent_toNumberWithMarker(self, 0xFE, result);
141 }
142 
151 ndn_Error ndn_NameComponent_toNumberWithPrefix
152  (const struct ndn_NameComponent *self, const uint8_t *prefix,
153  size_t prefixLength, uint64_t *result);
154 
162 int
163 ndn_NameComponent_hasPrefix
164  (const struct ndn_NameComponent *self, const uint8_t *prefix,
165  size_t prefixLength);
166 
175 int ndn_NameComponent_compare
176  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
177 
183 static __inline void
184 ndn_NameComponent_setFromNameComponent
185  (struct ndn_NameComponent *self, const struct ndn_NameComponent *other)
186 {
187  *self = *other;
188 }
189 
202 ndn_Error
203 ndn_NameComponent_setFromNumber
204  (struct ndn_NameComponent *self, uint64_t number, uint8_t *buffer,
205  size_t bufferLength);
206 
220 ndn_Error
221 ndn_NameComponent_setFromNumberWithMarker
222  (struct ndn_NameComponent *self, uint64_t number, uint8_t marker,
223  uint8_t *buffer, size_t bufferLength);
224 
238 static __inline ndn_Error
239 ndn_NameComponent_setSegment
240  (struct ndn_NameComponent *self, uint64_t segment, uint8_t* buffer,
241  size_t bufferLength)
242 {
243  return ndn_NameComponent_setFromNumberWithMarker
244  (self, segment, 0x00, buffer, bufferLength);
245 }
246 
260 static __inline ndn_Error
261 ndn_NameComponent_setSegmentOffset
262  (struct ndn_NameComponent *self, uint64_t segmentOffset, uint8_t* buffer,
263  size_t bufferLength)
264 {
265  return ndn_NameComponent_setFromNumberWithMarker
266  (self, segmentOffset, 0xFB, buffer, bufferLength);
267 }
268 
283 static __inline ndn_Error
284 ndn_NameComponent_setVersion
285  (struct ndn_NameComponent *self, uint64_t version, uint8_t* buffer,
286  size_t bufferLength)
287 {
288  return ndn_NameComponent_setFromNumberWithMarker
289  (self, version, 0xFD, buffer, bufferLength);
290 }
291 
306 static __inline ndn_Error
307 ndn_NameComponent_setTimestamp
308  (struct ndn_NameComponent *self, uint64_t timestamp, uint8_t* buffer,
309  size_t bufferLength)
310 {
311  return ndn_NameComponent_setFromNumberWithMarker
312  (self, timestamp, 0xFC, buffer, bufferLength);
313 }
314 
328 static __inline ndn_Error
329 ndn_NameComponent_setSequenceNumber
330  (struct ndn_NameComponent *self, uint64_t sequenceNumber, uint8_t* buffer,
331  size_t bufferLength)
332 {
333  return ndn_NameComponent_setFromNumberWithMarker
334  (self, sequenceNumber, 0xFE, buffer, bufferLength);
335 }
336 
343 static __inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
344 {
345  self->components = components;
346  self->maxComponents = maxComponents;
347  self->nComponents = 0;
348 }
349 
354 static __inline void
355 ndn_Name_clear(struct ndn_Name *self) { self->nComponents = 0; }
356 
365 int ndn_Name_equals(const struct ndn_Name *self, const struct ndn_Name *name);
366 
373 int ndn_Name_match(const struct ndn_Name *self, const struct ndn_Name *name);
374 
382 ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, const uint8_t* value, size_t valueLength);
383 
390 static __inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
391 {
392  return ndn_Name_appendComponent(self, value->value, value->length);
393 }
394 
401 ndn_Error ndn_Name_appendString(struct ndn_Name *self, const char * value);
402 
410 ndn_Error
411 ndn_Name_setFromName(struct ndn_Name *self, const struct ndn_Name *other);
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 
417 #endif
418 
size_t length
the number of bytes in value.
Definition: blob-types.h:35
Copyright (C) 2015 Regents of the University of California.
Definition: name-types.h:33
An ndn_Name holds an array of ndn_NameComponent.
Definition: name-types.h:40
const uint8_t * value
pointer to the pre-allocated buffer for the value.
Definition: blob-types.h:34
Copyright (C) 2015 Regents of the University of California.
Definition: blob-types.h:33