ndn-lite
name.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Zhiyi Zhang
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v3.0. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef NDN_ENCODING_NAME_H
10 #define NDN_ENCODING_NAME_H
11 
12 #include "name-component.h"
13 #include <stdbool.h>
14 #include <stdio.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
24 typedef struct ndn_name {
32  uint32_t components_size;
33 } ndn_name_t;
34 
39 static inline void
41 {
42  for (int i = 0; i < name->components_size; i++) {
43  printf("/%.*s", name->components[i].size, name->components[i].value);
44  }
45  printf("\n");
46 }
47 
54 int
55 ndn_name_init(ndn_name_t *name, const name_component_t* components, uint32_t size);
56 
63 int
65 
72 int
73 ndn_name_from_block(ndn_name_t* name, const uint8_t* block_value, uint32_t block_size);
74 
81 int
83 
92 int
93 ndn_name_from_string(ndn_name_t* name, const char* string, uint32_t size);
94 
101 static inline uint32_t
103 {
104  uint32_t value_size = 0;
105  for (uint32_t i = 0; i < name->components_size; i++) {
106  value_size += name_component_probe_block_size(&name->components[i]);
107  }
108  return encoder_probe_block_size(TLV_Name, value_size);
109 }
110 
118 int
119 ndn_name_tlv_encode(ndn_encoder_t* encoder, const ndn_name_t *name);
120 
127 int
128 ndn_name_compare(const ndn_name_t* lhs, const ndn_name_t* rhs);
129 
140 int
141 ndn_name_compare_sub_names(const ndn_name_t* lhs, int lhs_b, int lhs_e,
142  const ndn_name_t* rhs, int rhs_b, int rhs_e);
143 
151 int
152 ndn_name_is_prefix_of(const ndn_name_t* lhs, const ndn_name_t* rhs);
153 
166 int
167 ndn_name_compare_block(const uint8_t* lhs_block_value, uint32_t lhs_block_size,
168  const uint8_t* rhs_block_value, uint32_t rhs_block_size);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif // NDN_ENCODING_NAME_H
static uint32_t name_component_probe_block_size(const name_component_t *component)
Probe the size of a Name component TLV block before encoding it from a Name Component structure.
Definition: name-component.h:140
int ndn_name_compare_block(const uint8_t *lhs_block_value, uint32_t lhs_block_size, const uint8_t *rhs_block_value, uint32_t rhs_block_size)
Compare two encoded Names.
Definition: name.c:178
The structure to keep the state when doing NDN TLV decoding.
Definition: decoder.h:21
int ndn_name_init(ndn_name_t *name, const name_component_t *components, uint32_t size)
Init a Name structure.
Definition: name.c:12
Definition: tlv.h:23
int ndn_name_tlv_encode(ndn_encoder_t *encoder, const ndn_name_t *name)
Encode the Name structure into wire format (TLV block).
Definition: name.c:108
struct ndn_name ndn_name_t
The structure to represent the Name.
name_component_t components[NDN_NAME_COMPONENTS_SIZE]
The array of name components contained in this name (not including T and L)
Definition: name.h:28
The structure to represent the Name.
Definition: name.h:24
#define NDN_NAME_COMPONENTS_SIZE
Definition: ndn-constants.h:17
int ndn_name_from_string(ndn_name_t *name, const char *string, uint32_t size)
Init a name block from a string.
Definition: name.c:71
static uint32_t encoder_probe_block_size(uint32_t type, uint32_t payload_size)
Probe the size of a TLV block.
Definition: encoder.h:82
static uint32_t ndn_name_probe_block_size(const ndn_name_t *name)
Probe the size of a Name TLV block before encoding it from a Name structure.
Definition: name.h:102
uint8_t value[NDN_NAME_COMPONENT_BUFFER_SIZE]
The value which name component holds.
Definition: name-component.h:31
The structure to represent the Name Component.
Definition: name-component.h:23
static void ndn_name_print(ndn_name_t *name)
Print a name.
Definition: name.h:40
int ndn_name_compare_sub_names(const ndn_name_t *lhs, int lhs_b, int lhs_e, const ndn_name_t *rhs, int rhs_b, int rhs_e)
Compare sub-names of two names.
Definition: name.c:145
int ndn_name_is_prefix_of(const ndn_name_t *lhs, const ndn_name_t *rhs)
Compare two Name based on the canonical order, to see whether a name is the prefix of another.
Definition: name.c:159
int ndn_name_compare(const ndn_name_t *lhs, const ndn_name_t *rhs)
Compare two Name.
Definition: name.c:131
The structure to keep the state when doing NDN TLV encoding.
Definition: encoder.h:31
int ndn_name_append_component(ndn_name_t *name, const name_component_t *component)
Appends a component to the end of a name.
Definition: name.c:59
uint32_t size
The size of component value buffer.
Definition: name-component.h:35
int ndn_name_tlv_decode(ndn_decoder_t *decoder, ndn_name_t *name)
Decode the Name from wire format (TLV block).
Definition: name.c:24
uint32_t components_size
The number of name components.
Definition: name.h:32
int ndn_name_from_block(ndn_name_t *name, const uint8_t *block_value, uint32_t block_size)
Decode an Name TLV block into an Name.
Definition: name.c:51