@@ -7,6 +7,7 @@ module json
7
7
#flag @VROOT/thirdparty/cJSON/cJSON.o
8
8
#include "cJSON.h"
9
9
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))
10
+
10
11
struct C.cJSON {
11
12
valueint int
12
13
valuedouble f32
@@ -23,6 +24,11 @@ pub fn encode(x voidptr) string {
23
24
return ''
24
25
}
25
26
27
+ pub fn encode_pretty (x voidptr ) string {
28
+ // compiler implementation
29
+ return ''
30
+ }
31
+
26
32
fn decode_int (root & C.cJSON) int {
27
33
if isnil (root) {
28
34
return 0
@@ -107,21 +113,17 @@ fn decode_string(root &C.cJSON) string {
107
113
108
114
fn C.cJSON_IsTrue (voidptr ) bool
109
115
110
-
111
116
fn C.cJSON_CreateNumber (int ) & C.cJSON
112
117
113
-
114
118
fn C.cJSON_CreateBool (bool ) & C.cJSON
115
119
116
-
117
120
fn C.cJSON_CreateString (charptr ) & C.cJSON
118
121
119
-
120
122
fn C.cJSON_Parse (charptr ) & C.cJSON
121
123
122
-
123
124
fn C.cJSON_PrintUnformatted (voidptr ) byteptr
124
125
126
+ fn C.cJSON_Print (voidptr ) byteptr
125
127
126
128
fn decode_bool (root & C.cJSON) bool {
127
129
if isnil (root) {
@@ -178,6 +180,7 @@ fn encode_bool(val bool) &C.cJSON {
178
180
fn encode_string (val string ) & C.cJSON {
179
181
return C.cJSON_CreateString (val.str)
180
182
}
183
+
181
184
// ///////////////////////
182
185
// user := decode_User(json_parse(js_string_var))
183
186
fn json_parse (s string ) & C.cJSON {
@@ -190,6 +193,11 @@ fn json_print(json &C.cJSON) string {
190
193
return unsafe { tos (s, C.strlen (s)) }
191
194
}
192
195
196
+ fn json_print_pretty (json & C.cJSON) string {
197
+ s := C.cJSON_Print (json)
198
+ return unsafe { tos (s, C.strlen (s)) }
199
+ }
200
+
193
201
// / cjson wrappers
194
202
// fn json_array_for_each(val, root &C.cJSON) {
195
203
// #cJSON_ArrayForEach (val ,root)
0 commit comments