summaryrefslogtreecommitdiffstats
path: root/protocol.h
diff options
context:
space:
mode:
authorFinn Behrens <me@kloenk.de>2021-02-21 13:07:31 +0100
committerFinn Behrens <me@kloenk.de>2021-02-21 13:07:31 +0100
commite1775bb99219adcae3996c5ca89a0e2843d80f73 (patch)
tree26adecdabb9b62631795b4b4772880a191e2ba04 /protocol.h
parent92b180374eee440aec9537bdd4380f14edbfa28d (diff)
downloadmcc-e1775bb99219adcae3996c5ca89a0e2843d80f73.tar.gz
mcc-e1775bb99219adcae3996c5ca89a0e2843d80f73.tar.xz
mcc-e1775bb99219adcae3996c5ca89a0e2843d80f73.zip
broken libevent?
Diffstat (limited to 'protocol.h')
-rw-r--r--protocol.h57
1 files changed, 52 insertions, 5 deletions
diff --git a/protocol.h b/protocol.h
index a002bf8..bdf062d 100644
--- a/protocol.h
+++ b/protocol.h
@@ -9,27 +9,74 @@
#define protocol_h
#include <sys/types.h>
+#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
-#include <byteswap.h>
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define BE32_TO_H(x) (x)
+// MARK: - Helpers
+#if defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define bswap_16(x) OSSwapInt16(x)
+#define bswap_32(x) OSSwapInt32(x)
+#define bswap_64(x) OSSwapInt64(x)
#else
-#define BE32_TO_H(x) bswap_32(x)
+#include <byteswap.h>
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
+#define BE16_TO_H(x) (x)
+#define BE32_TO_H(x) (x)
+#define BE64_TO_H(x) (x)
+
#define H_TO_BE32(x) (x)
#else
+#define BE16_TO_H(x) bswap_16(x)
+#define BE32_TO_H(x) bswap_32(x)
+#define BE64_TO_H(x) bswap_64(x)
+
#define H_TO_BE32(x) bswap_32(x)
#endif
+
+// MARK: - READ
+// MARK: VAR
int read_var_int(int *dest, uint8_t *src);
int read_var_long(long *dest, uint8_t *src);
+// MARK: primitives
+int read_bool(bool *dest, uint8_t *src);
+
+// byte
+int read_int8(int8_t *dest, uint8_t *src);
+int read_uint8(uint8_t *dest, uint8_t *src);
+
+// short
+int read_int16(int16_t *dest, uint8_t *src);
+int read_uint16(uint16_t *dest, uint8_t *src);
+
+// int
+int read_int32(int32_t *dest, uint8_t *src);
+int read_uint32(uint32_t *dest, uint8_t *src);
+
+// long
+int read_int64(int64_t *dest, uint8_t *src);
+int read_uint64(uint64_t *dest, uint8_t *src);
+
+// MARK: Position
+typedef struct {
+ int32_t x;
+ int32_t z;
+ int16_t y;
+} position_t;
+
+int read_position(position_t *dest, uint8_t *src);
+
+// MARK: - WRITE
+// MARK: VAR
int write_var_int(int value, uint8_t *dest);
int write_var_long(long value, uint8_t *dest);
+// MARK: primitives
+
+
#endif /* protocol_h */