diff --git a/app/src/control_msg.c b/app/src/control_msg.c index e8ae4681..a57d8cc2 100644 --- a/app/src/control_msg.c +++ b/app/src/control_msg.c @@ -63,17 +63,17 @@ static const char *const copy_key_labels[] = { static void write_position(uint8_t *buf, const struct sc_position *position) { - buffer_write32be(&buf[0], position->point.x); - buffer_write32be(&buf[4], position->point.y); - buffer_write16be(&buf[8], position->screen_size.width); - buffer_write16be(&buf[10], position->screen_size.height); + sc_write32be(&buf[0], position->point.x); + sc_write32be(&buf[4], position->point.y); + sc_write16be(&buf[8], position->screen_size.width); + sc_write16be(&buf[10], position->screen_size.height); } // write length (4 bytes) + string (non null-terminated) static size_t write_string(const char *utf8, size_t max_len, unsigned char *buf) { size_t len = sc_str_utf8_truncation_index(utf8, max_len); - buffer_write32be(buf, len); + sc_write32be(buf, len); memcpy(&buf[4], utf8, len); return 4 + len; } @@ -94,9 +94,9 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) { switch (msg->type) { case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE: buf[1] = msg->inject_keycode.action; - buffer_write32be(&buf[2], msg->inject_keycode.keycode); - buffer_write32be(&buf[6], msg->inject_keycode.repeat); - buffer_write32be(&buf[10], msg->inject_keycode.metastate); + sc_write32be(&buf[2], msg->inject_keycode.keycode); + sc_write32be(&buf[6], msg->inject_keycode.repeat); + sc_write32be(&buf[10], msg->inject_keycode.metastate); return 14; case SC_CONTROL_MSG_TYPE_INJECT_TEXT: { size_t len = @@ -106,20 +106,20 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) { } case SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT: buf[1] = msg->inject_touch_event.action; - buffer_write64be(&buf[2], msg->inject_touch_event.pointer_id); + sc_write64be(&buf[2], msg->inject_touch_event.pointer_id); write_position(&buf[10], &msg->inject_touch_event.position); uint16_t pressure = to_fixed_point_16(msg->inject_touch_event.pressure); - buffer_write16be(&buf[22], pressure); - buffer_write32be(&buf[24], msg->inject_touch_event.buttons); + sc_write16be(&buf[22], pressure); + sc_write32be(&buf[24], msg->inject_touch_event.buttons); return 28; case SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT: write_position(&buf[1], &msg->inject_scroll_event.position); - buffer_write32be(&buf[13], + sc_write32be(&buf[13], (uint32_t) msg->inject_scroll_event.hscroll); - buffer_write32be(&buf[17], + sc_write32be(&buf[17], (uint32_t) msg->inject_scroll_event.vscroll); - buffer_write32be(&buf[21], msg->inject_scroll_event.buttons); + sc_write32be(&buf[21], msg->inject_scroll_event.buttons); return 25; case SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON: buf[1] = msg->inject_keycode.action; @@ -128,7 +128,7 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) { buf[1] = msg->get_clipboard.copy_key; return 2; case SC_CONTROL_MSG_TYPE_SET_CLIPBOARD: - buffer_write64be(&buf[1], msg->set_clipboard.sequence); + sc_write64be(&buf[1], msg->set_clipboard.sequence); buf[9] = !!msg->set_clipboard.paste; size_t len = write_string(msg->set_clipboard.text, SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH, diff --git a/app/src/demuxer.c b/app/src/demuxer.c index 2d0449c3..35ea4c06 100644 --- a/app/src/demuxer.c +++ b/app/src/demuxer.c @@ -46,8 +46,8 @@ sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) { return false; } - uint64_t pts_flags = buffer_read64be(header); - uint32_t len = buffer_read32be(&header[8]); + uint64_t pts_flags = sc_read64be(header); + uint32_t len = sc_read32be(&header[8]); assert(len); if (av_new_packet(packet, len)) { diff --git a/app/src/device_msg.c b/app/src/device_msg.c index 9a93036b..4b4a4974 100644 --- a/app/src/device_msg.c +++ b/app/src/device_msg.c @@ -18,7 +18,7 @@ device_msg_deserialize(const unsigned char *buf, size_t len, msg->type = buf[0]; switch (msg->type) { case DEVICE_MSG_TYPE_CLIPBOARD: { - size_t clipboard_len = buffer_read32be(&buf[1]); + size_t clipboard_len = sc_read32be(&buf[1]); if (clipboard_len > len - 5) { return 0; // not available } @@ -36,7 +36,7 @@ device_msg_deserialize(const unsigned char *buf, size_t len, return 5 + clipboard_len; } case DEVICE_MSG_TYPE_ACK_CLIPBOARD: { - uint64_t sequence = buffer_read64be(&buf[1]); + uint64_t sequence = sc_read64be(&buf[1]); msg->ack_clipboard.sequence = sequence; return 9; } diff --git a/app/src/util/buffer_util.h b/app/src/util/buffer_util.h index 337bb262..a5456abf 100644 --- a/app/src/util/buffer_util.h +++ b/app/src/util/buffer_util.h @@ -1,5 +1,5 @@ -#ifndef BUFFER_UTIL_H -#define BUFFER_UTIL_H +#ifndef SC_BUFFER_UTIL_H +#define SC_BUFFER_UTIL_H #include "common.h" @@ -7,13 +7,13 @@ #include static inline void -buffer_write16be(uint8_t *buf, uint16_t value) { +sc_write16be(uint8_t *buf, uint16_t value) { buf[0] = value >> 8; buf[1] = value; } static inline void -buffer_write32be(uint8_t *buf, uint32_t value) { +sc_write32be(uint8_t *buf, uint32_t value) { buf[0] = value >> 24; buf[1] = value >> 16; buf[2] = value >> 8; @@ -21,25 +21,25 @@ buffer_write32be(uint8_t *buf, uint32_t value) { } static inline void -buffer_write64be(uint8_t *buf, uint64_t value) { - buffer_write32be(buf, value >> 32); - buffer_write32be(&buf[4], (uint32_t) value); +sc_write64be(uint8_t *buf, uint64_t value) { + sc_write32be(buf, value >> 32); + sc_write32be(&buf[4], (uint32_t) value); } static inline uint16_t -buffer_read16be(const uint8_t *buf) { +sc_read16be(const uint8_t *buf) { return (buf[0] << 8) | buf[1]; } static inline uint32_t -buffer_read32be(const uint8_t *buf) { +sc_read32be(const uint8_t *buf) { return ((uint32_t) buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; } static inline uint64_t -buffer_read64be(const uint8_t *buf) { - uint32_t msb = buffer_read32be(buf); - uint32_t lsb = buffer_read32be(&buf[4]); +sc_read64be(const uint8_t *buf) { + uint32_t msb = sc_read32be(buf); + uint32_t lsb = sc_read32be(&buf[4]); return ((uint64_t) msb << 32) | lsb; } diff --git a/app/tests/test_buffer_util.c b/app/tests/test_buffer_util.c index c7c13bdd..a9fec896 100644 --- a/app/tests/test_buffer_util.c +++ b/app/tests/test_buffer_util.c @@ -8,7 +8,7 @@ static void test_buffer_write16be(void) { uint16_t val = 0xABCD; uint8_t buf[2]; - buffer_write16be(buf, val); + sc_write16be(buf, val); assert(buf[0] == 0xAB); assert(buf[1] == 0xCD); @@ -18,7 +18,7 @@ static void test_buffer_write32be(void) { uint32_t val = 0xABCD1234; uint8_t buf[4]; - buffer_write32be(buf, val); + sc_write32be(buf, val); assert(buf[0] == 0xAB); assert(buf[1] == 0xCD); @@ -30,7 +30,7 @@ static void test_buffer_write64be(void) { uint64_t val = 0xABCD1234567890EF; uint8_t buf[8]; - buffer_write64be(buf, val); + sc_write64be(buf, val); assert(buf[0] == 0xAB); assert(buf[1] == 0xCD); @@ -45,7 +45,7 @@ static void test_buffer_write64be(void) { static void test_buffer_read16be(void) { uint8_t buf[2] = {0xAB, 0xCD}; - uint16_t val = buffer_read16be(buf); + uint16_t val = sc_read16be(buf); assert(val == 0xABCD); } @@ -53,7 +53,7 @@ static void test_buffer_read16be(void) { static void test_buffer_read32be(void) { uint8_t buf[4] = {0xAB, 0xCD, 0x12, 0x34}; - uint32_t val = buffer_read32be(buf); + uint32_t val = sc_read32be(buf); assert(val == 0xABCD1234); } @@ -62,7 +62,7 @@ static void test_buffer_read64be(void) { uint8_t buf[8] = {0xAB, 0xCD, 0x12, 0x34, 0x56, 0x78, 0x90, 0xEF}; - uint64_t val = buffer_read64be(buf); + uint64_t val = sc_read64be(buf); assert(val == 0xABCD1234567890EF); }