dynamic-uint8-array.h
1 
21 #ifndef NDN_DYNAMIC_UINT8_ARRAY_H
22 #define NDN_DYNAMIC_UINT8_ARRAY_H
23 
24 #include <ndn-cpp/c/errors.h>
25 #include "ndn_memory.h"
26 #include <ndn-cpp/c/util/dynamic-uint8-array-types.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
40 static __inline void ndn_DynamicUInt8Array_initialize
41  (struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length,
42  ndn_ReallocFunction reallocFunction)
43 {
44  self->array = array;
45  self->length = length;
46  self->realloc = reallocFunction;
47 }
48 
58 ndn_Error ndn_DynamicUInt8Array_reallocArray
59  (struct ndn_DynamicUInt8Array *self, size_t length);
60 
73 ndn_Error ndn_DynamicUInt8Array_reallocArrayFromBack
74  (struct ndn_DynamicUInt8Array *self, size_t length);
75 
86 static __inline ndn_Error ndn_DynamicUInt8Array_ensureLength
87  (struct ndn_DynamicUInt8Array *self, size_t length)
88 {
89  if (self->length >= length)
90  return NDN_ERROR_success;
91 
92  return ndn_DynamicUInt8Array_reallocArray(self, length);
93 }
94 
104 static __inline ndn_Error ndn_DynamicUInt8Array_copy
105  (struct ndn_DynamicUInt8Array *self, const uint8_t *value, size_t valueLength,
106  size_t offset)
107 {
108  ndn_Error error;
109  if ((error = ndn_DynamicUInt8Array_ensureLength(self, valueLength + offset)))
110  return error;
111  ndn_memcpy(self->array + offset, value, valueLength);
112  return NDN_ERROR_success;
113 };
114 
125 static __inline ndn_Error ndn_DynamicUInt8Array_ensureLengthFromBack
126  (struct ndn_DynamicUInt8Array *self, size_t length)
127 {
128  if (self->length >= length)
129  return NDN_ERROR_success;
130 
131  return ndn_DynamicUInt8Array_reallocArrayFromBack(self, length);
132 }
133 
146 static __inline ndn_Error ndn_DynamicUInt8Array_copyFromBack
147  (struct ndn_DynamicUInt8Array *self, const uint8_t *value, size_t valueLength,
148  size_t offsetFromBack)
149 {
150  ndn_Error error;
151  if ((error = ndn_DynamicUInt8Array_ensureLengthFromBack(self, offsetFromBack)))
152  return error;
153  ndn_memcpy(self->array + (self->length - offsetFromBack), value, valueLength);
154  return NDN_ERROR_success;
155 };
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif
162 
A struct ndn_DynamicUInt8Array holds a pointer to an allocated array, the length of the allocated arr...
Definition: dynamic-uint8-array-types.h:40