diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-18 00:00:59 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-07-18 00:00:59 -0300 |
commit | 0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917 (patch) | |
tree | de671155caa23f3d1a3804fc0050a5c80ee6ba8d /src/server | |
parent | b25c3aef7c6a40e248964e3a551e2c16762dc370 (diff) | |
download | jet-0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917.tar.gz jet-0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917.zip |
Simplify command parsing
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/client.cpp | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/src/server/client.cpp b/src/server/client.cpp index bed62c5..d6fc0fc 100644 --- a/src/server/client.cpp +++ b/src/server/client.cpp @@ -11,38 +11,28 @@ struct Client { void parse_message() { int8_t message[MAX_MSG_SIZE] = {}; read(sockfd, message, MAX_MSG_SIZE - 1); - int8_t *iter = message; - while (*iter) { - switch (*iter) { - case OP_MOVE1: - move(iter[1]); - iter += 2; - break; - case OP_MOVE2: - move(decode2(iter, 1)); - iter += 3; - break; - case OP_MOVE4: - move(decode4(iter, 1)); - iter += 5; - break; - case OP_MOVE8: - move(decode8(iter, 1)); - iter += 9; - break; - case OP_INSERT: - push(iter[1]); - iter += 2; - break; - case OP_DELETE: - pop(); - iter += 1; - break; - case OP_SHOW: - show(decode2(iter, 1), decode2(iter, 3)); - iter += 6; - break; - } + switch (message[0]) { + case OP_MOVE1: + move(message[1]); + break; + case OP_MOVE2: + move(decode2(message, 1)); + break; + case OP_MOVE4: + move(decode4(message, 1)); + break; + case OP_MOVE8: + move(decode8(message, 1)); + break; + case OP_INSERT: + push(message[1]); + break; + case OP_DELETE: + pop(); + break; + case OP_SHOW: + show(decode2(message, 1), decode2(message, 3)); + break; } } |