json-parser.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef QAPI_QMP_JSON_PARSER_H
  14. #define QAPI_QMP_JSON_PARSER_H
  15. typedef struct JSONLexer {
  16. int start_state, state;
  17. GString *token;
  18. int x, y;
  19. } JSONLexer;
  20. typedef struct JSONMessageParser {
  21. void (*emit)(void *opaque, QObject *json, Error *err);
  22. void *opaque;
  23. va_list *ap;
  24. JSONLexer lexer;
  25. int brace_count;
  26. int bracket_count;
  27. GQueue tokens;
  28. uint64_t token_size;
  29. } JSONMessageParser;
  30. void json_message_parser_init(JSONMessageParser *parser,
  31. void (*emit)(void *opaque, QObject *json,
  32. Error *err),
  33. void *opaque, va_list *ap);
  34. void json_message_parser_feed(JSONMessageParser *parser,
  35. const char *buffer, size_t size);
  36. void json_message_parser_flush(JSONMessageParser *parser);
  37. void json_message_parser_destroy(JSONMessageParser *parser);
  38. #endif