Tchatator413
TripEnArvor instant messaging protocol - JSON-based
Loading...
Searching...
No Matches
json-helpers.h
Go to the documentation of this file.
1
5
6#ifndef JSON_HELPERS
7#define JSON_HELPERS
8
9#include "slice.h"
10#include <json-c.h>
11#include <stdbool.h>
12#include <stdint.h>
13
15#define min_json(obj) json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)
16
18#define json_object_dbg_print(obj) fprintf(stderr, "json_object_dbg_print: %s\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY))
19
21// json_util_get_last_err includes a \n
22#define LOG_FMT_JSON_C(fmt, ...) "json-c: " fmt ": %s" __VA_OPT__(, ) __VA_ARGS__, json_util_get_last_err()
23
25#define LOG_FMT_JSON_TYPE(type, actual, fmt, ...) "json: " fmt ": type: expected %s, got %s\n" __VA_OPT__(, ) __VA_ARGS__, json_type_to_name(type), json_type_to_name(actual)
26
27// JSON-C performs type coercion when getting values of the wrong type. That's confusing. We don't want that.
28// Creating explicit "strict" variants of each necessary getter function.
29
36bool json_object_get_uint16_strict(json_object const *obj, uint16_t *out);
37
44bool json_object_get_int_strict(json_object const *obj, int32_t *out);
45
52bool json_object_get_int64_strict(json_object const *obj, int64_t *out);
53
59bool json_object_get_string_strict(json_object *obj, slice_t *out);
60
61#endif // JSON_HELPERS
json-c wrapper. Include this instead of JSON-C (compile time error mechanisms)
bool json_object_get_int_strict(json_object const *obj, int32_t *out)
Get the 32-bit integer value of a JSON object.
bool json_object_get_uint16_strict(json_object const *obj, uint16_t *out)
Get the 16-bit unsigned integer value of a JSON object.
bool json_object_get_int64_strict(json_object const *obj, int64_t *out)
Get the 64-bit integer value of a JSON object.
bool json_object_get_string_strict(json_object *obj, slice_t *out)
Get the string value of a JSON object.
slice data strucutre - Interface
A memory slice.
Definition slice.h:12