diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-23 14:42:48 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-23 14:42:48 +0200 |
| commit | 034d197e7eb3749f9f5b347595abdcfe2d086965 (patch) | |
| tree | ba1237cdf7f9a98c39cc79b647baf89221de48be /json.h | |
| parent | b997e31ac151679a516fd76da45bb36931a13e40 (diff) | |
fix(json): Reduce memory usage and fix memory bugs
Diffstat (limited to 'json.h')
| -rw-r--r-- | json.h | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -9,16 +9,27 @@ typedef struct { Vec values; // Vec<JSON> size len; } JSONObject; +typedef enum { + JSON_NULL, + JSON_BOOL, + JSON_INTEGER, + JSON_FLOAT, + JSON_STRING, + JSON_ARRAY, + JSON_OBJECT +} JSONType; typedef struct { - i32 *boolean; - i32 *integer; - f32 *floating; - Vec *array; // Vec<JSON> - Str *string; - void *null; - JSONObject *object; + JSONType type; + union { + bool boolean; + i32 integer; + f32 floating; + Vec array; // Vec<JSON> + Str string; + JSONObject object; + } as; } JSON; -JSON *JSONObject_get(JSONObject *obj, Str key); +JSON *JSONObject_get(JSONObject obj, Str key); i32 JSON_fprint(FILE *w, JSON json); JSON JSON_parse(Arena *a, byte *src); JSON JSON_Int(Arena *a, i32 val); |
