D++ (DPP)  10.0.30
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, 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_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, 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...
 

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

References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.

Here is the call graph for this function:

◆ 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

References dpp::utility::anonymous_namespace{utility.cpp}::copy_data().

Here is the call graph for this function:

◆ 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

References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), and data.

Here is the call graph for this function:

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

References dpp::base64_encode(), data, and size.

Referenced by to_nullable_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

References size.

Referenced by to_nullable_json().

Here is the caller graph for this function:

◆ 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

References dpp::utility::file_extension(), and type.

Here is the call graph for this function:

◆ 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"

References dpp::utility::mime_type(), and type.

Referenced by to_nullable_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

References dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, size, and type.

Here is the call graph for this function:

◆ 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

References dpp::utility::bytes(), dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.

Here is the call graph for this function:

◆ 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

References dpp::utility::bytes(), dpp::utility::anonymous_namespace{utility.cpp}::copy_data(), data, and size.

Here is the call graph for this function:

◆ 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

References base64_encode(), empty(), and get_mime_type().

Here is the call graph for this function:

Member Data Documentation

◆ data

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().

◆ size

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

Size of the data in bytes.

Referenced by base64_encode(), empty(), image_data(), operator=(), and set().

◆ type

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

Type of the image.

See also
image_type

Referenced by get_file_extension(), get_mime_type(), and operator=().


The documentation for this struct was generated from the following files: