2018-07-07 13:08:57 +02:00
|
|
|
#include "common/NetworkResult.hpp"
|
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "common/QLogging.hpp"
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
2018-07-07 13:08:57 +02:00
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include <rapidjson/error/en.h>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2019-09-19 19:03:50 +02:00
|
|
|
NetworkResult::NetworkResult(const QByteArray &data, int status)
|
2018-07-07 13:08:57 +02:00
|
|
|
: data_(data)
|
2019-09-19 19:03:50 +02:00
|
|
|
, status_(status)
|
2018-07-07 13:08:57 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject NetworkResult::parseJson() const
|
|
|
|
{
|
|
|
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_));
|
2018-10-21 13:43:02 +02:00
|
|
|
if (jsonDoc.isNull())
|
|
|
|
{
|
2018-07-07 13:08:57 +02:00
|
|
|
return QJsonObject{};
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonDoc.object();
|
|
|
|
}
|
|
|
|
|
2019-09-03 23:32:22 +02:00
|
|
|
QJsonArray NetworkResult::parseJsonArray() const
|
|
|
|
{
|
|
|
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_));
|
|
|
|
if (jsonDoc.isNull())
|
|
|
|
{
|
|
|
|
return QJsonArray{};
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonDoc.array();
|
|
|
|
}
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
rapidjson::Document NetworkResult::parseRapidJson() const
|
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
rapidjson::Document ret(rapidjson::kObjectType);
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
rapidjson::ParseResult result =
|
|
|
|
ret.Parse(this->data_.data(), this->data_.length());
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (result.Code() != rapidjson::kParseErrorNone)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCWarning(chatterinoCommon)
|
|
|
|
<< "JSON parse error:" << rapidjson::GetParseError_En(result.Code())
|
|
|
|
<< "(" << result.Offset() << ")";
|
2018-07-07 13:08:57 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
const QByteArray &NetworkResult::getData() const
|
2018-07-07 13:08:57 +02:00
|
|
|
{
|
|
|
|
return this->data_;
|
|
|
|
}
|
|
|
|
|
2019-09-19 19:03:50 +02:00
|
|
|
int NetworkResult::status() const
|
|
|
|
{
|
|
|
|
return this->status_;
|
|
|
|
}
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
} // namespace chatterino
|