summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-18 00:00:59 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-18 00:00:59 -0300
commit0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917 (patch)
treede671155caa23f3d1a3804fc0050a5c80ee6ba8d /src/server
parentb25c3aef7c6a40e248964e3a551e2c16762dc370 (diff)
downloadjet-0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917.tar.gz
jet-0d4a6c89bea0756b314b1b24c5f8f99ccb2ef917.zip
Simplify command parsing
Diffstat (limited to 'src/server')
-rw-r--r--src/server/client.cpp54
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;
}
}