D++ (DPP)
C++ Discord API Bot Library
dpp::utility::image_data Struct Reference

Image to be received or sent to API calls. More...

#include <utility.h>

+ Collaboration diagram for dpp::utility::image_data:

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, std::string_view bytes)
 Construct from string buffer. More...
 
 image_data (image_type format, const std::byte *bytes, uint32_t byte_size)
 Construct from byte buffer. More...
 
image_dataoperator= (const image_data &rhs)
 Copy an image data. More...
 
image_dataoperator= (image_data &&rhs) noexcept=default
 Move an image data. More...
 
void set (image_type format, std::string_view bytes)
 Set image data. More...
 
void set (image_type format, const std::byte *bytes, uint32_t byte_size)
 Set image data. More...
 
std::string base64_encode () const
 Encode to base64. More...
 
std::string get_file_extension () const
 Get the file extension. More...
 
std::string get_mime_type () const
 Get the mime type. More...
 
bool empty () const noexcept
 Check if this is an empty image. 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ image_data() [1/5]

dpp::utility::image_data::image_data ( )
default

Construct an empty image.

◆ image_data() [2/5]

dpp::utility::image_data::image_data ( const image_data rhs)

Copy an image.

Parameters
rhsImage to copy

◆ image_data() [3/5]

dpp::utility::image_data::image_data ( image_data &&  rhs)
defaultnoexcept

Move an image.

Parameters
rhsImage to copy

◆ image_data() [4/5]

dpp::utility::image_data::image_data ( image_type  format,
std::string_view  bytes 
)

Construct from string buffer.

Parameters
formatImage format
bytesData in a string
See also
image_type

◆ image_data() [5/5]

dpp::utility::image_data::image_data ( image_type  format,
const std::byte *  bytes,
uint32_t  byte_size 
)

Construct from byte buffer.

Parameters
formatImage format
bytesData of the image
byte_sizeImage size in bytes
See also
image_type

Member Function Documentation

◆ base64_encode()

std::string dpp::utility::image_data::base64_encode ( ) const

Encode to base64.

Returns
std::string New string with the image data encoded in base64

◆ empty()

bool dpp::utility::image_data::empty ( ) const
noexcept

Check if this is an empty image.

Returns
bool Whether the image is empty or not

◆ get_file_extension()

std::string dpp::utility::image_data::get_file_extension ( ) const

Get the file extension.

Alias for file_extension

Returns
std::string File extension e.g. .png

◆ get_mime_type()

std::string dpp::utility::image_data::get_mime_type ( ) const

Get the mime type.

Alias for mime_type

Returns
std::string File mime type e.g. "image/png"

◆ operator=() [1/2]

image_data & dpp::utility::image_data::operator= ( const image_data rhs)

Copy an image data.

Parameters
rhsImage to copy
Returns
self for chaining

◆ operator=() [2/2]

image_data & dpp::utility::image_data::operator= ( image_data &&  rhs)
defaultnoexcept

Move an image data.

Parameters
rhsImage to move from
Returns
self for chaining

◆ set() [1/2]

void dpp::utility::image_data::set ( image_type  format,
const std::byte *  bytes,
uint32_t  byte_size 
)

Set image data.

Parameters
formatFormat of the image
bytesData of the image
byte_sizeImage size in bytes

◆ set() [2/2]

void dpp::utility::image_data::set ( image_type  format,
std::string_view  bytes 
)

Set image data.

Parameters
formatImage format
bytesData of the image

◆ to_nullable_json()

json dpp::utility::image_data::to_nullable_json ( ) const

Build a data URI scheme suitable for sending to Discord.

See also
https://discord.com/developers/docs/reference#image-data
Returns
The data URI scheme as a json or null if empty

Member Data Documentation

◆ data

std::unique_ptr<std::byte[]> dpp::utility::image_data::data = nullptr

Data in bytes of the image.

◆ size

uint32_t dpp::utility::image_data::size = 0

Size of the data in bytes.

◆ type

image_type dpp::utility::image_data::type = {}

Type of the image.

See also
image_type
D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ 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