24 #include <ndn-cpp/c/name-types.h>
25 #include <ndn-cpp/c/errors.h>
26 #include "util/blob.h"
39 static __inline
void ndn_NameComponent_initialize(
struct ndn_NameComponent *
self,
const uint8_t *value,
size_t valueLength)
41 self->type = ndn_NameComponentType_GENERIC;
42 ndn_Blob_initialize(&self->value, value, valueLength);
55 return (self->value.length >= 1 && self->value.value[0] == 0x00 &&
56 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
69 return (self->value.length >= 1 && self->value.value[0] == 0xFB &&
70 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
83 return (self->value.length >= 1 && self->value.value[0] == 0xFD &&
84 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
97 return (self->value.length >= 1 && self->value.value[0] == 0xFC &&
98 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
111 return (self->value.length >= 1 && self->value.value[0] == 0xFE &&
112 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
123 return self->type == ndn_NameComponentType_GENERIC ? 1 : 0;
134 return self->type == ndn_NameComponentType_IMPLICIT_SHA256_DIGEST ? 1 : 0;
151 ndn_Error ndn_NameComponent_toNumberWithMarker
163 static __inline ndn_Error
164 ndn_NameComponent_toSegment
167 return ndn_NameComponent_toNumberWithMarker(
self, 0x00, result);
179 static __inline ndn_Error
180 ndn_NameComponent_toSegmentOffset
183 return ndn_NameComponent_toNumberWithMarker(
self, 0xFB, result);
197 static __inline ndn_Error
198 ndn_NameComponent_toVersion
201 return ndn_NameComponent_toNumberWithMarker(
self, 0xFD, result);
214 static __inline ndn_Error
215 ndn_NameComponent_toTimestamp
218 return ndn_NameComponent_toNumberWithMarker(
self, 0xFC, result);
230 static __inline ndn_Error
231 ndn_NameComponent_toSequenceNumber
234 return ndn_NameComponent_toNumberWithMarker(
self, 0xFE, result);
245 ndn_Error ndn_NameComponent_toNumberWithPrefix
247 size_t prefixLength, uint64_t *result);
257 ndn_NameComponent_hasPrefix
259 size_t prefixLength);
267 int ndn_NameComponent_equals
278 int ndn_NameComponent_compare
287 ndn_NameComponent_setFromNameComponent
307 ndn_NameComponent_setFromNumber
309 size_t bufferLength);
326 ndn_NameComponent_setFromNumberWithMarker
328 uint8_t *buffer,
size_t bufferLength);
343 static __inline ndn_Error
344 ndn_NameComponent_setSegment
348 return ndn_NameComponent_setFromNumberWithMarker
349 (
self, segment, 0x00, buffer, bufferLength);
365 static __inline ndn_Error
366 ndn_NameComponent_setSegmentOffset
370 return ndn_NameComponent_setFromNumberWithMarker
371 (
self, segmentOffset, 0xFB, buffer, bufferLength);
388 static __inline ndn_Error
389 ndn_NameComponent_setVersion
393 return ndn_NameComponent_setFromNumberWithMarker
394 (
self, version, 0xFD, buffer, bufferLength);
411 static __inline ndn_Error
412 ndn_NameComponent_setTimestamp
416 return ndn_NameComponent_setFromNumberWithMarker
417 (
self, timestamp, 0xFC, buffer, bufferLength);
433 static __inline ndn_Error
434 ndn_NameComponent_setSequenceNumber
438 return ndn_NameComponent_setFromNumberWithMarker
439 (
self, sequenceNumber, 0xFE, buffer, bufferLength);
452 ndn_NameComponent_setImplicitSha256Digest
461 static __inline
void ndn_Name_initialize(
struct ndn_Name *
self,
struct ndn_NameComponent *components,
size_t maxComponents)
463 self->components = components;
464 self->maxComponents = maxComponents;
465 self->nComponents = 0;
473 ndn_Name_clear(
struct ndn_Name *
self) {
self->nComponents = 0; }
483 int ndn_Name_equals(
const struct ndn_Name *
self,
const struct ndn_Name *name);
491 int ndn_Name_match(
const struct ndn_Name *
self,
const struct ndn_Name *name);
500 ndn_Error ndn_Name_appendComponent(
struct ndn_Name *
self,
const uint8_t* value,
size_t valueLength);
508 static __inline ndn_Error ndn_Name_appendBlob(
struct ndn_Name *
self,
struct ndn_Blob *value)
510 return ndn_Name_appendComponent(
self, value->
value, value->
length);
523 static __inline ndn_Error ndn_Name_appendImplicitSha256Digest
524 (
struct ndn_Name *
self,
const uint8_t* digest,
size_t digestLength)
528 if ((error = ndn_Name_appendComponent(
self, 0, 0)))
530 return ndn_NameComponent_setImplicitSha256Digest
531 (&self->components[self->nComponents - 1], digest, digestLength);
540 ndn_Error ndn_Name_appendString(
struct ndn_Name *
self,
const char * value);
size_t length
the number of bytes in value.
Definition: blob-types.h:35
An ndn_NameComponent holds a pointer to the component value.
Definition: name-types.h:41
An ndn_Name holds an array of ndn_NameComponent.
Definition: name-types.h:49
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