diff options
Diffstat (limited to 'shared/protocol.c')
-rw-r--r-- | shared/protocol.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/shared/protocol.c b/shared/protocol.c index 943604c..c1217b2 100644 --- a/shared/protocol.c +++ b/shared/protocol.c @@ -6,14 +6,14 @@ extern "C" { #endif -cd_cmd_id_t g_cd_protocol_fresh_message_id = 0; +cd_cmd_id_t g_cd_protocol_fresh_message_id = 0; size_t cd_cmd_sizeof(uint8_t data[CD_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) { cd_cmd_opcode_t opcode = data[0]; if (CD_CMD_HANDLERS_SIZE[opcode] > 0) return CD_CMD_HANDLERS_SIZE[opcode]; cd_s_bin *copy = cd_bin_s_alloc(data_length, data); - size_t length = (*CD_CMD_HANDLERS_SIZEOF[opcode])(copy); + size_t length = (*CD_CMD_HANDLERS_SIZEOF[opcode])(copy); CD_FREE(copy); @@ -39,19 +39,14 @@ size_t cd_cmd_sizeof(uint8_t data[CD_SERIAL_READ_BUFFER_SIZE], uint8_t data_leng * size += cd_bin_ntohd(&data->data[dyn_member_offset], dyn_member_size); * return size; */ -#define CD_DYN_MEMBER_SIZEOF(data, struct_t, length_field) \ - sizeof(struct_t) + ( \ - (data->bytes >= (offsetof(struct_t, length_field) + sizeof(((struct_t*)0)->length_field))) ? \ - (cd_bin_ntohd(&data->data[offsetof(struct_t, length_field)], sizeof(((struct_t*)0)->length_field))) :\ - 0); - -size_t cd_cmd_response_sizeof(cd_s_bin* data) { - return CD_DYN_MEMBER_SIZEOF(data, cd_s_cmd_response, response_size); -} +#define CD_DYN_MEMBER_SIZEOF(data, struct_t, length_field) \ + sizeof(struct_t) + ((data->bytes >= (offsetof(struct_t, length_field) + sizeof(((struct_t *)0)->length_field))) \ + ? (cd_bin_ntohd(&data->data[offsetof(struct_t, length_field)], sizeof(((struct_t *)0)->length_field))) \ + : 0); -cd_cmd_id_t cd_protocol_fresh_message_id() { - return g_cd_protocol_fresh_message_id++; -} +size_t cd_cmd_response_sizeof(cd_s_bin *data) { return CD_DYN_MEMBER_SIZEOF(data, cd_s_cmd_response, response_size); } + +cd_cmd_id_t cd_protocol_fresh_message_id() { return g_cd_protocol_fresh_message_id++; } #ifdef __cplusplus } |