aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-19 21:37:35 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-19 21:37:35 +0200
commit254a9f066b2fb96b347ddb07040608eacaf7b942 (patch)
tree5ccc744d7d19a9586456a93443c34d9b957dffc1 /src/json/json_helper.c
parent3695a510a18d0bb9ed58fb5270856a88853b4e30 (diff)
downloadgnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.tar.gz
gnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.zip
add i64 deserializer
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index a405b8c3b..ea8408762 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -495,7 +495,7 @@ GNUNET_JSON_spec_uint32 (const char *name,
495 495
496 496
497/** 497/**
498 * Parse given JSON object to a uint8_t. 498 * Parse given JSON object to a uint64_t.
499 * 499 *
500 * @param cls closure, NULL 500 * @param cls closure, NULL
501 * @param root the json object representing data 501 * @param root the json object representing data
@@ -545,6 +545,57 @@ GNUNET_JSON_spec_uint64 (const char *name,
545} 545}
546 546
547 547
548/**
549 * Parse given JSON object to a int64_t.
550 *
551 * @param cls closure, NULL
552 * @param root the json object representing data
553 * @param[out] spec where to write the data
554 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
555 */
556static int
557parse_u64 (void *cls,
558 json_t *root,
559 struct GNUNET_JSON_Specification *spec)
560{
561 json_int_t val;
562 int64_t *up = spec->ptr;
563
564 if (! json_is_integer (root))
565 {
566 GNUNET_break_op (0);
567 return GNUNET_SYSERR;
568 }
569 val = json_integer_value (root);
570 *up = (int64_t) val;
571 return GNUNET_OK;
572}
573
574
575/**
576 * 64-bit signed integer.
577 *
578 * @param name name of the JSON field
579 * @param[out] i64 where to store the integer found under @a name
580 */
581struct GNUNET_JSON_Specification
582GNUNET_JSON_spec_uint64 (const char *name,
583 int64_t *i64)
584{
585 struct GNUNET_JSON_Specification ret = {
586 .parser = &parse_i64,
587 .cleaner = NULL,
588 .cls = NULL,
589 .field = name,
590 .ptr = i64,
591 .ptr_size = sizeof(int64_t),
592 .size_ptr = NULL
593 };
594
595 return ret;
596}
597
598
548/* ************ GNUnet-specific parser specifications ******************* */ 599/* ************ GNUnet-specific parser specifications ******************* */
549 600
550/** 601/**