diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-19 21:37:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-19 21:37:35 +0200 |
commit | 254a9f066b2fb96b347ddb07040608eacaf7b942 (patch) | |
tree | 5ccc744d7d19a9586456a93443c34d9b957dffc1 /src | |
parent | 3695a510a18d0bb9ed58fb5270856a88853b4e30 (diff) | |
download | gnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.tar.gz gnunet-254a9f066b2fb96b347ddb07040608eacaf7b942.zip |
add i64 deserializer
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_json_lib.h | 23 | ||||
-rw-r--r-- | src/json/json_helper.c | 53 |
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 | */ |
227 | struct GNUNET_JSON_Specification | 227 | struct GNUNET_JSON_Specification |
228 | GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); | 228 | GNUNET_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 | */ |
237 | struct GNUNET_JSON_Specification | 238 | struct GNUNET_JSON_Specification |
238 | GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); | 239 | GNUNET_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 | */ |
247 | struct GNUNET_JSON_Specification | 249 | struct GNUNET_JSON_Specification |
248 | GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); | 250 | GNUNET_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 | */ |
257 | struct GNUNET_JSON_Specification | 260 | struct GNUNET_JSON_Specification |
258 | GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); | 261 | GNUNET_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 | */ | ||
271 | struct GNUNET_JSON_Specification | ||
272 | GNUNET_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 | */ | ||
556 | static int | ||
557 | parse_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 | */ | ||
581 | struct GNUNET_JSON_Specification | ||
582 | GNUNET_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 | /** |