xref: /qemu/include/qapi/qmp/json-parser.h (revision abff1abf)
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 x, y;
21 } JSONLexer;
22 
23 typedef struct JSONMessageParser {
24     void (*emit)(void *opaque, QObject *json, Error *err);
25     void *opaque;
26     va_list *ap;
27     JSONLexer lexer;
28     int brace_count;
29     int bracket_count;
30     GQueue tokens;
31     uint64_t token_size;
32 } JSONMessageParser;
33 
34 void json_message_parser_init(JSONMessageParser *parser,
35                               void (*emit)(void *opaque, QObject *json,
36                                            Error *err),
37                               void *opaque, va_list *ap);
38 
39 void json_message_parser_feed(JSONMessageParser *parser,
40                              const char *buffer, size_t size);
41 
42 void json_message_parser_flush(JSONMessageParser *parser);
43 
44 void json_message_parser_destroy(JSONMessageParser *parser);
45 
46 #endif
47