master
h 54 lines 1.33 KB
Raw
1 /*
2 * JSON Parser
3 *
4 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
14 #ifndef QAPI_QMP_JSON_PARSER_H
15 #define QAPI_QMP_JSON_PARSER_H
16
17 typedef struct JSONLexer {
18 int start_state, state;
19 GString *token;
20 int cur_x, cur_y;
21 int x, y;
22 } JSONLexer;
23
24 typedef struct JSONParserContext {
25 Error *err;
26 GQueue *stack;
27 va_list *ap;
28 } JSONParserContext;
29
30 typedef struct JSONMessageParser {
31 void (*emit)(void *opaque, QObject *json, Error *err);
32 void *opaque;
33 JSONLexer lexer;
34 JSONParserContext parser;
35 unsigned int brace_count;
36 unsigned int bracket_count;
37 unsigned int token_count;
38 bool error;
39 uint64_t token_size;
40 } JSONMessageParser;
41
42 void json_message_parser_init(JSONMessageParser *parser,
43 void (*emit)(void *opaque, QObject *json,
44 Error *err),
45 void *opaque, va_list *ap);
46
47 void json_message_parser_feed(JSONMessageParser *parser,
48 const char *buffer, size_t size);
49
50 void json_message_parser_flush(JSONMessageParser *parser);
51
52 void json_message_parser_destroy(JSONMessageParser *parser);
53
54 #endif