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/ValueBaseStructParserStateMachine.h | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/ValueBaseStructParserStateMachine.h (limited to 'src/ValueBaseStructParserStateMachine.h') diff --git a/src/ValueBaseStructParserStateMachine.h b/src/ValueBaseStructParserStateMachine.h new file mode 100644 index 00000000..30143181 --- /dev/null +++ b/src/ValueBaseStructParserStateMachine.h @@ -0,0 +1,116 @@ +/* */ +#ifndef D_VALUE_BASE_STRUCT_PARSER_STATE_MACHINE_H +#define D_VALUE_BASE_STRUCT_PARSER_STATE_MACHINE_H + +#include "StructParserStateMachine.h" + +#include +#include + +#include "SharedHandle.h" + +namespace aria2 { + +class ValueBase; + +namespace rpc { +class XmlRpcRequestParserController; +} // namespace rpc; + +class ValueBaseStructParserState; + +// Implementation of StructParserStateMachine, using ValueBase as +// value holder. +class ValueBaseStructParserStateMachine : public StructParserStateMachine { +public: + typedef SharedHandle ResultType; + static const SharedHandle noResult; + + struct NumberData { + int64_t number; + int frac; + int exp; + }; + + struct SessionData { + std::string str; + NumberData number; + bool bval; + }; + + ValueBaseStructParserStateMachine(); + virtual ~ValueBaseStructParserStateMachine(); + + virtual void beginElement(int elementType); + virtual void endElement(int elementType); + + virtual void charactersCallback(const char* data, size_t len); + virtual void numberCallback(int64_t number, int frac, int exp); + virtual void boolCallback(bool bval); + + SharedHandle getResult() const; + + virtual void reset(); + + const std::string& getCharacters() const; + const NumberData& getNumber() const; + bool getBool() const; + + void popArrayFrame(); + void popDictFrame(); + void pushFrame(); + void setCurrentFrameValue(const SharedHandle& value); + const SharedHandle& getCurrentFrameValue() const; + void setCurrentFrameName(const std::string& name); + + void pushDictState(); + void pushDictKeyState(); + void pushDictDataState(); + void pushArrayState(); + void pushArrayDataState(); + void pushStringState(); + void pushNumberState(); + void pushBoolState(); + void pushNullState(); +private: + rpc::XmlRpcRequestParserController* ctrl_; + std::stack stateStack_; + SessionData sessionData_; +}; + +} // namespace aria2 + +#endif // D_VALUE_BASE_STRUCT_PARSER_STATE_MACHINE_H -- cgit