aboutsummaryrefslogtreecommitdiff
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
parent3695a510a18d0bb9ed58fb5270856a88853b4e30 (diff)
downloadgnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.tar.gz
gnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.zip
add i64 deserializer
-rw-r--r--src/include/gnunet_json_lib.h23
-rw-r--r--src/json/json_helper.c53
2 files changed, 71 insertions, 5 deletions
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 82b8502e0..f6cabd589 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -225,7 +225,8 @@ GNUNET_JSON_spec_json (const char *name, json_t **jsonp);
225 * @param[out] u8 where to store the integer found under @a name 225 * @param[out] u8 where to store the integer found under @a name
226 */ 226 */
227struct GNUNET_JSON_Specification 227struct GNUNET_JSON_Specification
228GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); 228GNUNET_JSON_spec_uint8 (const char *name,
229 uint8_t *u8);
229 230
230 231
231/** 232/**
@@ -235,7 +236,8 @@ GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8);
235 * @param[out] u16 where to store the integer found under @a name 236 * @param[out] u16 where to store the integer found under @a name
236 */ 237 */
237struct GNUNET_JSON_Specification 238struct GNUNET_JSON_Specification
238GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); 239GNUNET_JSON_spec_uint16 (const char *name,
240 uint16_t *u16);
239 241
240 242
241/** 243/**
@@ -245,7 +247,8 @@ GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16);
245 * @param[out] u32 where to store the integer found under @a name 247 * @param[out] u32 where to store the integer found under @a name
246 */ 248 */
247struct GNUNET_JSON_Specification 249struct GNUNET_JSON_Specification
248GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); 250GNUNET_JSON_spec_uint32 (const char *name,
251 uint32_t *u32);
249 252
250 253
251/** 254/**
@@ -255,7 +258,19 @@ GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32);
255 * @param[out] u64 where to store the integer found under @a name 258 * @param[out] u64 where to store the integer found under @a name
256 */ 259 */
257struct GNUNET_JSON_Specification 260struct GNUNET_JSON_Specification
258GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); 261GNUNET_JSON_spec_uint64 (const char *name,
262 uint64_t *u64);
263
264
265/**
266 * 64-bit signed integer.
267 *
268 * @param name name of the JSON field
269 * @param[out] i64 where to store the integer found under @a name
270 */
271struct GNUNET_JSON_Specification
272GNUNET_JSON_spec_int64 (const char *name,
273 int64_t *i64);
259 274
260 275
261/** 276/**
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/**