| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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:
[legend]

## Public Member Functions

| image_data ()=default
| Construct an empty image.
| image_data (const image_data &rhs)
| Copy an image.
| image_data (image_data &&rhs) noexcept=default
| Move an image.
| image_data (image_type format, const std::byte *bytes, uint32_t byte_size)
| Construct from byte buffer.
| image_data (image_type format, std::string_view bytes)
| Construct from string buffer.
std::string | base64_encode () const
| Encode to base64.
bool | empty () const noexcept
| Check if this is an empty image.
std::string | get_file_extension () const
| Get the file extension.
std::string | get_mime_type () const
| Get the mime type.
image_data & | operator= (const image_data &rhs)
| Copy an image data.
image_data & | operator= (image_data &&rhs) noexcept=default
| Move an image data.
void | set (image_type format, const std::byte *bytes, uint32_t byte_size)
| Set image data.
void | set (image_type format, std::string_view bytes)
| Set image data.
json | to_nullable_json () const
| Build a data URI scheme suitable for sending to Discord.

## Public Attributes

std::unique_ptr< std::byte[]> | data = nullptr
| Data in bytes of the image.
uint32_t | size = 0
| Size of the data in bytes.
image_type | type = {}
| Type of the image.

## 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

  rhs | Image to copy

## ◆ image_data() [3/5]

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

default noexcept

Move an image.

Parameters

  rhs | Image to copy

## ◆ image_data() [4/5]

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

Construct from string buffer.

Parameters

  format | Image format
  bytes | Data 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

  format | Image format
  bytes | Data of the image
  byte_size | Image 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

  rhs | Image to copy

Returns
  self for chaining

## ◆ operator=() [2/2]

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

default noexcept

Move an image data.

Parameters

  rhs | Image 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

  format | Format of the image
  bytes | Data of the image
  byte_size | Image size in bytes

## ◆ set() [2/2]

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

Set image data.

Parameters

  format | Image format
  bytes | Data 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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0