[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: add i64 deserializer
From: |
gnunet |
Subject: |
[gnunet] branch master updated: add i64 deserializer |
Date: |
Sun, 19 Apr 2020 21:43:55 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 254a9f066 add i64 deserializer
new c3b24699c Merge branch 'master' of git+ssh://gnunet.org/gnunet
254a9f066 is described below
commit 254a9f066b2fb96b347ddb07040608eacaf7b942
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Apr 19 21:37:35 2020 +0200
add i64 deserializer
---
src/include/gnunet_json_lib.h | 23 +++++++++++++++----
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);
* @param[out] u8 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8);
+GNUNET_JSON_spec_uint8 (const char *name,
+ uint8_t *u8);
/**
@@ -235,7 +236,8 @@ GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8);
* @param[out] u16 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16);
+GNUNET_JSON_spec_uint16 (const char *name,
+ uint16_t *u16);
/**
@@ -245,7 +247,8 @@ GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16);
* @param[out] u32 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32);
+GNUNET_JSON_spec_uint32 (const char *name,
+ uint32_t *u32);
/**
@@ -255,7 +258,19 @@ GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32);
* @param[out] u64 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64);
+GNUNET_JSON_spec_uint64 (const char *name,
+ uint64_t *u64);
+
+
+/**
+ * 64-bit signed integer.
+ *
+ * @param name name of the JSON field
+ * @param[out] i64 where to store the integer found under @a name
+ */
+struct GNUNET_JSON_Specification
+GNUNET_JSON_spec_int64 (const char *name,
+ int64_t *i64);
/**
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,
/**
- * Parse given JSON object to a uint8_t.
+ * Parse given JSON object to a uint64_t.
*
* @param cls closure, NULL
* @param root the json object representing data
@@ -545,6 +545,57 @@ GNUNET_JSON_spec_uint64 (const char *name,
}
+/**
+ * Parse given JSON object to a int64_t.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static int
+parse_u64 (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ json_int_t val;
+ int64_t *up = spec->ptr;
+
+ if (! json_is_integer (root))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ val = json_integer_value (root);
+ *up = (int64_t) val;
+ return GNUNET_OK;
+}
+
+
+/**
+ * 64-bit signed integer.
+ *
+ * @param name name of the JSON field
+ * @param[out] i64 where to store the integer found under @a name
+ */
+struct GNUNET_JSON_Specification
+GNUNET_JSON_spec_uint64 (const char *name,
+ int64_t *i64)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_i64,
+ .cleaner = NULL,
+ .cls = NULL,
+ .field = name,
+ .ptr = i64,
+ .ptr_size = sizeof(int64_t),
+ .size_ptr = NULL
+ };
+
+ return ret;
+}
+
+
/* ************ GNUnet-specific parser specifications ******************* */
/**
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: add i64 deserializer,
gnunet <=