From 04fa990b0ced02a7011ad4801d8c956cbc1f65ab Mon Sep 17 00:00:00 2001 From: vperus Date: Sun, 7 Nov 2021 14:56:33 +0200 Subject: [input_common] Add completion test for CalibrationConfigurationJob --- src/input_common/helpers/udp_protocol.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/input_common/helpers') diff --git a/src/input_common/helpers/udp_protocol.h b/src/input_common/helpers/udp_protocol.h index bcba12c58..2d5d54ddb 100644 --- a/src/input_common/helpers/udp_protocol.h +++ b/src/input_common/helpers/udp_protocol.h @@ -54,6 +54,18 @@ struct Message { template constexpr Type GetMessageType(); +template +Message CreateMessage(const u32 magic, const T data, const u32 sender_id) { + boost::crc_32_type crc; + Header header{ + magic, PROTOCOL_VERSION, sizeof(T) + sizeof(Type), 0, sender_id, GetMessageType(), + }; + Message message{header, data}; + crc.process_bytes(&message, sizeof(Message)); + message.header.crc = crc.checksum(); + return message; +} + namespace Request { enum RegisterFlags : u8 { @@ -101,14 +113,7 @@ static_assert(std::is_trivially_copyable_v, */ template Message Create(const T data, const u32 client_id = 0) { - boost::crc_32_type crc; - Header header{ - CLIENT_MAGIC, PROTOCOL_VERSION, sizeof(T) + sizeof(Type), 0, client_id, GetMessageType(), - }; - Message message{header, data}; - crc.process_bytes(&message, sizeof(Message)); - message.header.crc = crc.checksum(); - return message; + return CreateMessage(CLIENT_MAGIC, data, client_id); } } // namespace Request -- cgit v1.2.3