Files
json-parser/include/json_value.h
olemorud b3821cf8bf Feature: Use arena-allocation for memory handling
Arena allocation make deallocation of nested structed MUCH faster, and
improves the spatial locality of allocations. It makes no sense to
deallocate only parts of a JSON structure so arenas are a good fit here.
2023-06-05 21:25:40 +02:00

44 lines
908 B
C

#ifndef _JSON_VALUE_H
#define _JSON_VALUE_H
#include "arena.h"
#include "config.h"
#include <stdbool.h> // bool
typedef struct obj_entry {
char const* key;
struct json_value* val;
struct obj_entry* next;
}* __p_obj_entry;
typedef __p_obj_entry obj_t[OBJ_SIZE];
enum json_type { object,
array,
string,
number,
boolean,
null };
struct json_value {
enum json_type type;
union {
obj_t* object;
struct json_value** array; // we need an array of pointers to allow null termination
char* string;
bool boolean;
double number;
};
};
void* obj_at(obj_t m, char* const key);
bool obj_insert(obj_t m, char* const key, struct json_value* value, arena_t* arena);
void obj_delete(obj_t* m, arena_t* arena);
void print_json(struct json_value val, int indent);
void json_value_delete(struct json_value val, arena_t* arena);
#endif