From 57b46d5123084a42a2936e9014a43115d0dc070f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 10 Jul 2012 01:42:42 +0900 Subject: Added streaming parser for structured data format. Added JSON streaming parser. Note that currently JSON parser ignores frac and exp parts of number construct. --- src/StructParserStateMachine.h | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/StructParserStateMachine.h (limited to 'src/StructParserStateMachine.h') diff --git a/src/StructParserStateMachine.h b/src/StructParserStateMachine.h new file mode 100644 index 00000000..a30cc4d7 --- /dev/null +++ b/src/StructParserStateMachine.h @@ -0,0 +1,70 @@ +/* */ +#ifndef D_STRUCT_PARSER_STATE_MACHINE_H +#define D_STRUCT_PARSER_STATE_MACHINE_H + +#include "common.h" + +namespace aria2 { + +enum StructElementType { + STRUCT_DICT_T, + STRUCT_DICT_KEY_T, + STRUCT_DICT_DATA_T, + STRUCT_ARRAY_T, + STRUCT_ARRAY_DATA_T, + STRUCT_STRING_T, + STRUCT_NUMBER_T, + STRUCT_BOOL_T, + STRUCT_NULL_T +}; + +// Interface for streaming parser of structured data format (e.g., +// JSON, Bencode). +class StructParserStateMachine { +public: + virtual ~StructParserStateMachine() {} + + virtual void beginElement(int elementType) = 0; + virtual void endElement(int elementType) = 0; + virtual void reset() = 0; + virtual void charactersCallback(const char* data, size_t len) = 0; + virtual void numberCallback(int64_t number, int frac, int exp) = 0; + virtual void boolCallback(bool bval) = 0; +}; + +} // namespace aria2 + +#endif // D_STRUCT_PARSER_STATE_MACHINE_H -- cgit