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 self->otherTypeCode = -1;
43 ndn_Blob_initialize(&self->value, value, valueLength);
57 ndn_NameComponent_setType
63 (type == ndn_NameComponentType_OTHER_CODE ? otherTypeCode : -1);
76 return (self->value.length >= 1 && self->value.value[0] == 0x00 &&
77 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
90 return (self->value.length >= 1 && self->value.value[0] == 0xFB &&
91 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
104 return (self->value.length >= 1 && self->value.value[0] == 0xFD &&
105 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
118 return (self->value.length >= 1 && self->value.value[0] == 0xFC &&
119 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
132 return (self->value.length >= 1 && self->value.value[0] == 0xFE &&
133 self->type == ndn_NameComponentType_GENERIC) ? 1 : 0;
144 return self->type == ndn_NameComponentType_GENERIC ? 1 : 0;
155 return self->type == ndn_NameComponentType_IMPLICIT_SHA256_DIGEST ? 1 : 0;
166 return self->type == ndn_NameComponentType_PARAMETERS_SHA256_DIGEST ? 1 : 0;
183 ndn_Error ndn_NameComponent_toNumberWithMarker
195 static __inline ndn_Error
196 ndn_NameComponent_toSegment
199 return ndn_NameComponent_toNumberWithMarker(
self, 0x00, result);
211 static __inline ndn_Error
212 ndn_NameComponent_toSegmentOffset
215 return ndn_NameComponent_toNumberWithMarker(
self, 0xFB, result);
229 static __inline ndn_Error
230 ndn_NameComponent_toVersion
233 return ndn_NameComponent_toNumberWithMarker(
self, 0xFD, result);
246 static __inline ndn_Error
247 ndn_NameComponent_toTimestamp
250 return ndn_NameComponent_toNumberWithMarker(
self, 0xFC, result);
262 static __inline ndn_Error
263 ndn_NameComponent_toSequenceNumber
266 return ndn_NameComponent_toNumberWithMarker(
self, 0xFE, result);
277 ndn_Error ndn_NameComponent_toNumberWithPrefix
279 size_t prefixLength, uint64_t *result);
289 ndn_NameComponent_hasPrefix
291 size_t prefixLength);
299 int ndn_NameComponent_equals
310 int ndn_NameComponent_compare
319 ndn_NameComponent_setFromNameComponent
339 ndn_NameComponent_setFromNumber
341 size_t bufferLength);
358 ndn_NameComponent_setFromNumberWithMarker
360 uint8_t *buffer,
size_t bufferLength);
375 static __inline ndn_Error
376 ndn_NameComponent_setSegment
380 return ndn_NameComponent_setFromNumberWithMarker
381 (
self, segment, 0x00, buffer, bufferLength);
397 static __inline ndn_Error
398 ndn_NameComponent_setSegmentOffset
402 return ndn_NameComponent_setFromNumberWithMarker
403 (
self, segmentOffset, 0xFB, buffer, bufferLength);
420 static __inline ndn_Error
421 ndn_NameComponent_setVersion
425 return ndn_NameComponent_setFromNumberWithMarker
426 (
self, version, 0xFD, buffer, bufferLength);
443 static __inline ndn_Error
444 ndn_NameComponent_setTimestamp
448 return ndn_NameComponent_setFromNumberWithMarker
449 (
self, timestamp, 0xFC, buffer, bufferLength);
465 static __inline ndn_Error
466 ndn_NameComponent_setSequenceNumber
470 return ndn_NameComponent_setFromNumberWithMarker
471 (
self, sequenceNumber, 0xFE, buffer, bufferLength);
484 ndn_NameComponent_setImplicitSha256Digest
497 ndn_NameComponent_setParametersSha256Digest
506 static __inline
void ndn_Name_initialize(
struct ndn_Name *
self,
struct ndn_NameComponent *components,
size_t maxComponents)
508 self->components = components;
509 self->maxComponents = maxComponents;
510 self->nComponents = 0;
518 ndn_Name_clear(
struct ndn_Name *
self) {
self->nComponents = 0; }
528 int ndn_Name_equals(
const struct ndn_Name *
self,
const struct ndn_Name *name);
536 int ndn_Name_match(
const struct ndn_Name *
self,
const struct ndn_Name *name);
545 ndn_Error ndn_Name_appendComponent(
struct ndn_Name *
self,
const uint8_t* value,
size_t valueLength);
556 ndn_Error ndn_Name_appendNameComponent
567 ndn_Error ndn_Name_appendName(
struct ndn_Name *
self,
const struct ndn_Name *name);
575 static __inline ndn_Error ndn_Name_appendBlob(
struct ndn_Name *
self,
struct ndn_Blob *value)
577 return ndn_Name_appendComponent(
self, value->
value, value->
length);
590 static __inline ndn_Error ndn_Name_appendImplicitSha256Digest
591 (
struct ndn_Name *
self,
const uint8_t* digest,
size_t digestLength)
595 if ((error = ndn_Name_appendComponent(
self, 0, 0)))
597 return ndn_NameComponent_setImplicitSha256Digest
598 (&self->components[self->nComponents - 1], digest, digestLength);
612 static __inline ndn_Error ndn_Name_appendParametersSha256Digest
613 (
struct ndn_Name *
self,
const uint8_t* digest,
size_t digestLength)
617 if ((error = ndn_Name_appendComponent(
self, 0, 0)))
619 return ndn_NameComponent_setParametersSha256Digest
620 (&self->components[self->nComponents - 1], digest, digestLength);
629 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:47
An ndn_Name holds an array of ndn_NameComponent.
Definition: name-types.h:56
const uint8_t * value
pointer to the pre-allocated buffer for the value.
Definition: blob-types.h:34
Copyright (C) 2015-2018 Regents of the University of California.
Definition: blob-types.h:33