Improve message json serialization performance

This commit is contained in:
Allan Bazinet 2024-11-03 21:21:38 -08:00
parent e94bffb402
commit 89074e47f4
2 changed files with 16 additions and 8 deletions

View file

@ -207,23 +207,27 @@ Message::read(QJsonObject const & json)
void
Message::write(QJsonObject & json) const
{
json["type"] = d_->type_;
json["value"] = d_->value_;
json["params"] = QJsonObject::fromVariantMap(d_->params_);
toJsonObject().swap(json);
}
/******************************************************************************/
// Conversions
/******************************************************************************/
QJsonObject
Message::toJsonObject() const
{
return {
{ "type", d_->type_ },
{ "value", d_->value_ },
{ "params", QJsonObject::fromVariantMap(d_->params_) }
};
}
QByteArray
Message::toJson() const
{
QJsonObject object;
write(object);
return QJsonDocument(object).toJson(QJsonDocument::Compact);
return QJsonDocument(toJsonObject()).toJson(QJsonDocument::Compact);
}
QVariantMap