diff --git a/include/snipplib/network/snplib_netproto.h b/include/snipplib/network/snplib_netproto.h index 7b9517d..5fa38cb 100644 --- a/include/snipplib/network/snplib_netproto.h +++ b/include/snipplib/network/snplib_netproto.h @@ -237,7 +237,7 @@ struct netproto_stopseq_t { }; -static_assert(net_connection_proto_c>, "!!!"); +static_assert(net_repr_proto_c>, "!!!"); /* BINARY BLOB PROTOCOL */ @@ -374,7 +374,7 @@ struct netproto_binary_blob_t { -static_assert(net_connection_proto_c>, "!!!"); +static_assert(net_repr_proto_c>, "!!!"); diff --git a/include/snipplib/network/snplib_network.h b/include/snipplib/network/snplib_network.h index f86ad76..306dd69 100644 --- a/include/snipplib/network/snplib_network.h +++ b/include/snipplib/network/snplib_network.h @@ -42,8 +42,28 @@ concept net_message_c = requires(const T t_const) { }); }; +template +concept net_repr_proto_result_c = requires(T t) { + typename T::result_flag_t; + + []() { + [[maybe_unused]] static constexpr std::array arr{T::result_flag_t::OK, + // needs more data + T::result_flag_t::NOT_ENOUGH_DATA, + // given byte sequence is invalid + T::result_flag_t::INVALID_DATA}; + }(); + + // static_cast(T::NOT_ENOUGH_DATA) != false; + // static_cast(T::INVALID_DATA) != false; + + std::same_as; + + char_range_or_range_of_char_ranges_c; +}; + // template -// concept net_connection_proto_c = requires(T t) { +// concept net_repr_proto_c = requires(T t) { // requires net_message_c; // // from application-level representation to session-level one @@ -63,13 +83,16 @@ concept net_message_c = requires(const T t_const) { // }; +// OSI representation level protocol template > -concept net_connection_proto_c = requires(T t) { - // from byte sequence payload representation to "network"-ready (session) one (a byte sequence to be sent over - // transport level (TCP, UDP etc...)) +concept net_repr_proto_c = requires(T t) { + // from payload byte sequence representation to "network"-ready (Representation Level in the OSI model) one (a byte + // sequence to be sent over transport level (TCP, UDP etc...)) + // The method may add some "markers" (e.g. "stop symbols") to the input byte sequence to encode + // sequence of messages { t.toNetwork(std::declval()) } -> char_range_or_range_of_char_ranges_c; - // from session level representation to byte sequence payload representation + // from "network"-ready level representation to byte sequence payload representation requires( requires { { t.fromNetwork(std::declval>()) } -> ret_expected_c; diff --git a/include/snipplib/network/snplib_network_asio.h b/include/snipplib/network/snplib_network_asio.h index ecbc06f..5d270a8 100644 --- a/include/snipplib/network/snplib_network_asio.h +++ b/include/snipplib/network/snplib_network_asio.h @@ -37,12 +37,12 @@ concept transport_dgram_proto_c = -template +template class net_connection_t { public: typedef NETMSG_T message_t; - typedef NETPROTO_T netproto_t; + typedef NET_REPR_PROTO_T net_repr_proto_t; typedef std::error_code error_t; typedef std::expected recv_result_t; @@ -165,6 +165,7 @@ protected: -static_assert(net_connection_c, netproto_stopseq_t<>>>, "!!!"); +static_assert(net_connection_c, ::asio::ip::tcp, netproto_stopseq_t<>>>, + "!!!"); } // namespace snplib::asio \ No newline at end of file