D++ (DPP)
C++ Discord API Bot Library
dpp::bignumber Class Reference

An arbitrary length integer number. Officially, the Discord documentation says that permission values can be any arbitrary number of digits. At time of writing there are only 50 bits of permissions, but this is set to grow larger and potentially past 64 bits. They will continue to send this data as a huge single integer at that point, because this is obviously sensible. /s. More...

Public Member Functions

 bignumber ()=default
 Construct a new bignumber object. More...
 
 bignumber (const std::string &number_string)
 Parse a std::string of an arbitrary length number into a bignumber. More...
 
 bignumber (std::vector< uint64_t > bits)
 Build a bignumber from a vector of 64 bit values. The values are accepted in "reverse order", so the first vector entry at index 0 is the leftmost 64 bits of the bignum. The vector can be any arbitrary length. More...
 
 ~bignumber ()=default
 Default destructor. More...
 
std::string get_number (bool hex=false) const
 Get the string representation of the bignumber. More...
 
std::vector< uint64_t > get_binary () const
 Get the array of 64 bit values that represents the bignumber. This is what we should use to store bignumbers in memory, not this bignumber class itself, as the bignumber class instantiates OpenSSL structs and takes significantly more ram than just a vector. More...
 

Detailed Description

An arbitrary length integer number. Officially, the Discord documentation says that permission values can be any arbitrary number of digits. At time of writing there are only 50 bits of permissions, but this is set to grow larger and potentially past 64 bits. They will continue to send this data as a huge single integer at that point, because this is obviously sensible. /s.

Note
dpp::bignumber uses OpenSSL BN_* under the hood, as we include openssl anyway for HTTPS.

Constructor & Destructor Documentation

◆ bignumber() [1/3]

dpp::bignumber::bignumber ( )
default

Construct a new bignumber object.

◆ bignumber() [2/3]

dpp::bignumber::bignumber ( const std::string &  number_string)

Parse a std::string of an arbitrary length number into a bignumber.

Parameters
number_stringstring representation of a number. The number must be an integer, and can be positive or negative.
Note
Prefixing number_string with 0x will parse it as hexadecimal. This is not case sensitive.

◆ bignumber() [3/3]

dpp::bignumber::bignumber ( std::vector< uint64_t >  bits)

Build a bignumber from a vector of 64 bit values. The values are accepted in "reverse order", so the first vector entry at index 0 is the leftmost 64 bits of the bignum. The vector can be any arbitrary length.

Parameters
bitsVector of 64 bit values which represent the number

◆ ~bignumber()

dpp::bignumber::~bignumber ( )
default

Default destructor.

Member Function Documentation

◆ get_binary()

std::vector<uint64_t> dpp::bignumber::get_binary ( ) const

Get the array of 64 bit values that represents the bignumber. This is what we should use to store bignumbers in memory, not this bignumber class itself, as the bignumber class instantiates OpenSSL structs and takes significantly more ram than just a vector.

Returns
Vector of 64 bit values representing the bignumber

◆ get_number()

std::string dpp::bignumber::get_number ( bool  hex = false) const

Get the string representation of the bignumber.

Parameters
hexIf false (the default) the number is returned in decimal, else if this parameter is true, it will be returned as hex (without leading '0x')
Returns
String representation of bignumber
D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0