I like this better over here.
This commit is contained in:
parent
fa437ad897
commit
827c056602
3 changed files with 8 additions and 9 deletions
|
@ -12,8 +12,6 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rapidjson/internal/itoa.h"
|
|
||||||
|
|
||||||
constexpr size_t MaxMessageSize = 16 * 1024;
|
constexpr size_t MaxMessageSize = 16 * 1024;
|
||||||
constexpr size_t MessageQueueSize = 8;
|
constexpr size_t MessageQueueSize = 8;
|
||||||
|
|
||||||
|
@ -159,9 +157,7 @@ extern "C" void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
||||||
{
|
{
|
||||||
auto qmessage = SendQueueGetNextAddMessage();
|
auto qmessage = SendQueueGetNextAddMessage();
|
||||||
if (qmessage) {
|
if (qmessage) {
|
||||||
char nonce[32]{};
|
qmessage->length = JsonWriteRichPresenceObj(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, Pid, presence);
|
||||||
rapidjson::internal::i32toa(Nonce++, nonce);
|
|
||||||
qmessage->length = JsonWriteRichPresenceObj(qmessage->buffer, sizeof(qmessage->buffer), nonce, Pid, presence);
|
|
||||||
SendQueueCommitMessage();
|
SendQueueCommitMessage();
|
||||||
SignalIOActivity();
|
SignalIOActivity();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
|
#include "rapidjson/internal/itoa.h"
|
||||||
|
|
||||||
// I want to use as few allocations as I can get away with, and to do that with RapidJson, you need to supply some of
|
// I want to use as few allocations as I can get away with, and to do that with RapidJson, you need to supply some of
|
||||||
// your own allocators for stuff rather than use the defaults
|
// your own allocators for stuff rather than use the defaults
|
||||||
|
@ -93,12 +94,14 @@ void WriteOptionalString(JsonWriter& w, T& k, const char* value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonWriteCommandStart(JsonWriter& writer, const char* nonce, const char* cmd)
|
void JsonWriteCommandStart(JsonWriter& writer, int nonce, const char* cmd)
|
||||||
{
|
{
|
||||||
writer.StartObject();
|
writer.StartObject();
|
||||||
|
|
||||||
WriteKey(writer, "nonce");
|
WriteKey(writer, "nonce");
|
||||||
writer.String(nonce);
|
char nonceBuffer[32]{};
|
||||||
|
rapidjson::internal::i32toa(nonce, nonceBuffer);
|
||||||
|
writer.String(nonceBuffer);
|
||||||
|
|
||||||
WriteKey(writer, "cmd");
|
WriteKey(writer, "cmd");
|
||||||
writer.String(cmd);
|
writer.String(cmd);
|
||||||
|
@ -113,7 +116,7 @@ void JsonWriteCommandEnd(JsonWriter& writer)
|
||||||
writer.EndObject(); // top level
|
writer.EndObject(); // top level
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, char* nonce, int pid, const DiscordRichPresence* presence)
|
size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, int nonce, int pid, const DiscordRichPresence* presence)
|
||||||
{
|
{
|
||||||
DirectStringBuffer sb(dest, maxLen);
|
DirectStringBuffer sb(dest, maxLen);
|
||||||
WriterAllocator wa;
|
WriterAllocator wa;
|
||||||
|
|
|
@ -20,5 +20,5 @@ inline size_t StringCopy(char (&dest)[Len], const char* src) {
|
||||||
size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char* applicationId);
|
size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char* applicationId);
|
||||||
|
|
||||||
struct DiscordRichPresence;
|
struct DiscordRichPresence;
|
||||||
size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, char* nonce, int pid, const DiscordRichPresence* presence);
|
size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, int nonce, int pid, const DiscordRichPresence* presence);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue