...
This commit is contained in:
64
include/snipplib/network/snplib_netmsg.h
Normal file
64
include/snipplib/network/snplib_netmsg.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../utils/snplib_keyvalue_expr.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
A SIMPLE NETWORK MESSAGE
|
||||||
|
|
||||||
|
|
||||||
|
format:
|
||||||
|
keyword<key-value-delim-seq>value1<value-value-delim-seq>value2<value-value-delim-seq>value3...valueN
|
||||||
|
|
||||||
|
e.g.:
|
||||||
|
1) keyword-only:
|
||||||
|
'key1'
|
||||||
|
2) keyword-value (<key-value-delim-seq>=" "):
|
||||||
|
'key value'
|
||||||
|
2) keyword-value-seq (<key-value-delim-seq>=" =", <value-value-delim-seq>=", "):
|
||||||
|
'key = value1, value2, value3'
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace snplib
|
||||||
|
{
|
||||||
|
|
||||||
|
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>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using base_t = snplib_keyvalue_expr_t<ByteSeqT>;
|
||||||
|
|
||||||
|
std::conditional_t<base_t::mutableContent, std::vector<char>, void> _byteSeq{};
|
||||||
|
|
||||||
|
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,
|
||||||
|
.valseq_delim = SNPLIB_DEFAULT_NETMSG_VALUEVALUE_DELIM})
|
||||||
|
requires(base_t::mutableContent)
|
||||||
|
: base_t(_byteSeq, std::move(config))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~snplib_netmsg_t() = default;
|
||||||
|
|
||||||
|
template <snplib_char_range_c R>
|
||||||
|
static snplib_netmsg_t fromBytes(R&& r)
|
||||||
|
{
|
||||||
|
return base_t::fromByteSequence();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <snplib_char_range_c OR>
|
||||||
|
OR toBytes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace snplib
|
||||||
Reference in New Issue
Block a user