HeartbeatMessage now uses yyjson

This commit is contained in:
celisej567
2024-05-12 22:16:47 +03:00
parent ef6f05913d
commit 3b57ff03b4
2 changed files with 15 additions and 2 deletions

View File

@@ -2658,8 +2658,8 @@ void DiscordClient::HeartbeatThread() {
HeartbeatMessage msg;
msg.Sequence = m_last_sequence;
nlohmann::json j = msg;
m_websocket.Send(j);
//nlohmann::json j = msg;
m_websocket.Send(msg.BuildJson());
if (!m_heartbeat_waiter.wait_for(std::chrono::milliseconds(m_heartbeat_msec)))
break;

View File

@@ -517,6 +517,19 @@ struct IdentifyMessage : GatewayMessage {
struct HeartbeatMessage : GatewayMessage {
int Sequence;
std::string BuildJson() const
{
YYJsonDocument yyjsn;
yyjsn.CreateDoc();
yyjsn.AddInt("op", (int)GatewayOp::Heartbeat);
if (Sequence == -1)
yyjsn.AddNull("d");
else
yyjsn.AddInt("d", Sequence);
return yyjsn.BuildJson();
}
friend void to_json(nlohmann::json &j, const HeartbeatMessage &m);
};