summaryrefslogtreecommitdiff
path: root/shared/bin.h
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-29 19:41:16 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-29 19:41:16 +0200
commit4227c0d62e6df83e96c2b5fa62a8a743d4d96c8f (patch)
tree22b8115111dfc5439c6d024d2c69ee9add07152e /shared/bin.h
parent1c7c0bd747c839fb1e449e98cec942894821addf (diff)
funky pointer magic to optimize memory usage
Diffstat (limited to 'shared/bin.h')
-rw-r--r--shared/bin.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/shared/bin.h b/shared/bin.h
index 48485c8..1eaa2a7 100644
--- a/shared/bin.h
+++ b/shared/bin.h
@@ -13,6 +13,13 @@
extern uint8_t g_w2_endianness;
+#define W2_CAST_BIN(type, in, out) type *out = (type*) &in->data;
+#define W2_CREATE_MSG_BIN(type, normal, bin) \
+ W2_CREATE_MSG_SIZE_BIN(type, sizeof(type), normal, bin)
+#define W2_CREATE_MSG_SIZE_BIN(type, size, normal, bin) \
+ w2_s_bin* bin = malloc(size); \
+ type* normal = (type*) &bin->data;
+
typedef struct {
uint16_t bytes;
uint8_t data[];