diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-11 23:26:03 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-11 23:26:03 -0300 |
commit | 842355c831404cc1aa3d9ac0918eed0c2d2a86fc (patch) | |
tree | 15d45bad489fb394b7053a135e905b02fab414ae | |
parent | 13fdfe875efdfb33d392c5e634ceff494962e7dc (diff) | |
download | jet-842355c831404cc1aa3d9ac0918eed0c2d2a86fc.tar.gz jet-842355c831404cc1aa3d9ac0918eed0c2d2a86fc.zip |
Fix decoding
-rw-r--r-- | client.cpp | 6 | ||||
-rw-r--r-- | ipc.cpp | 21 | ||||
-rw-r--r-- | jet2.cpp | 8 |
3 files changed, 19 insertions, 16 deletions
@@ -9,9 +9,9 @@ struct Client { Client(const Buffer &b) : cursor(b), window_start(cursor) {} void parse_message() { - uint8_t message[MAX_MSG_SIZE] = {}; + int8_t message[MAX_MSG_SIZE] = {}; read(sockfd, message, MAX_MSG_SIZE - 1); - uint8_t *iter = message; + int8_t *iter = message; while (*iter) { switch (*iter) { case OP_MOVE1: @@ -46,7 +46,7 @@ struct Client { } } - void show(int16_t window_w, int16_t window_h) { + void show(size_t window_w, size_t window_h) { char *view = new char[window_w * window_h]; Point window_end(window_start); @@ -9,29 +9,32 @@ enum Operation { OP_SHOW }; -void encode2(int16_t data, uint8_t *message, size_t offset) { +void encode2(int16_t data, int8_t *message, size_t offset) { message[offset] = data & 0x00ff; message[offset + 1] = (data & 0xff00) >> 8; } -int16_t decode2(uint8_t *message, size_t offset) { - return message[offset] | ((int16_t)message[offset + 1] << 8); +int16_t decode2(int8_t *message, size_t offset) { + return (int16_t)message[offset + 1] << 8 & 0xff00 + | (int16_t)message[offset] & 0x00ff; } -void encode4(int32_t data, uint8_t *message, size_t offset) { +void encode4(int32_t data, int8_t *message, size_t offset) { encode2( data & 0x0000ffff, message, offset); encode2((data & 0xffff0000) >> 16, message, offset + 2); } -int32_t decode4(uint8_t *message, size_t offset) { - return decode2(message, offset) | ((int32_t)decode2(message, offset + 2) << 16); +int32_t decode4(int8_t *message, size_t offset) { + return (int32_t)decode2(message, offset + 2) << 16 & 0xffff0000 + | (int32_t)decode2(message, offset) & 0x0000ffff; } -void encode8(int64_t data, uint8_t *message, size_t offset) { +void encode8(int64_t data, int8_t *message, size_t offset) { encode4( data & 0x00000000ffffffff, message, offset); encode4((data & 0xffffffff00000000) >> 32, message, offset + 4); } -int64_t decode8(uint8_t *message, size_t offset) { - return decode4(message, offset) | ((int64_t)decode4(message, offset + 4) << 32); +int64_t decode8(int8_t *message, size_t offset) { + return (int64_t)decode4(message, offset + 4) << 32 & 0xffffffff00000000 + | (int64_t)decode4(message, offset) & 0x00000000ffffffff; } @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) { while (!quit) { clear(); - uint8_t msg[5]; + int8_t msg[5]; msg[0] = OP_SHOW; encode2(window_width, msg, 1); encode2(window_height, msg, 3); @@ -48,9 +48,9 @@ int main(int argc, char *argv[]) { printw("%c", view[i]); } - uint8_t mov[2]; - uint8_t del[1]; - uint8_t ins[2]; + int8_t mov[2]; + int8_t del[1]; + int8_t ins[2]; int input = getch(); if (mode == NORMAL_MODE) { switch (input) { |