summaryrefslogtreecommitdiff
path: root/ipc.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 21:09:08 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 21:09:08 -0300
commita193e6a9fee8760000561ba4fe1a6ec13ea0018d (patch)
treeadd6c1f7fe08fcf7c91e73a5bdf41e61bf7255c5 /ipc.cpp
parente450b0d47e9d05a806769d096646d723845e0ba2 (diff)
downloadjet-a193e6a9fee8760000561ba4fe1a6ec13ea0018d.tar.gz
jet-a193e6a9fee8760000561ba4fe1a6ec13ea0018d.zip
Implement IPC using binary format
Diffstat (limited to 'ipc.cpp')
-rw-r--r--ipc.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/ipc.cpp b/ipc.cpp
index 7b6ea5d..9c96d5a 100644
--- a/ipc.cpp
+++ b/ipc.cpp
@@ -1,15 +1,37 @@
enum Operation {
- OP_I1,
- OP_I2,
- OP_I4,
- OP_I8,
- OP_U1,
- OP_U2,
- OP_U4,
- OP_U8,
- OP_STR,
- OP_MOVE,
+ OP_NULL = 0,
+ OP_MOVE1,
+ OP_MOVE2,
+ OP_MOVE4,
+ OP_MOVE8,
OP_INSERT,
OP_DELETE,
OP_SHOW
};
+
+void encode2(int16_t data, uint8_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);
+}
+
+void encode4(int32_t data, uint8_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);
+}
+
+void encode8(int64_t data, uint8_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);
+}