...
This commit is contained in:
@@ -33,6 +33,17 @@ concept snplib_char_view_c = std::ranges::view<T> && std::same_as<std::ranges::r
|
||||
template <typename T, typename CharT = char>
|
||||
concept snplib_view_or_output_char_range_c = snplib_char_view_c<T> || snplib_output_char_range_c<T, CharT>;
|
||||
|
||||
template <typename T, typename CharT = char>
|
||||
concept snplib_range_of_char_views_or_output_ranges_c =
|
||||
std::ranges::range<T> && snplib_view_or_output_char_range_c<std::ranges::range_value_t<T>, CharT>;
|
||||
|
||||
|
||||
template <typename T, typename CharT = char>
|
||||
concept snplib_char_range_or_range_of_char_ranges_c =
|
||||
snplib_char_range_c<T, CharT> ||
|
||||
(std::ranges::range<T> && snplib_char_range_c<std::ranges::range_value_t<T>, CharT>);
|
||||
|
||||
|
||||
/* std::chrono related concepts */
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utils/snplib_keyvalue_expr.h"
|
||||
#include "snplib_network.h"
|
||||
|
||||
/*
|
||||
A SIMPLE NETWORK MESSAGE
|
||||
A SIMPLE NETWORK MESSAGE IMPLEMENTATION
|
||||
|
||||
|
||||
format:
|
||||
@@ -26,23 +27,20 @@ static constexpr char SNPLIB_DEFAULT_NETMSG_KEYVALUE_DELIM[] = "=";
|
||||
static constexpr char SNPLIB_DEFAULT_NETMSG_VALUEVALUE_DELIM[] = ",";
|
||||
|
||||
|
||||
template <snplib_char_range_c ByteSeqT = std::vector<char>>
|
||||
class snplib_netmsg_t : public snplib_keyvalue_expr_t<ByteSeqT>
|
||||
template <snplib_char_range_c CharRangeT, snplib_net_proto_c<CharRangeT> ProtoT>
|
||||
class snplib_netmsg_t : public snplib_keyvalue_expr_t<CharRangeT>, protected ProtoT
|
||||
{
|
||||
protected:
|
||||
using base_t = snplib_keyvalue_expr_t<ByteSeqT>;
|
||||
|
||||
std::conditional_t<base_t::mutableContent, std::vector<char>, void> _byteSeq{};
|
||||
using base_t = snplib_keyvalue_expr_t<CharRangeT>;
|
||||
|
||||
public:
|
||||
using base_t::config_t;
|
||||
|
||||
using base_t::base_t;
|
||||
|
||||
snplib_netmsg_t(base_t::config_t config = {.keyval_delim = SNPLIB_DEFAULT_NETMSG_KEYVALUE_DELIM,
|
||||
snplib_netmsg_t(CharRangeT& r,
|
||||
base_t::config_t config = {.keyval_delim = SNPLIB_DEFAULT_NETMSG_KEYVALUE_DELIM,
|
||||
.valseq_delim = SNPLIB_DEFAULT_NETMSG_VALUEVALUE_DELIM})
|
||||
requires(base_t::mutableContent)
|
||||
: base_t(_byteSeq, std::move(config))
|
||||
requires std::is_default_constructible_v<ProtoT>
|
||||
: base_t(r, std::move(config)), ProtoT()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,6 +56,12 @@ public:
|
||||
template <snplib_char_range_c OR>
|
||||
OR toBytes()
|
||||
{
|
||||
return ProtoT::template toBytes<OR>(this->_byteSeq);
|
||||
}
|
||||
|
||||
std::vector<char> toBytes()
|
||||
{
|
||||
return toBytes<std::vector<char>>();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,10 +24,23 @@ concept snplib_net_endpoint_c = requires(T t, const T t_const) {
|
||||
};
|
||||
|
||||
|
||||
template <typename T, typename CharRangeT = std::vector<char>>
|
||||
concept snplib_net_proto_c = requires(T t) {
|
||||
// from session-level representation to transport-level one
|
||||
{ t.toBytes(std::declval<CharRangeT>()) } -> snplib_char_range_or_range_of_char_ranges_c;
|
||||
|
||||
requires(
|
||||
requires {
|
||||
{ t.fromBytes(std::declval<std::span<const char>>()) } -> snplib_char_range_c;
|
||||
} ||
|
||||
requires {
|
||||
{ t.fromBytes(std::declval<std::span<char>>()) } -> snplib_char_range_c;
|
||||
});
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept snplib_net_message_c = requires(T t) {
|
||||
{ t.toBytes() } -> snplib_output_char_range_c;
|
||||
{ t.toBytes() } -> snplib_char_range_or_range_of_char_ranges_c;
|
||||
|
||||
// can be constructed from contiguous byte range
|
||||
requires(
|
||||
|
||||
@@ -13,14 +13,14 @@ namespace snplib
|
||||
template <typename T>
|
||||
concept snplib_serializable_c = requires { snplib_serializer_t<std::remove_cvref_t<T>>{}; };
|
||||
|
||||
template <snplib_char_range_c ByteSeqT>
|
||||
requires(std::ranges::viewable_range<ByteSeqT> && !std::ranges::borrowed_range<ByteSeqT>)
|
||||
template <snplib_char_range_c CharRangeT>
|
||||
requires(std::ranges::viewable_range<CharRangeT> && !std::ranges::borrowed_range<CharRangeT>)
|
||||
class snplib_keyvalue_expr_t
|
||||
{
|
||||
public:
|
||||
static constexpr bool mutableContent = snplib_output_char_range_c<ByteSeqT>;
|
||||
static constexpr bool mutableContent = snplib_output_char_range_c<CharRangeT>;
|
||||
static constexpr bool contiguousContent =
|
||||
std::ranges::viewable_range<ByteSeqT> && std::ranges::contiguous_range<ByteSeqT>;
|
||||
std::ranges::viewable_range<CharRangeT> && std::ranges::contiguous_range<CharRangeT>;
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
@@ -32,15 +32,15 @@ public:
|
||||
std::string_view valseq_delim{DEFAULT_VALSEQ_DELIM_SEQ};
|
||||
};
|
||||
|
||||
constexpr snplib_keyvalue_expr_t(ByteSeqT& bytes, config_t cfg = config_t{}) : _byteSeq(bytes), _config(cfg)
|
||||
constexpr snplib_keyvalue_expr_t(CharRangeT& bytes, config_t cfg = config_t{}) : _byteSeq(bytes), _config(cfg)
|
||||
{
|
||||
fromByteSequence(bytes, cfg);
|
||||
fromCharRange(bytes, cfg);
|
||||
}
|
||||
|
||||
virtual ~snplib_keyvalue_expr_t() = default;
|
||||
|
||||
// parse from char range
|
||||
error_t fromByteSequence(ByteSeqT& bytes, config_t cfg = config_t{})
|
||||
error_t fromCharRange(CharRangeT& bytes, config_t cfg = config_t{})
|
||||
{
|
||||
_byteSeq = bytes;
|
||||
_config = cfg;
|
||||
@@ -222,10 +222,11 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
ByteSeqT& _byteSeq;
|
||||
CharRangeT& _byteSeq;
|
||||
|
||||
std::conditional_t<contiguousContent, std::string_view, std::ranges::subrange<typename ByteSeqT::iterator>> _key{};
|
||||
std::conditional_t<contiguousContent, std::string_view, std::ranges::subrange<typename ByteSeqT::iterator>>
|
||||
std::conditional_t<contiguousContent, std::string_view, std::ranges::subrange<typename CharRangeT::iterator>>
|
||||
_key{};
|
||||
std::conditional_t<contiguousContent, std::string_view, std::ranges::subrange<typename CharRangeT::iterator>>
|
||||
_value{};
|
||||
std::vector<decltype(_value)> _valueSeq{};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user