about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-03-05 12:45:17 -0500
committerJune McEnroe <june@causal.agency>2018-03-05 12:45:17 -0500
commit7bac64b1b3d8a0ab763aa584e3b085b45ae082b7 (patch)
tree6a7d9306dd4b0f7e9658660159cc4ed26a511e76
parentUndef COLOR_ constants in torus.h (diff)
downloadtorus-7bac64b1b3d8a0ab763aa584e3b085b45ae082b7.tar.gz
torus-7bac64b1b3d8a0ab763aa584e3b085b45ae082b7.zip
Pack message type enums
-rw-r--r--torus.h27
1 files changed, 12 insertions, 15 deletions
diff --git a/torus.h b/torus.h
index 5f8eb9a..efe828d 100644
--- a/torus.h
+++ b/torus.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <time.h>
 
+#define PACKED __attribute__((packed))
 #define ALIGNED(x) __attribute__((aligned(x)))
 
 #undef COLOR_BLACK
@@ -80,15 +81,13 @@ static const struct {
 
 #define SPAWN_COUNT (sizeof(SPAWN) / sizeof(SPAWN[0]))
 
-enum ServerMessageType {
-    SERVER_TILE,
-    SERVER_MOVE,
-    SERVER_PUT,
-    SERVER_CURSOR,
-};
-
 struct ServerMessage {
-    enum ServerMessageType type;
+    enum PACKED {
+        SERVER_TILE,
+        SERVER_MOVE,
+        SERVER_PUT,
+        SERVER_CURSOR,
+    } type;
     union {
         struct {
             uint8_t cellX;
@@ -111,14 +110,12 @@ struct ServerMessage {
 
 #define CURSOR_NONE UINT8_MAX
 
-enum ClientMessageType {
-    CLIENT_MOVE,
-    CLIENT_PUT,
-    CLIENT_SPAWN,
-};
-
 struct ClientMessage {
-    enum ClientMessageType type;
+    enum PACKED {
+        CLIENT_MOVE,
+        CLIENT_PUT,
+        CLIENT_SPAWN,
+    } type;
     union {
         struct {
             int8_t dx;
This avoids duplicating tokens when a client sends VERSION and the server responds with its 005s again. 2021-06-09Use seprintf for snip, removing strlcpynJune McEnroe 2021-06-09Use seprintf for reserializeJune McEnroe 2021-06-09Use seprintf for capListJune McEnroe 2021-06-09Add seprintfJune McEnroe Based on seprint(2) from Plan 9. I'm not sure if my return value exactly matches Plan 9's in the case of truncation. seprint(2) is described only as returning a pointer to the terminating '\0', but if it does so even in the case of truncation, it is awkward for the caller to detect. This implementation returns end in the truncation case, so that (ptr == end) indicates truncation. 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe Default MANDIR to ${PREFIX}/man since it turns out man-db includes /usr/local/man by default. Add support for BINDIR. Separate libs out into LDADD variables. 2021-04-30palaver: Exit on getopt failureJune McEnroe Oops. 2021-04-30notify: Implement pounce-notifyJune McEnroe