Concord - C Discord API library
A Discord API wrapper library written in C
Data Wrap

Helpers for wrapping Discord data types for easier management. More...

Collaboration diagram for Data Wrap:

Modules

 JSON Conversion
 Helpers for converting Discord data types to/from JSON.
 

Macros

#define __CAT(_a, _b)   _a##_b
 
#define _CAT(_a, _b)   __CAT(_a, _b)
 
#define _EXPECT_CONTAINER__struct
 
#define _EXPECT_CONTAINER__union
 
#define _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol)    _CAT(_EXPECT_CONTAINER__, _symbol)
 
#define discord_data_wrap   reflectc_wrap
 The Discord data wrap structure. More...
 
#define discord_data_wrap_from(_symbol, _client, _data)
 Wrap a Discord data type into a reflectc_wrap structure. More...
 
#define discord_data_cleanup(_client, _data)    discord_data_free(discord_get_registry((_client)), (_data))
 Cleanup a Discord data type wrapped into a reflectc_wrap structure. More...
 
#define discord_data_unwrap(_client, _data)    discord_data_release(discord_get_registry((_client)), (_data))
 Drop the wrap cached for _data without touching its contents. More...
 

Functions

void discord_data_free (struct reflectc *registry, void *data)
 
void discord_data_release (struct reflectc *registry, void *data)
 

Detailed Description

Helpers for wrapping Discord data types for easier management.

Macro Definition Documentation

◆ __CAT

#define __CAT (   _a,
  _b 
)    _a##_b

◆ _CAT

#define _CAT (   _a,
  _b 
)    __CAT(_a, _b)

◆ _EXPECT_CONTAINER__struct

#define _EXPECT_CONTAINER__struct

◆ _EXPECT_CONTAINER__union

#define _EXPECT_CONTAINER__union

◆ _DISCORD_SYMBOL_WITHOUT_CONTAINER

#define _DISCORD_SYMBOL_WITHOUT_CONTAINER (   _symbol)     _CAT(_EXPECT_CONTAINER__, _symbol)

◆ discord_data_wrap

#define discord_data_wrap   reflectc_wrap

The Discord data wrap structure.

This struct is used to wrap Discord data types for easier management

◆ discord_data_wrap_from

#define discord_data_wrap_from (   _symbol,
  _client,
  _data 
)
Value:
_CAT(reflectc_from_, _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol))( \
discord_get_registry((_client)), _data, NULL)
#define _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol)
Definition: discord.h:462
#define _CAT(_a, _b)
Definition: discord.h:459

Wrap a Discord data type into a reflectc_wrap structure.

Parameters
_symbolthe Discord data type symbol (with struct or union)
_clientthe client created with discord_from_token()
_datathe Discord data type to be wrapped
Returns
the discord_data_wrap Discord data type

◆ discord_data_cleanup

#define discord_data_cleanup (   _client,
  _data 
)     discord_data_free(discord_get_registry((_client)), (_data))

Cleanup a Discord data type wrapped into a reflectc_wrap structure.

Releases everything discord_data_from_json() allocated for _data — strings, nested objects, list arrays — plus the reflect-c wrap and its registry entry. Every non-NULL pointer member is treated as owned: do not call this on hand-built structs pointing at literals or stack objects.

Parameters
_clientthe client created with discord_from_token()
_datathe Discord data type to be cleaned up
Examples
components.c, embed.c, fetch-messages.c, manual-dm.c, and slash-commands2.c.

◆ discord_data_unwrap

#define discord_data_unwrap (   _client,
  _data 
)     discord_data_release(discord_get_registry((_client)), (_data))

Drop the wrap cached for _data without touching its contents.

discord_data_to_json() caches a reflect-c wrap keyed by _data's address; release it with this once done encoding a caller-owned struct (e.g. stack-built params). Without it the stale registry entry would be wrongly reused by a future object at the same address. Decoded structs don't need this — discord_data_cleanup() releases both the data and the wrap.

Parameters
_clientthe client created with discord_from_token()
_datathe encoded Discord data type to drop the wrap for

Function Documentation

◆ discord_data_free()

void discord_data_free ( struct reflectc *  registry,
void *  data 
)

Function backing discord_data_cleanup; see its contract

◆ discord_data_release()

void discord_data_release ( struct reflectc *  registry,
void *  data 
)

Function backing discord_data_unwrap