aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-02-13 12:12:11 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-02-13 12:12:11 +0100
commite906126c4e46ad9f3471aee208f096f55289ca03 (patch)
tree33ba290ef34dfa9bb4cafc064bfa757f3ea4397b
parent89e45c0c97859b4f93095c28784bc2b2c723fc1b (diff)
utils-json: some comments
Change-Id: I5271074c171d6c1fc74706546fc5a7a1073283d5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/utils-json.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils-json.h b/src/utils-json.h
index 5b8ebec..4b86fa9 100644
--- a/src/utils-json.h
+++ b/src/utils-json.h
@@ -16,27 +16,47 @@
limitations under the License.
*/
+/*
+ * predicates on types
+ */
#define j_is_string(o) (json_object_get_type(o) == json_type_string)
#define j_is_boolean(o) (json_object_get_type(o) == json_type_boolean)
#define j_is_integer(o) (json_object_get_type(o) == json_type_int)
+/*
+ * Read the value if object is of the good type and return true.
+ * Returns false if the type is not correct.
+ */
extern int j_read_string(struct json_object *obj, const char **value);
extern int j_read_boolean(struct json_object *obj, int *value);
extern int j_read_integer(struct json_object *obj, int *value);
+/*
+ * Get the value of the type or the default value if the type does not match.
+ */
extern const char *j_string(struct json_object *obj, const char *defval);
extern int j_boolean(struct json_object *obj, int defval);
extern int j_integer(struct json_object *obj, int defval);
+/*
+ * Read the value of the entry of key in object if exist and of the good type and return true.
+ * Returns false if the key does not exist or if the type is not correct.
+ */
extern int j_read_object_at(struct json_object *obj, const char *key, struct json_object **value);
extern int j_read_string_at(struct json_object *obj, const char *key, const char **value);
extern int j_read_boolean_at(struct json_object *obj, const char *key, int *value);
extern int j_read_integer_at(struct json_object *obj, const char *key, int *value);
+/*
+ * Get the value of the key of type or the default value if the key or type does not match.
+ */
extern const char *j_string_at(struct json_object *obj, const char *key, const char *defval);
extern int j_boolean_at(struct json_object *obj, const char *key, int defval);
extern int j_integer_at(struct json_object *obj, const char *key, int defval);
+/*
+ * Adds a keyed value (of type) and returns true if done or false in case of error
+ */
extern int j_add(struct json_object *obj, const char *key, struct json_object *val);
extern int j_add_string(struct json_object *obj, const char *key, const char *val);
extern int j_add_boolean(struct json_object *obj, const char *key, int val);