| 846 | } |
| 847 | |
| 848 | bool cbm_daemon_frame_header_decode(const uint8_t header[CBM_DAEMON_FRAME_HEADER_SIZE], |
| 849 | cbm_daemon_frame_t *frame) { |
| 850 | if (!header || !frame || header[FRAME_MAGIC_0] != 'C' || header[FRAME_MAGIC_1] != 'B' || |
| 851 | header[FRAME_MAGIC_2] != 'M' || header[FRAME_MAGIC_3] != 'D' || |
| 852 | header[FRAME_VERSION] != CBM_DAEMON_RENDEZVOUS_FRAME_VERSION) { |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | cbm_daemon_frame_type_t type = (cbm_daemon_frame_type_t)header[FRAME_TYPE]; |
| 857 | uint32_t length = ((uint32_t)header[FRAME_LENGTH_3] << 24) | |
| 858 | ((uint32_t)header[FRAME_LENGTH_2] << 16) | |
| 859 | ((uint32_t)header[FRAME_LENGTH_1] << 8) | (uint32_t)header[FRAME_LENGTH_0]; |
| 860 | if (!frame_type_valid(type) || length > CBM_DAEMON_MAX_FRAME_SIZE) { |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | frame->type = type; |
| 865 | frame->flags = |
| 866 | (uint16_t)(((uint16_t)header[FRAME_FLAGS_HI] << 8) | (uint16_t)header[FRAME_FLAGS_LO]); |
| 867 | frame->length = length; |
| 868 | return true; |
| 869 | } |
no test coverage detected