From 4bbbfb8e8139e690ea084b72ccc2de71fdca1e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 2 Aug 2020 03:50:26 -0300 Subject: Simplify encoding and decoding --- src/client/jetc.cpp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/client/jetc.cpp') diff --git a/src/client/jetc.cpp b/src/client/jetc.cpp index cdb570e..cfe3db7 100644 --- a/src/client/jetc.cpp +++ b/src/client/jetc.cpp @@ -12,13 +12,13 @@ Socket io; Window window; Cursor cursor(window); +Message msg; void update() { - int8_t msg[5]; - msg[0] = OP_SHOW; - encode2(window.width, msg, 1); - encode2(window.height, msg, 3); - io.send(msg, 5); + msg.encode1(OP_SHOW); + msg.encode2(window.width); + msg.encode2(window.height); + io.send(msg); io.recv(window.view, window.width * window.height); io.recv(window.line_ends, window.height); @@ -27,33 +27,29 @@ void update() { } void move_left() { - int8_t mov[2]; - mov[0] = OP_MOVE1; - mov[1] = -1; - io.send(mov, 2); + msg.encode1(OP_MOVE1); + msg.encode1(-1); + io.send(msg); cursor.move_left(); } void move_right() { - int8_t mov[2]; - mov[0] = OP_MOVE1; - mov[1] = 1; - io.send(mov, 2); + msg.encode1(OP_MOVE1); + msg.encode1(1); + io.send(msg); cursor.move_right(); } void delete_element() { - int8_t del; - del = OP_DELETE; - io.send(&del, 1); + msg.encode1(OP_DELETE); + io.send(msg); cursor.move_left(); } void insert_element(int input) { - int8_t ins[2]; - ins[0] = OP_INSERT; - ins[1] = input; - io.send(ins, 2); + msg.encode1(OP_INSERT); + msg.encode1(input); + io.send(msg); cursor.move_right(); } -- cgit v1.2.3