From dd1779c4c7581b0b863886371f891d9d545d6b27 Mon Sep 17 00:00:00 2001 From: Plex Date: Sun, 24 Oct 2021 22:50:22 +0200 Subject: writeVarInt --- mctypes.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 mctypes.c (limited to 'mctypes.c') diff --git a/mctypes.c b/mctypes.c new file mode 100644 index 0000000..ad855e4 --- /dev/null +++ b/mctypes.c @@ -0,0 +1,36 @@ +#include "mctypes.h" +#include +#include +#include + +varint writeVarInt(unsigned int x) +{ + // unsigned int v = x; + varint n = malloc(sizeof(u_int8_t)); + unsigned int size = 1; + while(1) { + n = reallocarray(n, size, sizeof(u_int8_t)); + n[size-1] = x & 0x7F; + x >>= 7; + if(x == 0) + return n; + n[size-1] |= 0b10000000; + size++; + } + return n; +} +/* +writeVarInt(varint x, int s) +{ + while (1) { + if ((x & 0xFFFFFF80) == 0) { + if (send(s, &x, 8, 0) == -1) + exit(EXIT_FAILURE); + return; + } + if (send(s, &x, 8, 0) == -1) + exit(EXIT_FAILURE); + + x >>= 7; + } +} */ -- cgit v1.2.3