@@ -172,6 +172,95 @@ typedef int (*json_append_bytes_t)(const u8_t *bytes, size_t len,
172
172
.n_elements = (max_len_), \
173
173
}
174
174
175
+ /**
176
+ * @brief Variant of JSON_OBJ_DESCR_PRIM that can be used when the
177
+ * structure and JSON field names differ.
178
+ *
179
+ * This is useful when the JSON field is not a valid C identifier.
180
+ *
181
+ * @param struct_ Struct packing the values.
182
+ *
183
+ * @param json_field_name_ String, field name in JSON strings
184
+ *
185
+ * @param struct_field_name_ Field name in the struct
186
+ *
187
+ * @param type_ Token type for JSON value corresponding to a primitive
188
+ * type.
189
+ *
190
+ * @see JSON_OBJ_DESCR_PRIM
191
+ */
192
+ #define JSON_OBJ_DESCR_PRIM_NAMED (struct_ , json_field_name_ , \
193
+ struct_field_name_ , type_ ) \
194
+ { \
195
+ .field_name = (json_field_name_), \
196
+ .field_name_len = sizeof(json_field_name_) - 1, \
197
+ .offset = offsetof(struct_, struct_field_name_), \
198
+ .type = type_, \
199
+ }
200
+
201
+ /**
202
+ * @brief Variant of JSON_OBJ_DESCR_OBJECT that can be used when the
203
+ * structure and JSON field names differ.
204
+ *
205
+ * This is useful when the JSON field is not a valid C identifier.
206
+ *
207
+ * @param struct_ Struct packing the values
208
+ *
209
+ * @param json_field_name_ String, field name in JSON strings
210
+ *
211
+ * @param struct_field_name_ Field name in the struct
212
+ *
213
+ * @param sub_descr_ Array of json_obj_descr describing the subobject
214
+ *
215
+ * @see JSON_OBJ_DESCR_OBJECT
216
+ */
217
+ #define JSON_OBJ_DESCR_OBJECT_NAMED (struct_ , json_field_name_ , \
218
+ struct_field_name_ , sub_descr_ ) \
219
+ { \
220
+ .field_name = (json_field_name_), \
221
+ .field_name_len = (sizeof(json_field_name_) - 1), \
222
+ .offset = offsetof(struct_, struct_field_name_), \
223
+ .type = JSON_TOK_OBJECT_START, \
224
+ .sub_descr = sub_descr_, \
225
+ .sub_descr_len = ARRAY_SIZE(sub_descr_) \
226
+ }
227
+
228
+ /**
229
+ * @brief Variant of JSON_OBJ_DESCR_ARRAY that can be used when the
230
+ * structure and JSON field names differ.
231
+ *
232
+ * This is useful when the JSON field is not a valid C identifier.
233
+ *
234
+ * @param struct_ Struct packing the values
235
+ *
236
+ * @param json_field_name_ String, field name in JSON strings
237
+ *
238
+ * @param struct_field_name_ Field name in the struct
239
+ *
240
+ * @param max_len_ Maximum number of elements in array
241
+ *
242
+ * @param len_field_ Field name in the struct for the number of elements
243
+ * in the array
244
+ *
245
+ * @param elem_type_ Element type
246
+ *
247
+ * @see JSON_OBJ_DESCR_ARRAY
248
+ */
249
+ #define JSON_OBJ_DESCR_ARRAY_NAMED (struct_ , json_field_name_ ,\
250
+ struct_field_name_ , max_len_ , len_field_ , \
251
+ elem_type_ ) \
252
+ { \
253
+ .field_name = (json_field_name_), \
254
+ .field_name_len = sizeof(json_field_name_) - 1, \
255
+ .offset = offsetof(struct_, struct_field_name_), \
256
+ .type = JSON_TOK_LIST_START, \
257
+ .element_descr = &(struct json_obj_descr) { \
258
+ .type = elem_type_, \
259
+ .offset = offsetof(struct_, len_field_), \
260
+ }, \
261
+ .n_elements = (max_len_), \
262
+ }
263
+
175
264
/**
176
265
* @brief Parses the JSON-encoded object pointer to by @param json, with
177
266
* size @param len, according to the descriptor pointed to by @param descr.
0 commit comments