Move stringify function to rapidjson-helpers

This commit is contained in:
Rasmus Karlsson 2018-05-13 17:51:01 +02:00
parent 9bad40742f
commit d4c31309f0
5 changed files with 17 additions and 10 deletions

View file

@ -68,7 +68,7 @@ bool PubSubClient::listen(rapidjson::Document &message)
rj::set(message, "nonce", uuid); rj::set(message, "nonce", uuid);
std::string payload = stringify(message); std::string payload = rj::stringify(message);
sentMessages[uuid.toStdString()] = payload; sentMessages[uuid.toStdString()] = payload;
this->send(payload.c_str()); this->send(payload.c_str());
@ -100,7 +100,7 @@ void PubSubClient::unlistenPrefix(const std::string &prefix)
rj::set(message, "nonce", CreateUUID()); rj::set(message, "nonce", CreateUUID());
std::string payload = stringify(message); std::string payload = rj::stringify(message);
sentMessages[uuid.toStdString()] = payload; sentMessages[uuid.toStdString()] = payload;
this->send(payload.c_str()); this->send(payload.c_str());
@ -747,7 +747,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
std::string moderationAction; std::string moderationAction;
if (!rj::getSafe(data, "moderation_action", moderationAction)) { if (!rj::getSafe(data, "moderation_action", moderationAction)) {
debug::Log("Missing moderation action in data: {}", stringify(data)); debug::Log("Missing moderation action in data: {}", rj::stringify(data));
return; return;
} }

View file

@ -34,11 +34,6 @@ bool getTargetUser(const rapidjson::Value &data, ActionUser &user)
return rj::getSafe(data, "target_user_id", user.id); return rj::getSafe(data, "target_user_id", user.id);
} }
std::string stringify(const rapidjson::Value &v)
{
return pajlada::Settings::SettingManager::stringify(v);
}
rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec, rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec,
std::shared_ptr<providers::twitch::TwitchAccount> account) std::shared_ptr<providers::twitch::TwitchAccount> account)
{ {

View file

@ -21,8 +21,6 @@ bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
bool getTargetUser(const rapidjson::Value &data, ActionUser &user); bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
std::string stringify(const rapidjson::Value &v);
rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec, rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec,
std::shared_ptr<providers::twitch::TwitchAccount> account); std::shared_ptr<providers::twitch::TwitchAccount> account);
rapidjson::Document createUnlistenMessage(const std::vector<std::string> &topicsVec); rapidjson::Document createUnlistenMessage(const std::vector<std::string> &topicsVec);

View file

@ -1,5 +1,7 @@
#include "util/rapidjson-helpers.hpp" #include "util/rapidjson-helpers.hpp"
#include <rapidjson/prettywriter.h>
namespace chatterino { namespace chatterino {
namespace rj { namespace rj {
@ -15,5 +17,14 @@ void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a); obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a);
} }
std::string stringify(const rapidjson::Value &value)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value.Accept(writer);
return std::string(buffer.GetString());
}
} // namespace rj } // namespace rj
} // namespace chatterino } // namespace chatterino

View file

@ -6,6 +6,7 @@
#include <pajlada/settings/serialize.hpp> #include <pajlada/settings/serialize.hpp>
#include <cassert> #include <cassert>
#include <string>
namespace chatterino { namespace chatterino {
namespace rj { namespace rj {
@ -93,5 +94,7 @@ bool getSafe(const rapidjson::Value &value, Type &out)
return true; return true;
} }
std::string stringify(const rapidjson::Value &value);
} // namespace rj } // namespace rj
} // namespace chatterino } // namespace chatterino