From eb64c6e56d633a7d5589ade40a898b6f17dde0c9 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 26 May 2024 00:31:59 +0300 Subject: [PATCH] ... --- CMakeLists.txt | 6 +++++- net/adc_netmessage.h | 31 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce1733..896298b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ set(ADC_DEVICE_HEADERS device/adc_device.h ) + +set(ADC_NETWORK_HEADERS + net/adc_netmessage.h) + option(BUILD_TESTS "Build tests" ON) if (BUILD_TESTS) @@ -52,7 +56,7 @@ endif(BUILD_TESTS) include(GNUInstallDirs) -add_library(${PROJECT_NAME} INTERFACE ${ADC_COMMON_HEADERS} ${ADC_DEVICE_HEADERS}) +add_library(${PROJECT_NAME} INTERFACE ${ADC_COMMON_HEADERS} ${ADC_DEVICE_HEADERS} ${ADC_NETWORK_HEADERS}) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) # target_link_libraries(${PROJECT_NAME} INTERFACE ASIO::ASIO) target_include_directories( diff --git a/net/adc_netmessage.h b/net/adc_netmessage.h index 45cc6f1..e8a9a38 100644 --- a/net/adc_netmessage.h +++ b/net/adc_netmessage.h @@ -33,6 +33,12 @@ template concept adc_from_bytes_func_c = std::invocable && std::convertible_to, VT>; +template +concept adc_netmsg_converter_c = requires(T t) { + { t.template serialize(std::declval()) } -> std::same_as; + { t.template deserialize(std::declval()) } -> std::same_as; +}; + struct AdcTheSameTypeTag { }; @@ -63,6 +69,12 @@ protected: AdcNetMessageInterface& operator=(const AdcNetMessageInterface&) = default; AdcNetMessageInterface& operator=(AdcNetMessageInterface&&) = default; + virtual void updateState() = 0; + +public: + typedef ByteStorageT byte_storage_t; + typedef StorageSeqT storage_seq_t; + template void appendBytes(const T& v, const Ts&... vs) { @@ -81,6 +93,8 @@ protected: { _byteStorage = ByteStorageT(); appendBytes(v, vs...); + + updateState(); } @@ -88,17 +102,19 @@ protected: void setBytes(IterT begin, IterT end) { _byteStorage = ByteStorageT(begin, end); + + updateState(); } template void appendBytes(IterT begin, IterT end) { std::copy(begin, end, std::back_inserter(_byteStorage)); + + updateState(); } -public: - typedef ByteStorageT byte_storage_t; - typedef StorageSeqT storage_seq_t; + virtual size_t byteSize() { @@ -135,6 +151,9 @@ public: using typename base_t::byte_storage_t; using typename base_t::storage_seq_t; + using base_t::appendBytes; + using base_t::setBytes; + using message_view_t = std::conditional_t, ByteStorageT, MessageViewT>; @@ -223,6 +242,12 @@ public: protected: MessageViewT _messageView; + + void updateState() override + { + if constexpr (!std::is_same_v) { + } + } };