Skip to content

Commit

Permalink
macaroni
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Oct 3, 2023
1 parent a64bf37 commit 237c7d6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 0 additions & 2 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@

namespace dpp {

using json = nlohmann::json;

/**
* @brief Types of startup for cluster::start()
*/
Expand Down
2 changes: 0 additions & 2 deletions include/dpp/discordclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#define API_PATH "/api/v" DISCORD_API_VERSION
namespace dpp {

using json = nlohmann::json;

// Forward declarations
class cluster;

Expand Down
2 changes: 0 additions & 2 deletions include/dpp/discordvoiceclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class audio_mixer;

inline constexpr size_t send_audio_raw_max_length = 11520;

using json = nlohmann::json;

/*
* @brief For holding a moving average of the number of current voice users, for applying a smooth gain ramp.
*/
Expand Down
2 changes: 0 additions & 2 deletions include/dpp/event_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <dpp/exception.h>
#include <dpp/coro/job.h>

using json = nlohmann::json;

namespace dpp {

#ifdef DPP_CORO
Expand Down
6 changes: 5 additions & 1 deletion include/dpp/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
#include <nlohmann/json.hpp>
#else
#include <dpp/nlohmann/json.hpp>
#endif
#endif

namespace dpp {
using json = nlohmann::json;
}
6 changes: 5 additions & 1 deletion include/dpp/json_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
#include <nlohmann/json_fwd.hpp>
#else
#include <dpp/nlohmann/json_fwd.hpp>
#endif
#endif

namespace dpp {
using json = nlohmann::json;
}
2 changes: 0 additions & 2 deletions include/dpp/restresults.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
#include <shared_mutex>
#include <cstring>

using json = nlohmann::json;

namespace dpp {

#ifdef _WIN32
Expand Down
13 changes: 7 additions & 6 deletions include/dpp/snowflake.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <dpp/exception.h>
#include <cstdint>
#include <charconv>
#include <type_traits>

/**
* @brief The main namespace for D++ functions. classes and types
Expand All @@ -33,17 +34,17 @@ namespace dpp {

/** @brief A container for a 64 bit unsigned value representing many things on discord.
* This value is known in distributed computing as a snowflake value.
*
*
* Snowflakes are:
*
*
* - Performant (very fast to generate at source and to compare in code)
* - Uncoordinated (allowing high availability across clusters, data centres etc)
* - Time ordered (newer snowflakes have higher IDs)
* - Directly Sortable (due to time ordering)
* - Compact (64 bit numbers, not 128 bit, or string)
*
*
* An identical format of snowflake is used by Twitter, Instagram and several other platforms.
*
*
* @see https://en.wikipedia.org/wiki/Snowflake_ID
* @see https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231
*/
Expand Down Expand Up @@ -81,7 +82,7 @@ class DPP_EXPORT snowflake final {
constexpr snowflake(T snowflake_val) noexcept(std::is_unsigned_v<T>) : value(static_cast<std::make_unsigned_t<T>>(snowflake_val)) {
/**
* we cast to the unsigned version of the type given - this maintains "possible loss of data" warnings for sizeof(T) > sizeof(value)
* while suppressing them for signed to unsigned conversion
* while suppressing them for signed to unsigned conversion (for example snowflake(42) will call snowflake(int) which is a signed type)
*/
if constexpr (!std::is_unsigned_v<T>) {
/* if the type is signed, at compile-time, add a check at runtime that the value is unsigned */
Expand Down Expand Up @@ -204,7 +205,7 @@ class DPP_EXPORT snowflake final {
* @brief For building json
* @return The snowflake value as a string
*/
operator nlohmann::json() const;
operator json() const;

/**
* @brief Get the creation time of this snowflake according to Discord.
Expand Down
3 changes: 2 additions & 1 deletion src/dpp/snowflake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
************************************************************************************/
#include <dpp/snowflake.h>
#include <dpp/json.h>
#include <charconv>
#include <string>

Expand All @@ -37,7 +38,7 @@ snowflake& snowflake::operator=(std::string_view string_value) noexcept {
return *this;
}

snowflake::operator nlohmann::json() const {
snowflake::operator json() const {
/* Discord transfers snowflakes as strings for compatibility with javascript */
return std::to_string(value);
}
Expand Down

0 comments on commit 237c7d6

Please sign in to comment.