Some minor updates

This commit is contained in:
WolverinDEV 2021-07-23 14:59:43 +02:00
parent 9f03f33a23
commit f127894110
5 changed files with 42 additions and 37 deletions

View File

@ -3,6 +3,23 @@
#include <any>
#include <string>
#include <cstddef>
#include <chrono>
#define DEFINE_CONVERTER_ENUM(class, size_type) \
namespace ts { \
template <> \
struct converter<class> { \
static constexpr bool supported{true}; \
static constexpr bool references{false}; \
\
static constexpr std::string(*to_string)(const std::any&) = [](const std::any& val) { \
return std::to_string(std::any_cast<class>(val)); \
}; \
static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \
return ((class(*)(const std::string_view&)) ts::converter<size_type>::from_string_view)(val); \
}; \
}; \
}
namespace ts {
typedef long double long_double;
@ -17,7 +34,7 @@ namespace ts {
static constexpr T(*from_string_view)(const std::string_view&) = nullptr;
};
#define DECLARE_CONVERTER(type, decode, encode, references_) \
#define DECLARE_CONVERTER(type, decode, encode, references_) \
template <> \
struct converter<type> { \
static constexpr bool supported{true}; \
@ -27,11 +44,11 @@ namespace ts {
static constexpr type(*from_string_view)(const std::string_view&) = decode; \
};
#define CONVERTER_METHOD_DECODE(type, name) type name(const std::string_view& str)
#define CONVERTER_METHOD_ENCODE(type, name) std::string name(const std::any& value)
#define CONVERTER_METHOD_DECODE(type, name) type name(const std::string_view& str)
#define CONVERTER_METHOD_ENCODE(type, name) std::string name(const std::any& value)
/* helper for primitive types */
#define CONVERTER_PRIMITIVE(type, references) \
#define CONVERTER_PRIMITIVE(type, references) \
namespace impl { \
CONVERTER_METHOD_DECODE(type, converter_ ##type ##_decode); \
CONVERTER_METHOD_ENCODE(type, converter_ ##type ##_encode); \
@ -68,27 +85,21 @@ namespace ts {
template <int length>
struct converter<char[length]> {
using type = char[length];
static constexpr bool supported = true;
static constexpr bool supported{true};
static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::string(std::any_cast<const char*>(value), length - 1); };
};
#undef CONVERTER_PRIMITIVE
}
/* We're not enabling this since we don't transport the unit
template <typename Rep, typename Period>
struct converter<std::chrono::duration<Rep, Period>> {
using type = std::chrono::duration<Rep, Period>;
static constexpr bool supported{true};
#define DEFINE_CONVERTER_ENUM(class, size_type) \
namespace ts { \
template <> \
struct converter<class> { \
static constexpr bool supported{true}; \
static constexpr bool references{false}; \
\
static constexpr std::string(*to_string)(const std::any&) = [](const std::any& val) { \
return std::to_string(std::any_cast<class>(val)); \
}; \
static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \
return ((class(*)(const std::string_view&)) ts::converter<size_type>::from_string_view)(val); \
}; \
}; \
static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::to_string(std::any_cast<type>(value)); };
}
*/
#undef CONVERTER_PRIMITIVE
}
/* DO NOT REMOVE ME (NL warning) */

View File

@ -84,7 +84,7 @@ namespace ts {
/**
* Helper class for tasks which could be executed multiple times.
* It will avoid execution stacking while the task is executing.
* The task will never be executed twice only sequential.
* The task will never be executed twice, only sequential.
* Note: If the `multi_shot_task` handle gets deleted no enqueued tasks will be executed.
*/
struct multi_shot_task {

View File

@ -6,7 +6,6 @@
#include <mutex>
#include "./Packet.h"
#define DEBUG_ACKNOWLEDGE
namespace ts::connection {
class AcknowledgeManager {
public:

View File

@ -16,11 +16,9 @@ namespace ts::connection {
void reset();
//TeamSpeak old
bool setupSharedSecret(const std::string& /* alpha */, const std::string& /* beta */, ecc_key* /* remote_public_key */, ecc_key* /* own_private_key */, std::string &/* error */);
bool setupSharedSecret(const std::string& /* alpha */, const std::string& /* beta */, const std::string& /* shared_key */, std::string &/* error */);
//TeamSpeak new
bool setupSharedSecretNew(const std::string& alpha, const std::string& beta, const char privateKey[32], const char publicKey[32]);
bool encrypt(

View File

@ -19,9 +19,6 @@ namespace ts::protocol {
ACK = 0x06,
ACK_LOW = 0x07,
INIT1 = 0x08,
PACKET_MAX = INIT1,
UNDEFINED = 0xFF
};
class PacketIdManager {