Concord - C Discord API library
A Discord API wrapper library written in C
discord-request.h
Go to the documentation of this file.
1
8#ifndef DISCORD_REQUEST_H
9#define DISCORD_REQUEST_H
10
11/* helper typedefs for casting */
12typedef void (*cast_done_typed)(struct discord *,
13 struct discord_response *,
14 const void *);
15typedef void (*cast_init)(void *);
16typedef void (*cast_cleanup)(void *);
17typedef size_t (*cast_from_json)(const char *, size_t, void *);
18
19/* helper typedef for getting sizeof of `struct discord_ret` common fields */
20typedef struct {
23
24#define _RET_COPY_TYPED(dest, src) \
25 do { \
26 memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
27 (dest).has_type = true; \
28 (dest).done.typed = (cast_done_typed)(src).done; \
29 (dest).sync = (src).sync; \
30 } while (0)
31
32#define _RET_COPY_TYPELESS(dest, src) \
33 do { \
34 memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
35 (dest).has_type = false; \
36 (dest).done.typeless = (src).done; \
37 (dest).sync = (void *)(src).sync; \
38 } while (0)
39
48#define DISCORD_ATTR_INIT(attr, type, ret, _reason) \
49 do { \
50 (attr).response.size = sizeof(struct type); \
51 (attr).response.init = (cast_init)type##_init; \
52 (attr).response.from_json = (cast_from_json)type##_from_json; \
53 (attr).response.cleanup = (cast_cleanup)type##_cleanup; \
54 (attr).reason = _reason; \
55 if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
56 } while (0)
57
66#define DISCORD_ATTR_LIST_INIT(attr, type, ret, _reason) \
67 do { \
68 (attr).response.size = sizeof(struct type); \
69 (attr).response.from_json = (cast_from_json)type##_from_json; \
70 (attr).response.cleanup = (cast_cleanup)type##_cleanup; \
71 (attr).reason = _reason; \
72 if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
73 } while (0)
74
83#define DISCORD_ATTR_BLANK_INIT(attr, ret, _reason) \
84 do { \
85 (attr).reason = _reason; \
86 if (ret) _RET_COPY_TYPELESS(attr.dispatch, *ret); \
87 } while (0)
88
94#define DISCORD_ATTACHMENTS_IDS_INIT(attchs) \
95 do { \
96 for (int i = 0; i < attchs->size; ++i) { \
97 attchs->array[i].id = (u64snowflake)i; \
98 } \
99 } while (0)
100
101#endif /* DISCORD_REQUEST_H */
size_t(* cast_from_json)(const char *, size_t, void *)
Definition: discord-request.h:17
void(* cast_init)(void *)
Definition: discord-request.h:15
void(* cast_done_typed)(struct discord *, struct discord_response *, const void *)
Definition: discord-request.h:12
void(* cast_cleanup)(void *)
Definition: discord-request.h:16
The response for the completed request.
Definition: discord-response.h:12
Definition: discord-request.h:20
DISCORD_RET_DEFAULT_FIELDS
Definition: discord-request.h:21
The Discord client handler.
Definition: discord-internal.h:1190