1 | // SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net> |
2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | |
4 | #include "requestdata.h" |
5 | |
6 | #include <QtCore/QIODevice> |
7 | #include <QtCore/QBuffer> |
8 | #include <QtCore/QByteArray> |
9 | #include <QtCore/QJsonArray> |
10 | #include <QtCore/QJsonDocument> |
11 | #include <QtCore/QJsonObject> |
12 | |
13 | using namespace Quotient; |
14 | |
15 | auto fromData(const QByteArray& data) |
16 | { |
17 | auto source = makeImpl<QBuffer, QIODevice>(); |
18 | source->setData(data); |
19 | source->open(openMode: QIODevice::ReadOnly); |
20 | return source; |
21 | } |
22 | |
23 | template <typename JsonDataT> |
24 | inline auto fromJson(const JsonDataT& jdata) |
25 | { |
26 | return fromData(data: QJsonDocument(jdata).toJson(format: QJsonDocument::Compact)); |
27 | } |
28 | |
29 | RequestData::RequestData(const QByteArray& a) : _source(fromData(data: a)) {} |
30 | |
31 | RequestData::RequestData(const QJsonObject& jo) : _source(fromJson(jdata: jo)) {} |
32 | |
33 | RequestData::RequestData(const QJsonArray& ja) : _source(fromJson(jdata: ja)) {} |
34 | |
35 | RequestData::RequestData(QIODevice* source) |
36 | : _source(acquireImpl(from: source)) |
37 | {} |
38 | |