| 430 * Typedef for the json status enum. |
430 * Typedef for the json status enum. |
| 431 */ |
431 */ |
| 432 typedef enum cx_json_status CxJsonStatus; |
432 typedef enum cx_json_status CxJsonStatus; |
| 433 |
433 |
| 434 /** |
434 /** |
| |
435 * The JSON writer settings. |
| |
436 */ |
| |
437 struct cx_json_writer_s { |
| |
438 bool pretty; |
| |
439 bool sort_members; |
| |
440 uint8_t frac_max_digits; |
| |
441 bool indent_space; |
| |
442 uint8_t indent; |
| |
443 bool wrap_array; |
| |
444 uint16_t wrap_threshold; |
| |
445 }; |
| |
446 |
| |
447 /** |
| |
448 * Typedef for the json writer. |
| |
449 */ |
| |
450 typedef struct cx_json_writer_s CxJsonWriter; |
| |
451 |
| |
452 |
| |
453 /** |
| |
454 * Writes a JSON value to a buffer or stream. |
| |
455 * |
| |
456 * This function blocks until all data is written or an error when trying |
| |
457 * to write data occurs. |
| |
458 * The write operation is not atomic in the sense that it might happen |
| |
459 * that the data is only partially written when an error occurs with no |
| |
460 * way to indicate how much data was written. |
| |
461 * To avoid this problem, you can use a CxBuffer as \p target which is |
| |
462 * unlikely to fail a write operation and either use the buffer's flush |
| |
463 * feature to relay the data or use the data in the buffer manually to |
| |
464 * write it to the actual target. |
| |
465 * |
| |
466 * @param target the buffer or stream where to write to |
| |
467 * @param value the value that shall be written |
| |
468 * @param wfunc the write function to use |
| |
469 * @param settings formatting settings (or \c NULL to use a compact default) |
| |
470 * @return zero on success, non-zero when no or not all data could be written |
| |
471 */ |
| |
472 cx_attr_nonnull_arg(1, 2, 3) |
| |
473 int cxJsonWrite( |
| |
474 void* target, |
| |
475 const CxJsonValue* value, |
| |
476 cx_write_func wfunc, |
| |
477 const CxJsonWriter* settings |
| |
478 ); |
| |
479 |
| |
480 /** |
| 435 * Initializes the json interface. |
481 * Initializes the json interface. |
| 436 * |
482 * |
| 437 * @param json the json interface |
483 * @param json the json interface |
| 438 * @param allocator the allocator that shall be used for the produced values |
484 * @param allocator the allocator that shall be used for the produced values |
| 439 * @see cxJsonDestroy() |
485 * @see cxJsonDestroy() |
| 1148 cx_attr_nonnull |
1194 cx_attr_nonnull |
| 1149 cx_attr_nodiscard |
1195 cx_attr_nodiscard |
| 1150 CxIterator cxJsonArrIter(const CxJsonValue *value); |
1196 CxIterator cxJsonArrIter(const CxJsonValue *value); |
| 1151 |
1197 |
| 1152 /** |
1198 /** |
| |
1199 * Returns an iterator over the JSON object members. |
| |
1200 * |
| |
1201 * The iterator yields values of type \c CxJsonObjValue* which |
| |
1202 * contain the name and value of the member. |
| |
1203 * |
| |
1204 * If the \p value is not a JSON object, the behavior is undefined. |
| |
1205 * |
| |
1206 * @param value the JSON value |
| |
1207 * @return an iterator over the object members |
| |
1208 * @see cxJsonIsObject() |
| |
1209 */ |
| |
1210 cx_attr_nonnull |
| |
1211 cx_attr_nodiscard |
| |
1212 CxIterator cxJsonObjIter(const CxJsonValue *value); |
| |
1213 |
| |
1214 /** |
| 1153 * @copydoc cxJsonObjGet() |
1215 * @copydoc cxJsonObjGet() |
| 1154 */ |
1216 */ |
| 1155 cx_attr_nonnull |
1217 cx_attr_nonnull |
| 1156 cx_attr_returns_nonnull |
1218 cx_attr_returns_nonnull |
| 1157 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); |
1219 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); |