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 struct reflectc_wrap *(*cast_init)(struct reflectc *,
16 void *,
17 struct reflectc_wrap *);
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)reflectc_from_##_type; \
52 (_attr).reason = _reason; \
53 if (_ret) _RET_COPY_TYPED((_attr).dispatch, *(_ret)); \
54 } while (0)
55
64#define DISCORD_ATTR_BLANK_INIT(_attr, _ret, _reason) \
65 do { \
66 (_attr).reason = _reason; \
67 if (_ret) _RET_COPY_TYPELESS((_attr).dispatch, *(_ret)); \
68 } while (0)
69
75#define DISCORD_ATTACHMENTS_IDS_INIT(_attchs) \
76 do { \
77 for (int i = 0; i < (_attchs)->size; ++i) { \
78 (_attchs)->array[i].id = (u64snowflake)i; \
79 } \
80 } while (0)
81
82#endif /* DISCORD_REQUEST_H */
void(* cast_done_typed)(struct discord *, struct discord_response *, const void *)
Definition: discord-request.h:12
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:1206