-
Notifications
You must be signed in to change notification settings - Fork 24
/
serialization.h
63 lines (47 loc) · 1.49 KB
/
serialization.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 Cutehacks AS. All rights reserved.
// License can be found in the LICENSE file.
#ifndef SERIALIZATION_H
#define SERIALIZATION_H
#include <QtQml/QJSValue>
#include "qpm.h"
class QQmlEngine;
namespace com { namespace cutehacks { namespace duperagent {
typedef QList<QPair<QString, QString> > QueryItems;
class BodyCodec
{
public:
virtual QByteArray stringify(const QJSValue&) = 0;
virtual QJSValue parse(const QByteArray&) = 0;
protected:
BodyCodec(QQmlEngine *);
QQmlEngine *m_engine;
};
class JsonCodec : public BodyCodec
{
public:
JsonCodec(QQmlEngine *);
QByteArray stringify(const QJSValue &);
QJSValue parse(const QByteArray &);
protected:
QJSValue parseJsonDocument(const QJsonDocument &);
QJSValue parseJsonArray(const QJsonArray &);
QJSValue parseJsonObject(const QJsonObject &);
QJSValue parseJsonValue(const QJsonValue &);
QJsonObject stringifyObject(const QJSValue &) const;
QJsonArray stringifyArray(const QJSValue &) const;
QJsonValue stringifyValue(const QJSValue &) const;
};
class FormUrlEncodedCodec : public BodyCodec
{
public:
FormUrlEncodedCodec(QQmlEngine *);
public:
QByteArray stringify(const QJSValue &);
QJSValue parse(const QByteArray &);
protected:
QueryItems stringifyObject(const QString&, const QJSValue &) const;
QueryItems stringifyArray(const QString&, const QJSValue &) const;
QueryItems stringifyValue(const QString&, const QJSValue &) const;
};
} } }
#endif // SERIALIZATION_H