-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmjson.h
More file actions
85 lines (63 loc) · 2.52 KB
/
mjson.h
File metadata and controls
85 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* mjson - modified json parser
* syntax changes:
* - no {} needed around the whole file
* - "=" is allowed instead of ":"
* - quotes around the key are optional
* - commas after values are optional
* - and c-style comments allowed
*
* intermediate storage is based on ideas from BJSON specification: http://bjson.org
*
* some code ideas are borrowed from another json parser: https://github.com/megous/sjson
*/
#ifndef __MJSON_H_INCLUDED__
#define __MJSON_H_INCLUDED__
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct _mjson_entry_t;
typedef const struct _mjson_entry_t* mjson_element_t;
enum mjson_element_id_t
{
MJSON_ID_NULL = 0,
MJSON_ID_FALSE = 1,
MJSON_ID_EMPTY_STRING = 2,
MJSON_ID_TRUE = 3,
MJSON_ID_UINT32 = 4,
MJSON_ID_UINT64 = 5,
MJSON_ID_SINT32 = 6,
MJSON_ID_SINT64 = 7,
MJSON_ID_FLOAT32 = 8,
MJSON_ID_FLOAT64 = 9,
MJSON_ID_UTF8_KEY32 = 10,
MJSON_ID_UTF8_KEY64 = 11,
MJSON_ID_UTF8_STRING32 = 12,
MJSON_ID_UTF8_STRING64 = 13,
MJSON_ID_BINARY32 = 14,
MJSON_ID_BINARY64 = 15,
MJSON_ID_ARRAY32 = 16,
MJSON_ID_ARRAY64 = 17,
MJSON_ID_DICT32 = 18,
MJSON_ID_DICT64 = 19
};
int mjson_parse(const char *json_data, size_t json_data_size, void* storage_buf, size_t storage_buf_size, mjson_element_t* top_element);
mjson_element_t mjson_get_top_element(void* storage_buf, size_t storage_buf_size);
mjson_element_t mjson_get_element_first(mjson_element_t array);
mjson_element_t mjson_get_element_next (mjson_element_t array, mjson_element_t current_value);
mjson_element_t mjson_get_element (mjson_element_t array, int index);
mjson_element_t mjson_get_member_first(mjson_element_t dictionary, mjson_element_t* value);
mjson_element_t mjson_get_member_next (mjson_element_t dictionary, mjson_element_t current_key, mjson_element_t* next_value);
mjson_element_t mjson_get_member (mjson_element_t dictionary, const char* name);
int mjson_get_type(mjson_element_t element);
const char* mjson_get_string(mjson_element_t element, const char* fallback);
int32_t mjson_get_int (mjson_element_t element, int32_t fallback);
float mjson_get_float (mjson_element_t element, float fallback);
int mjson_get_bool (mjson_element_t element, int fallback);
int mjson_is_null (mjson_element_t element);
#ifdef __cplusplus
}
#endif
#endif