|
| 1 | +module main |
| 2 | + |
| 3 | +import json |
| 4 | + |
| 5 | +struct UseJson { |
| 6 | + x int |
| 7 | +} |
| 8 | + |
| 9 | +fn suppress_json_warning() { |
| 10 | + json.encode(UseJson{}) |
| 11 | +} |
| 12 | + |
| 13 | +// struct C.cJSON {} |
| 14 | +fn C.cJSON_CreateObject() &C.cJSON |
| 15 | + |
| 16 | +fn C.cJSON_CreateArray() &C.cJSON |
| 17 | + |
| 18 | +// fn C.cJSON_CreateBool(bool) &C.cJSON |
| 19 | +fn C.cJSON_CreateTrue() &C.cJSON |
| 20 | + |
| 21 | +fn C.cJSON_CreateFalse() &C.cJSON |
| 22 | + |
| 23 | +fn C.cJSON_CreateNull() &C.cJSON |
| 24 | + |
| 25 | +// fn C.cJSON_CreateNumber() &C.cJSON |
| 26 | +// fn C.cJSON_CreateString() &C.cJSON |
| 27 | +fn C.cJSON_CreateRaw(&u8) &C.cJSON |
| 28 | + |
| 29 | +fn C.cJSON_IsInvalid(voidptr) bool |
| 30 | + |
| 31 | +fn C.cJSON_IsFalse(voidptr) bool |
| 32 | + |
| 33 | +// fn C.cJSON_IsTrue(voidptr) bool |
| 34 | +fn C.cJSON_IsBool(voidptr) bool |
| 35 | + |
| 36 | +fn C.cJSON_IsNull(voidptr) bool |
| 37 | + |
| 38 | +fn C.cJSON_IsNumber(voidptr) bool |
| 39 | + |
| 40 | +fn C.cJSON_IsString(voidptr) bool |
| 41 | + |
| 42 | +fn C.cJSON_IsArray(voidptr) bool |
| 43 | + |
| 44 | +fn C.cJSON_IsObject(voidptr) bool |
| 45 | + |
| 46 | +fn C.cJSON_IsRaw(voidptr) bool |
| 47 | + |
| 48 | +fn C.cJSON_AddItemToObject(voidptr, &u8, voidptr) |
| 49 | + |
| 50 | +fn C.cJSON_AddItemToArray(voidptr, voidptr) |
| 51 | + |
| 52 | +fn C.cJSON_Delete(voidptr) |
| 53 | + |
| 54 | +fn C.cJSON_Print(voidptr) &u8 |
| 55 | + |
| 56 | +@[inline] |
| 57 | +fn create_object() &C.cJSON { |
| 58 | + return C.cJSON_CreateObject() |
| 59 | +} |
| 60 | + |
| 61 | +@[inline] |
| 62 | +fn create_array() &C.cJSON { |
| 63 | + return C.cJSON_CreateArray() |
| 64 | +} |
| 65 | + |
| 66 | +@[inline] |
| 67 | +fn create_string(val string) &C.cJSON { |
| 68 | + return C.cJSON_CreateString(val.str) |
| 69 | +} |
| 70 | + |
| 71 | +@[inline] |
| 72 | +fn create_number(val f64) &C.cJSON { |
| 73 | + return C.cJSON_CreateNumber(val) |
| 74 | +} |
| 75 | + |
| 76 | +@[inline] |
| 77 | +fn create_bool(val bool) &C.cJSON { |
| 78 | + return C.cJSON_CreateBool(val) |
| 79 | +} |
| 80 | + |
| 81 | +@[inline] |
| 82 | +fn create_true() &C.cJSON { |
| 83 | + return C.cJSON_CreateTrue() |
| 84 | +} |
| 85 | + |
| 86 | +@[inline] |
| 87 | +fn create_false() &C.cJSON { |
| 88 | + return C.cJSON_CreateFalse() |
| 89 | +} |
| 90 | + |
| 91 | +@[inline] |
| 92 | +fn create_null() &C.cJSON { |
| 93 | + return C.cJSON_CreateNull() |
| 94 | +} |
| 95 | + |
| 96 | +@[inline] |
| 97 | +fn delete(b voidptr) { |
| 98 | + C.cJSON_Delete(b) |
| 99 | +} |
| 100 | + |
| 101 | +@[inline] |
| 102 | +fn add_item_to_object(obj &C.cJSON, key string, item &C.cJSON) { |
| 103 | + C.cJSON_AddItemToObject(obj, key.str, item) |
| 104 | +} |
| 105 | + |
| 106 | +@[inline] |
| 107 | +fn add_item_to_array(obj &C.cJSON, item &C.cJSON) { |
| 108 | + C.cJSON_AddItemToArray(obj, item) |
| 109 | +} |
| 110 | + |
| 111 | +fn json_print(json_ &C.cJSON) string { |
| 112 | + s := C.cJSON_Print(json_) |
| 113 | + return unsafe { tos3(s) } |
| 114 | +} |
0 commit comments