Files
qt5-legatus-legacy/Lts/Common/LtsWebSocket/reply_message.cpp
T
2026-08-13 18:33:10 +02:00

48 lines
1.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* LTS web socket server - Abstract Reply Message and Reply Handler
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-11-28
*/
#include "reply_message.h"
#include "json_keys.h"
#include <QUuid>
namespace LtsWebSocket
{
// ######## ReplyMessage begin ########
QString ReplyMessage::toJsonString() const
{
return QString::fromUtf8(QJsonDocument(m_jsonRepresentation).toJson(QJsonDocument::Compact));
}
ReplyMessage::ReplyMessage(const QString &type, const int typeId, const QString &uuid)
{
m_jsonRepresentation.insert(JsonKeys::TYPE(), type);
m_jsonRepresentation.insert(JsonKeys::TYPEID(), typeId);
if (!uuid.isEmpty())
m_jsonRepresentation.insert(JsonKeys::UUID_(), uuid);
}
// ######## ReplyMessage end ########
// ######## ErrorMessage begin ########
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
: ReplyMessage(JsonKeys::ERROR_(), -1, QUuid::createUuid().toString())
{
m_jsonRepresentation.insert(JsonKeys::DATA(),
QJsonObject({{JsonKeys::UUID_(), data.uuid},
{JsonKeys::ERROR_CLASS(), data.errorClass},
{JsonKeys::ERROR_MESSAGE(), data.errorMessage}
}));
}
// ######## ErrorMessage end ########
} // namespace LtsWebSocketServer