mirror of
https://github.com/yuzu-emu/discord-rpc
synced 2024-11-22 22:53:59 +00:00
Remove dep on rapidjson/internal
This commit is contained in:
parent
e07806424b
commit
4cf8ca5670
2 changed files with 28 additions and 5 deletions
|
@ -2,6 +2,31 @@
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "discord-rpc.h"
|
#include "discord-rpc.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void NumberToString(char* dest, T number)
|
||||||
|
{
|
||||||
|
if (!number) {
|
||||||
|
*dest++ = '0';
|
||||||
|
*dest++ = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (number < 0) {
|
||||||
|
*dest++ = '-';
|
||||||
|
number = -number;
|
||||||
|
}
|
||||||
|
char temp[32];
|
||||||
|
int place = 0;
|
||||||
|
while (number) {
|
||||||
|
auto digit = number % 10;
|
||||||
|
number = number / 10;
|
||||||
|
temp[place++] = '0' + (char)digit;
|
||||||
|
}
|
||||||
|
for (--place; place >= 0; --place) {
|
||||||
|
*dest++ = temp[place];
|
||||||
|
}
|
||||||
|
*dest = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// it's ever so slightly faster to not have to strlen the key
|
// it's ever so slightly faster to not have to strlen the key
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void WriteKey(JsonWriter& w, T& k)
|
void WriteKey(JsonWriter& w, T& k)
|
||||||
|
@ -50,8 +75,8 @@ void WriteOptionalString(JsonWriter& w, T& k, const char* value)
|
||||||
void JsonWriteNonce(JsonWriter& writer, int nonce)
|
void JsonWriteNonce(JsonWriter& writer, int nonce)
|
||||||
{
|
{
|
||||||
WriteKey(writer, "nonce");
|
WriteKey(writer, "nonce");
|
||||||
char nonceBuffer[32]{};
|
char nonceBuffer[32];
|
||||||
rapidjson::internal::i32toa(nonce, nonceBuffer);
|
NumberToString(nonceBuffer, nonce);
|
||||||
writer.String(nonceBuffer);
|
writer.String(nonceBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
#include "rapidjson/internal/itoa.h"
|
|
||||||
|
|
||||||
// if only there was a standard library function for this
|
// if only there was a standard library function for this
|
||||||
template <size_t Len>
|
template <size_t Len>
|
||||||
|
@ -35,8 +34,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
|
||||||
size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName);
|
size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName);
|
||||||
|
|
||||||
// I want to use as few allocations as I can get away with, and to do that with RapidJson, you need
|
// 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
|
// to supply some of your own allocators for stuff rather than use the defaults
|
||||||
// your own allocators for stuff rather than use the defaults
|
|
||||||
|
|
||||||
class LinearAllocator {
|
class LinearAllocator {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue