ndn-lite
metainfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Zhiyi Zhang, Tianyuan Yu
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_METAINFO_H
10 #define NDN_ENCODING_METAINFO_H
11 
12 #include "name.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
21 typedef struct ndn_metainfo {
25  uint64_t freshness_period;
33  uint8_t content_type;
34 
39 
44 static inline void
46 {
47  meta->enable_ContentType = 0;
48  meta->enable_FreshnessPeriod = 0;
49  meta->enable_FinalBlockId = 0;
50 }
51 
57 static inline void
59 {
60  memcpy(meta, other, sizeof(ndn_metainfo_t));
61 }
62 
69 int
71 
79 int
80 ndn_metainfo_from_tlv_block(ndn_metainfo_t* meta, const uint8_t* block_value, uint32_t block_size);
81 
87 static inline void
88 ndn_metainfo_set_content_type(ndn_metainfo_t* meta, uint8_t content_type)
89 {
90  meta->enable_ContentType = 1;
91  meta->content_type = content_type;
92 }
93 
99 static inline void
100 ndn_metainfo_set_freshness_period(ndn_metainfo_t* meta, uint64_t freshness_period)
101 {
102  meta->enable_FreshnessPeriod = 1;
103  meta->freshness_period = freshness_period;
104 }
105 
111 static inline void
113 {
114  meta->enable_FinalBlockId = 1;
115  memcpy(&meta->final_block_id, final_block_id, sizeof(name_component_t));
116 }
117 
124 static inline uint32_t
126 {
127  uint32_t meta_value_size = 0;
128  if (meta->enable_ContentType) {
129  meta_value_size += encoder_probe_block_size(TLV_ContentType, 1);
130  }
131  if (meta->enable_FreshnessPeriod) {
134  }
135  if (meta->enable_FinalBlockId) {
136  uint32_t comp_tlv_size = name_component_probe_block_size(&meta->final_block_id);
137  meta_value_size += encoder_probe_block_size(TLV_FinalBlockId, comp_tlv_size);
138  }
139 
140  if (meta_value_size == 0) {
141  return 0;
142  }
143  else {
144  return encoder_probe_block_size(TLV_MetaInfo, meta_value_size);
145  }
146 }
147 
154 int
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif // NDN_ENCODING_METAINFO_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_metainfo_from_tlv_block(ndn_metainfo_t *meta, const uint8_t *block_value, uint32_t block_size)
Decode a Metainfo TLV block into a ndn_metainfo_t.
Definition: metainfo.c:72
int ndn_metainfo_tlv_decode(ndn_decoder_t *decoder, ndn_metainfo_t *meta)
Decode the Metainfo from wire format (TLV block).
Definition: metainfo.c:12
Definition: tlv.h:46
The structure to keep the state when doing NDN TLV decoding.
Definition: decoder.h:21
uint8_t enable_FinalBlockId
Definition: metainfo.h:37
struct ndn_metainfo ndn_metainfo_t
The structure to represent the Metainfo structure.
static void ndn_metainfo_set_content_type(ndn_metainfo_t *meta, uint8_t content_type)
Set ContentType of the Metainfo.
Definition: metainfo.h:88
static void ndn_metainfo_from_other(ndn_metainfo_t *meta, const ndn_metainfo_t *other)
Init a Metainfo structure.
Definition: metainfo.h:58
uint64_t freshness_period
The freshness period of the Data packet.
Definition: metainfo.h:25
uint8_t content_type
The content type the Data packet holds.
Definition: metainfo.h:33
The structure to represent the Metainfo structure.
Definition: metainfo.h:21
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
int ndn_metainfo_tlv_encode(ndn_encoder_t *encoder, const ndn_metainfo_t *meta)
Encode the Metainfo structure into wire format (TLV block).
Definition: metainfo.c:80
static void ndn_metainfo_init(ndn_metainfo_t *meta)
Init a Metainfo structure.
Definition: metainfo.h:45
Definition: tlv.h:40
The structure to represent the Name Component.
Definition: name-component.h:23
static int encoder_probe_uint_length(uint64_t value)
Probe the length of a non-negative int as the value (V).
Definition: encoder.h:243
Definition: tlv.h:48
The structure to keep the state when doing NDN TLV encoding.
Definition: encoder.h:31
Definition: tlv.h:47
uint8_t enable_FreshnessPeriod
Definition: metainfo.h:36
static void ndn_metainfo_set_final_block_id(ndn_metainfo_t *meta, const name_component_t *final_block_id)
Set FinalBlockId of the Metainfo.
Definition: metainfo.h:112
static uint32_t ndn_metainfo_probe_block_size(const ndn_metainfo_t *meta)
Probe the size of a Metainfo TLV block before encoding it from a Metainfo structure.
Definition: metainfo.h:125
name_component_t final_block_id
The last name component in Name.
Definition: metainfo.h:29
static void ndn_metainfo_set_freshness_period(ndn_metainfo_t *meta, uint64_t freshness_period)
Set FreshnessPeriod of the Metainfo.
Definition: metainfo.h:100
uint8_t enable_ContentType
Definition: metainfo.h:35