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 
50 static __inline int
51 ndn_NameComponent_isSegment(const struct ndn_NameComponent *self)
52 {
53  return self->value.length >= 1 && self->value.value[0] == 0x00 ? 1 : 0;
54 }
55 
63 static __inline int
64 ndn_NameComponent_isSegmentOffset(const struct ndn_NameComponent *self)
65 {
66  return self->value.length >= 1 && self->value.value[0] == 0xFB ? 1 : 0;
67 }
68 
76 static __inline int
77 ndn_NameComponent_isVersion(const struct ndn_NameComponent *self)
78 {
79  return self->value.length >= 1 && self->value.value[0] == 0xFD ? 1 : 0;
80 }
81 
89 static __inline int
90 ndn_NameComponent_isTimestamp(const struct ndn_NameComponent *self)
91 {
92  return self->value.length >= 1 && self->value.value[0] == 0xFC ? 1 : 0;
93 }
94 
102 static __inline int
103 ndn_NameComponent_isSequenceNumber(const struct ndn_NameComponent *self)
104 {
105  return self->value.length >= 1 && self->value.value[0] == 0xFE ? 1 : 0;
106 }
107 
113 uint64_t ndn_NameComponent_toNumber(const struct ndn_NameComponent *self);
114 
122 ndn_Error ndn_NameComponent_toNumberWithMarker
123  (const struct ndn_NameComponent *self, uint8_t marker, uint64_t *result);
124 
134 static __inline ndn_Error
135 ndn_NameComponent_toSegment
136  (const struct ndn_NameComponent *self, uint64_t *result)
137 {
138  return ndn_NameComponent_toNumberWithMarker(self, 0x00, result);
139 }
140 
150 static __inline ndn_Error
151 ndn_NameComponent_toSegmentOffset
152  (const struct ndn_NameComponent *self, uint64_t *result)
153 {
154  return ndn_NameComponent_toNumberWithMarker(self, 0xFB, result);
155 }
156 
168 static __inline ndn_Error
169 ndn_NameComponent_toVersion
170  (const struct ndn_NameComponent *self, uint64_t *result)
171 {
172  return ndn_NameComponent_toNumberWithMarker(self, 0xFD, result);
173 }
174 
185 static __inline ndn_Error
186 ndn_NameComponent_toTimestamp
187  (const struct ndn_NameComponent *self, uint64_t *result)
188 {
189  return ndn_NameComponent_toNumberWithMarker(self, 0xFC, result);
190 }
191 
201 static __inline ndn_Error
202 ndn_NameComponent_toSequenceNumber
203  (const struct ndn_NameComponent *self, uint64_t *result)
204 {
205  return ndn_NameComponent_toNumberWithMarker(self, 0xFE, result);
206 }
207 
216 ndn_Error ndn_NameComponent_toNumberWithPrefix
217  (const struct ndn_NameComponent *self, const uint8_t *prefix,
218  size_t prefixLength, uint64_t *result);
219 
227 int
228 ndn_NameComponent_hasPrefix
229  (const struct ndn_NameComponent *self, const uint8_t *prefix,
230  size_t prefixLength);
231 
240 int ndn_NameComponent_compare
241  (const struct ndn_NameComponent *self, const struct ndn_NameComponent *other);
242 
248 static __inline void
249 ndn_NameComponent_setFromNameComponent
250  (struct ndn_NameComponent *self, const struct ndn_NameComponent *other)
251 {
252  *self = *other;
253 }
254 
267 ndn_Error
268 ndn_NameComponent_setFromNumber
269  (struct ndn_NameComponent *self, uint64_t number, uint8_t *buffer,
270  size_t bufferLength);
271 
285 ndn_Error
286 ndn_NameComponent_setFromNumberWithMarker
287  (struct ndn_NameComponent *self, uint64_t number, uint8_t marker,
288  uint8_t *buffer, size_t bufferLength);
289 
303 static __inline ndn_Error
304 ndn_NameComponent_setSegment
305  (struct ndn_NameComponent *self, uint64_t segment, uint8_t* buffer,
306  size_t bufferLength)
307 {
308  return ndn_NameComponent_setFromNumberWithMarker
309  (self, segment, 0x00, buffer, bufferLength);
310 }
311 
325 static __inline ndn_Error
326 ndn_NameComponent_setSegmentOffset
327  (struct ndn_NameComponent *self, uint64_t segmentOffset, uint8_t* buffer,
328  size_t bufferLength)
329 {
330  return ndn_NameComponent_setFromNumberWithMarker
331  (self, segmentOffset, 0xFB, buffer, bufferLength);
332 }
333 
348 static __inline ndn_Error
349 ndn_NameComponent_setVersion
350  (struct ndn_NameComponent *self, uint64_t version, uint8_t* buffer,
351  size_t bufferLength)
352 {
353  return ndn_NameComponent_setFromNumberWithMarker
354  (self, version, 0xFD, buffer, bufferLength);
355 }
356 
371 static __inline ndn_Error
372 ndn_NameComponent_setTimestamp
373  (struct ndn_NameComponent *self, uint64_t timestamp, uint8_t* buffer,
374  size_t bufferLength)
375 {
376  return ndn_NameComponent_setFromNumberWithMarker
377  (self, timestamp, 0xFC, buffer, bufferLength);
378 }
379 
393 static __inline ndn_Error
394 ndn_NameComponent_setSequenceNumber
395  (struct ndn_NameComponent *self, uint64_t sequenceNumber, uint8_t* buffer,
396  size_t bufferLength)
397 {
398  return ndn_NameComponent_setFromNumberWithMarker
399  (self, sequenceNumber, 0xFE, buffer, bufferLength);
400 }
401 
408 static __inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
409 {
410  self->components = components;
411  self->maxComponents = maxComponents;
412  self->nComponents = 0;
413 }
414 
419 static __inline void
420 ndn_Name_clear(struct ndn_Name *self) { self->nComponents = 0; }
421 
430 int ndn_Name_equals(const struct ndn_Name *self, const struct ndn_Name *name);
431 
438 int ndn_Name_match(const struct ndn_Name *self, const struct ndn_Name *name);
439 
447 ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, const uint8_t* value, size_t valueLength);
448 
455 static __inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
456 {
457  return ndn_Name_appendComponent(self, value->value, value->length);
458 }
459 
466 ndn_Error ndn_Name_appendString(struct ndn_Name *self, const char * value);
467 
475 ndn_Error
476 ndn_Name_setFromName(struct ndn_Name *self, const struct ndn_Name *other);
477 
478 #ifdef __cplusplus
479 }
480 #endif
481 
482 #endif
483 
size_t length
the number of bytes in value.
Definition: blob-types.h:35
Copyright (C) 2015-2016 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-2016 Regents of the University of California.
Definition: blob-types.h:33