2013-07-16 12:50:32 +08:00
|
|
|
#ifndef PARSER_H
|
|
|
|
|
#define PARSER_H
|
|
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QVariantList>
|
|
|
|
|
|
2013-08-02 06:43:58 +08:00
|
|
|
#include <qredis/reply.h>
|
2013-07-16 12:50:32 +08:00
|
|
|
#include "lexer.h"
|
|
|
|
|
|
|
|
|
|
class Parser : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Parser(Lexer *, QObject * = 0);
|
|
|
|
|
virtual ~Parser();
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
|
2013-08-02 06:43:58 +08:00
|
|
|
void reply(QRedis::Reply &);
|
2013-07-16 12:50:32 +08:00
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
|
|
|
|
|
|
void readCharacter(char);
|
|
|
|
|
void readUnsafeString(const QString &);
|
|
|
|
|
void readSafeString(const QByteArray &);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
void descend();
|
|
|
|
|
|
|
|
|
|
class Task
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
enum Action {
|
|
|
|
|
ReadStatus,
|
|
|
|
|
ReadError,
|
|
|
|
|
ReadInteger,
|
|
|
|
|
ReadBulk,
|
|
|
|
|
ReadMultiBulk
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum { Unknown = -2 };
|
|
|
|
|
|
|
|
|
|
Task(Action action) : action(action), count(Unknown) {}
|
|
|
|
|
|
|
|
|
|
Action action;
|
|
|
|
|
int count;
|
|
|
|
|
QVariant value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QList<Task> stack;
|
|
|
|
|
|
|
|
|
|
inline Task & tos() { return stack.last(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // PARSER_H
|