-
Notifications
You must be signed in to change notification settings - Fork 45
/
json.c
82 lines (73 loc) · 1.61 KB
/
json.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "json.h"
nsq_json_tokener_t *nsq_json_tokener_new()
{
#ifdef WITH_JANSSON
return NULL;
#else
return json_tokener_new();
#endif
}
void nsq_json_tokener_free(nsq_json_tokener_t *jstok)
{
#ifndef WITH_JANSSON
json_tokener_free(jstok);
#endif
}
int nsq_json_decref(nsq_json_t *jsobj)
{
#ifdef WITH_JANSSON
json_decref(jsobj);
return 0;
#else
return json_object_put(jsobj);
#endif
}
nsq_json_t *nsq_json_loadb(const char *buf, const nsq_json_size_t buflen, const size_t flags, nsq_json_tokener_t *jstok)
{
#ifdef WITH_JANSSON
return json_loadb(buf, (size_t)buflen, flags, NULL);
#else
return json_tokener_parse_ex(jstok, buf, (int)buflen);
#endif
}
nsq_json_size_t nsq_json_array_length(nsq_json_t *array)
{
#ifdef WITH_JANSSON
return json_array_size(array);
#else
return json_object_array_length(array);
#endif
}
nsq_json_t *nsq_json_array_get(nsq_json_t *array, const nsq_json_size_t idx)
{
#ifdef WITH_JANSSON
return json_array_get(array, idx);
#else
return json_object_array_get_idx(array, idx);
#endif
}
int nsq_json_object_get(nsq_json_t *jsobj, const char *key, nsq_json_t **value)
{
#ifdef WITH_JANSSON
*value = json_object_get(jsobj, key);
return *value != NULL;
#else
return json_object_object_get_ex(jsobj, key, value);
#endif
}
const char *nsq_json_string_value(nsq_json_t *jsobj)
{
#ifdef WITH_JANSSON
return json_string_value(jsobj);
#else
return json_object_get_string(jsobj);
#endif
}
nsq_json_int_t nsq_json_int_value(nsq_json_t *jsobj)
{
#ifdef WITH_JANSSON
return json_integer_value(jsobj);
#else
return json_object_get_int(jsobj);
#endif
}