From 3b57ff03b47a641d2211890023f69a2b68aec970 Mon Sep 17 00:00:00 2001 From: celisej567 Date: Sun, 12 May 2024 22:16:47 +0300 Subject: [PATCH] HeartbeatMessage now uses yyjson --- src/discord/discord.cpp | 4 ++-- src/discord/objects.hpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 5d4d615..03b380a 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -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; diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 4249e2e..52f1234 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -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); };