mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-12-23 00:45:33 +00:00
Remove dep on rapidjson/internal
This commit is contained in:
parent
e07806424b
commit
4cf8ca5670
|
@ -2,6 +2,31 @@
|
|||
#include "connection.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
|
||||
template <typename T>
|
||||
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)
|
||||
{
|
||||
WriteKey(writer, "nonce");
|
||||
char nonceBuffer[32]{};
|
||||
rapidjson::internal::i32toa(nonce, nonceBuffer);
|
||||
char nonceBuffer[32];
|
||||
NumberToString(nonceBuffer, nonce);
|
||||
writer.String(nonceBuffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/writer.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/internal/itoa.h"
|
||||
|
||||
// if only there was a standard library function for this
|
||||
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);
|
||||
|
||||
// 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
|
||||
// to supply some of your own allocators for stuff rather than use the defaults
|
||||
|
||||
class LinearAllocator {
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue