2022-07-23 00:19:12 +00:00
|
|
|
#ifndef TELODENDRIA_JSON_H
|
|
|
|
#define TELODENDRIA_JSON_H
|
|
|
|
|
|
|
|
#include <HashMap.h>
|
|
|
|
#include <Array.h>
|
|
|
|
|
2022-07-25 19:25:06 +00:00
|
|
|
typedef enum JsonType
|
|
|
|
{
|
2022-07-23 00:19:12 +00:00
|
|
|
JSON_OBJECT,
|
|
|
|
JSON_ARRAY,
|
|
|
|
JSON_STRING,
|
|
|
|
JSON_INTEGER,
|
|
|
|
JSON_FLOAT,
|
|
|
|
JSON_BOOLEAN,
|
|
|
|
JSON_NULL
|
|
|
|
} JsonType;
|
|
|
|
|
2022-07-25 19:25:06 +00:00
|
|
|
typedef struct JsonValue
|
|
|
|
{
|
2022-07-23 00:19:12 +00:00
|
|
|
JsonType type;
|
2022-07-25 19:25:06 +00:00
|
|
|
union as
|
|
|
|
{
|
2022-07-23 00:19:12 +00:00
|
|
|
HashMap *object;
|
|
|
|
Array *array;
|
|
|
|
char *string;
|
|
|
|
int64_t integer;
|
|
|
|
double floating;
|
2022-07-25 19:25:06 +00:00
|
|
|
int boolean:1;
|
2022-07-23 00:19:12 +00:00
|
|
|
};
|
|
|
|
} JsonValue;
|
|
|
|
|
|
|
|
|
|
|
|
extern JsonType
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueType(JsonValue * value);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueObject(HashMap * object);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern HashMap *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueAsObject(JsonValue * value);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueArray(Array * array);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern Array *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueAsArray(JsonValue * value);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueString(char *string);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueInteger(int64_t integer);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueFloat(double floating);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueBoolean(int boolean);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern JsonValue *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueNull(void);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern void *
|
2022-07-25 19:25:06 +00:00
|
|
|
JsonValueFree(JsonValue * value);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
2022-07-25 20:26:30 +00:00
|
|
|
extern int
|
|
|
|
JsonEncode(HashMap * object, FILE * out);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
extern HashMap *
|
2022-07-25 20:26:30 +00:00
|
|
|
JsonDecode(FILE * in);
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
#endif
|