aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 515cc4c7f..4795285f4 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -490,6 +490,49 @@ GNUNET_JSON_spec_bool (const char *name,
490 490
491 491
492/** 492/**
493 * Parse given JSON object to a double.
494 *
495 * @param cls closure, NULL
496 * @param root the json object representing data
497 * @param[out] spec where to write the data
498 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
499 */
500static enum GNUNET_GenericReturnValue
501parse_double (void *cls,
502 json_t *root,
503 struct GNUNET_JSON_Specification *spec)
504{
505 double *f = spec->ptr;
506
507 if (! json_is_real (root))
508 {
509 GNUNET_break_op (0);
510 return GNUNET_SYSERR;
511 }
512 *f = json_real_value (root);
513 return GNUNET_OK;
514}
515
516
517struct GNUNET_JSON_Specification
518GNUNET_JSON_spec_double (const char *name,
519 double *f)
520{
521 struct GNUNET_JSON_Specification ret = {
522 .parser = &parse_double,
523 .cleaner = NULL,
524 .cls = NULL,
525 .field = name,
526 .ptr = f,
527 .ptr_size = sizeof(double),
528 .size_ptr = NULL
529 };
530
531 return ret;
532}
533
534
535/**
493 * Parse given JSON object to a uint8_t. 536 * Parse given JSON object to a uint8_t.
494 * 537 *
495 * @param cls closure, NULL 538 * @param cls closure, NULL