Image to be received or sent to API calls. More...
#include "utility.h"
Public Member Functions | |
image_data ()=default | |
Construct an empty image. More... | |
image_data (const image_data &rhs) | |
Copy an image. More... | |
image_data (image_data &&rhs) noexcept=default | |
Move an image. More... | |
image_data (image_type format, const std::byte *bytes, uint32_t byte_size) | |
Construct from byte buffer. More... | |
image_data (image_type format, std::string_view bytes) | |
Construct from string buffer. More... | |
std::string | base64_encode () const |
Encode to base64. More... | |
bool | empty () const noexcept |
Check if this is an empty image. More... | |
std::string | get_file_extension () const |
Get the file extension. More... | |
std::string | get_mime_type () const |
Get the mime type. More... | |
image_data & | operator= (const image_data &rhs) |
Copy an image data. More... | |
image_data & | operator= (image_data &&rhs) noexcept=default |
Move an image data. More... | |
void | set (image_type format, const std::byte *bytes, uint32_t byte_size) |
Set image data. More... | |
void | set (image_type format, std::string_view bytes) |
Set image data. More... | |
json | to_nullable_json () const |
Build a data URI scheme suitable for sending to Discord. More... | |
Public Attributes | |
std::unique_ptr< std::byte[]> | data = nullptr |
Data in bytes of the image. More... | |
uint32_t | size = 0 |
Size of the data in bytes. More... | |
image_type | type = {} |
Type of the image. More... | |
Image to be received or sent to API calls.
This class is carefully crafted to be 16 bytes, this is why we use a ptr + 4 byte size instead of a vector. We want this class to be substitutable with iconhash in data structures.
|
default |
Construct an empty image.
dpp::utility::image_data::image_data | ( | const image_data & | rhs | ) |
Copy an image.
rhs | Image to copy |
References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.
|
defaultnoexcept |
Move an image.
rhs | Image to copy |
dpp::utility::image_data::image_data | ( | image_type | format, |
std::string_view | bytes | ||
) |
Construct from string buffer.
format | Image format |
bytes | Data in a string |
References dpp::utility::anonymous_namespace{utility.cpp}::copy_data().
dpp::utility::image_data::image_data | ( | image_type | format, |
const std::byte * | bytes, | ||
uint32_t | byte_size | ||
) |
Construct from byte buffer.
format | Image format |
bytes | Data of the image |
byte_size | Image size in bytes |
References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), and data.
std::string dpp::utility::image_data::base64_encode | ( | ) | const |
Encode to base64.
References dpp::base64_encode(), data, and size.
Referenced by to_nullable_json().
|
noexcept |
Check if this is an empty image.
References size.
Referenced by to_nullable_json().
std::string dpp::utility::image_data::get_file_extension | ( | ) | const |
Get the file extension.
Alias for file_extension
.png
References dpp::utility::file_extension(), and type.
std::string dpp::utility::image_data::get_mime_type | ( | ) | const |
Get the mime type.
Alias for mime_type
References dpp::utility::mime_type(), and type.
Referenced by to_nullable_json().
image_data & dpp::utility::image_data::operator= | ( | const image_data & | rhs | ) |
Copy an image data.
rhs | Image to copy |
References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, size, and type.
|
defaultnoexcept |
Move an image data.
rhs | Image to move from |
void dpp::utility::image_data::set | ( | image_type | format, |
const std::byte * | bytes, | ||
uint32_t | byte_size | ||
) |
Set image data.
format | Format of the image |
bytes | Data of the image |
byte_size | Image size in bytes |
References dpp::utility::bytes(), dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.
void dpp::utility::image_data::set | ( | image_type | format, |
std::string_view | bytes | ||
) |
Set image data.
format | Image format |
bytes | Data of the image |
References dpp::utility::bytes(), dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.
json dpp::utility::image_data::to_nullable_json | ( | ) | const |
Build a data URI scheme suitable for sending to Discord.
References base64_encode(), empty(), and get_mime_type().
std::unique_ptr<std::byte[]> dpp::utility::image_data::data = nullptr |
Data in bytes of the image.
Referenced by base64_encode(), image_data(), operator=(), and set().
uint32_t dpp::utility::image_data::size = 0 |
Size of the data in bytes.
Referenced by base64_encode(), empty(), image_data(), operator=(), and set().
image_type dpp::utility::image_data::type = {} |
Type of the image.
Referenced by get_file_extension(), get_mime_type(), and operator=().