Concord - C Discord API library
A Discord API wrapper library written in C
discord-request.h File Reference

Generic macros for initializing a discord_attributes. More...

Go to the source code of this file.

Data Structures

struct  discord_ret_default_fields
 

Macros

#define _RET_COPY_TYPED(dest, src)
 
#define _RET_COPY_TYPELESS(dest, src)
 
#define DISCORD_ATTR_INIT(attr, type, ret, _reason)
 Helper for setting attributes for a specs-generated return struct. More...
 
#define DISCORD_ATTR_LIST_INIT(attr, type, ret, _reason)
 Helper for setting attributes for a specs-generated list. More...
 
#define DISCORD_ATTR_BLANK_INIT(attr, ret, _reason)
 Helper for setting attributes for attruests that doensn't expect a response object. More...
 
#define DISCORD_ATTACHMENTS_IDS_INIT(attchs)
 Helper for initializing attachments ids. More...
 

Typedefs

typedef void(* cast_done_typed) (struct discord *, struct discord_response *, const void *)
 
typedef void(* cast_init) (void *)
 
typedef void(* cast_cleanup) (void *)
 
typedef size_t(* cast_from_json) (const char *, size_t, void *)
 

Detailed Description

Generic macros for initializing a discord_attributes.

Author
Cogmasters

Macro Definition Documentation

◆ _RET_COPY_TYPED

#define _RET_COPY_TYPED (   dest,
  src 
)
Value:
do { \
memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
(dest).has_type = true; \
(dest).done.typed = (cast_done_typed)(src).done; \
(dest).sync = (src).sync; \
} while (0)
void(* cast_done_typed)(struct discord *, struct discord_response *, const void *)
Definition: discord-request.h:12
Definition: discord-request.h:20

◆ _RET_COPY_TYPELESS

#define _RET_COPY_TYPELESS (   dest,
  src 
)
Value:
do { \
memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
(dest).has_type = false; \
(dest).done.typeless = (src).done; \
(dest).sync = (void *)(src).sync; \
} while (0)

◆ DISCORD_ATTR_INIT

#define DISCORD_ATTR_INIT (   attr,
  type,
  ret,
  _reason 
)
Value:
do { \
(attr).response.size = sizeof(struct type); \
(attr).response.init = (cast_init)type##_init; \
(attr).response.from_json = (cast_from_json)type##_from_json; \
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
} while (0)
size_t(* cast_from_json)(const char *, size_t, void *)
Definition: discord-request.h:17
void(* cast_init)(void *)
Definition: discord-request.h:15
#define _RET_COPY_TYPED(dest, src)
Definition: discord-request.h:24
void(* cast_cleanup)(void *)
Definition: discord-request.h:16

Helper for setting attributes for a specs-generated return struct.

Parameters
[out]attrdiscord_attributes handler to be initialized
[in]typedatatype of the struct
[in]retdispatch attributes
[in]_reasonreason for request (if available)

◆ DISCORD_ATTR_LIST_INIT

#define DISCORD_ATTR_LIST_INIT (   attr,
  type,
  ret,
  _reason 
)
Value:
do { \
(attr).response.size = sizeof(struct type); \
(attr).response.from_json = (cast_from_json)type##_from_json; \
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
} while (0)

Helper for setting attributes for a specs-generated list.

Parameters
[out]attrdiscord_attributes handler to be initialized
[in]typedatatype of the list
[in]retdispatch attributes
[in]_reasonreason for request (if available)

◆ DISCORD_ATTR_BLANK_INIT

#define DISCORD_ATTR_BLANK_INIT (   attr,
  ret,
  _reason 
)
Value:
do { \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPELESS(attr.dispatch, *ret); \
} while (0)
#define _RET_COPY_TYPELESS(dest, src)
Definition: discord-request.h:32

Helper for setting attributes for attruests that doensn't expect a response object.

Parameters
[out]attrdiscord_attributes handler to be initialized
[in]retdispatch attributes
[in]_reasonreason for request (if available)

◆ DISCORD_ATTACHMENTS_IDS_INIT

#define DISCORD_ATTACHMENTS_IDS_INIT (   attchs)
Value:
do { \
for (int i = 0; i < attchs->size; ++i) { \
attchs->array[i].id = (u64snowflake)i; \
} \
} while (0)
uint64_t u64snowflake
Snowflake datatype.
Definition: types.h:28

Helper for initializing attachments ids.

Parameters
[in,out]attchsa discord_attachments to have its IDs initialized

Typedef Documentation

◆ cast_done_typed

typedef void(* cast_done_typed) (struct discord *, struct discord_response *, const void *)

◆ cast_init

typedef void(* cast_init) (void *)

◆ cast_cleanup

typedef void(* cast_cleanup) (void *)

◆ cast_from_json

typedef size_t(* cast_from_json) (const char *, size_t, void *)