Compare commits
4 Commits
v1.0.4
...
32d30c7f44
| Author | SHA1 | Date | |
|---|---|---|---|
| 32d30c7f44 | |||
| 04ca498b0c | |||
| 4b2e4ca132 | |||
| efcfae69db |
@@ -14,8 +14,7 @@ using UpgradeTowerFields = std::tuple<
|
|||||||
sp::BitField<std::uint16_t,
|
sp::BitField<std::uint16_t,
|
||||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||||
>,
|
>
|
||||||
sp::VarInt //<- just for testing
|
|
||||||
>;
|
>;
|
||||||
|
|
||||||
DeclarePacket(UpgradeTower){
|
DeclarePacket(UpgradeTower){
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cxxabi.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::string GetBasicClassName(const T& a_Value) {
|
|
||||||
int status;
|
|
||||||
char* demangled = abi::__cxa_demangle(typeid(a_Value).name(), 0, 0, &status);
|
|
||||||
if (status != 0)
|
|
||||||
return "";
|
|
||||||
return std::string(demangled);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::string GetBasicClassName() {
|
|
||||||
int status;
|
|
||||||
char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
|
|
||||||
if (status != 0)
|
|
||||||
return "";
|
|
||||||
return std::string(demangled);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct Reflector {
|
|
||||||
static std::string GetClassName() {
|
|
||||||
return GetBasicClassName<T>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Reflector<std::string> {
|
|
||||||
static std::string GetClassName() {
|
|
||||||
return "std::string";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
struct Reflector<std::map<K, V>> {
|
|
||||||
static std::string GetClassName();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct Reflector<std::vector<T>> {
|
|
||||||
static std::string GetClassName();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::string Reflector<std::vector<T>>::GetClassName() {
|
|
||||||
return "std::vector<" + Reflector<T>::GetClassName() + ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
std::string Reflector<std::map<K, V>>::GetClassName() {
|
|
||||||
return "std::map<" + Reflector<K>::GetClassName() + ", " + Reflector<V>::GetClassName() + ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
@@ -51,48 +50,4 @@ void TupleForEach(TFunc&& func, TTuple&& tuple) {
|
|||||||
details::TupleForEachHelper<TupleSize>::Exec(std::forward<TTuple>(tuple), std::forward<TFunc>(func));
|
details::TupleForEachHelper<TupleSize>::Exec(std::forward<TTuple>(tuple), std::forward<TFunc>(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace details {
|
|
||||||
|
|
||||||
template <typename T, typename U = void>
|
|
||||||
struct is_mappish_impl : std::false_type {};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct is_mappish_impl<T, std::void_t<typename T::key_type, typename T::mapped_type,
|
|
||||||
decltype(std::declval<T&>()[std::declval<const typename T::key_type&>()])>> : std::true_type {};
|
|
||||||
|
|
||||||
template <typename T, typename U = void>
|
|
||||||
struct is_vectish_impl : std::false_type {};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct is_vectish_impl<T,
|
|
||||||
std::void_t<typename T::value_type, decltype(std::declval<T&>()[std::declval<const typename T::value_type&>()])>>
|
|
||||||
: std::true_type {};
|
|
||||||
|
|
||||||
template <typename T, typename U = void>
|
|
||||||
struct is_pairish_impl : std::false_type {};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct is_pairish_impl<T,
|
|
||||||
std::void_t<typename T::first_type, decltype(std::declval<T&>()[std::declval<const typename T::first_type&>()])>>
|
|
||||||
: std::true_type {};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using is_general_t = std::integral_constant<bool,
|
|
||||||
(std::is_same_v<T, std::string> || (!std::is_same_v<T, char> && !std::is_same_v<T, unsigned char> && !std::is_arithmetic_v<T> &&
|
|
||||||
!is_pairish_impl<T>::value && !is_mappish_impl<T>::value && !is_vectish_impl<T>::value))>;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using is_primitive =
|
|
||||||
std::integral_constant<bool, std::is_same_v<T, char> || std::is_same_v<T, unsigned char> || std::is_arithmetic_v<T>>;
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <sp/protocol/MessagePrinter.h>
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
@@ -58,9 +57,4 @@ class VarInt {
|
|||||||
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
|
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
inline std::string PrintData(const VarInt& a_VarInt) {
|
|
||||||
return PrintData(a_VarInt.GetValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ using PacketMessage = Message<
|
|||||||
option::ReadOperations, // add read() operation
|
option::ReadOperations, // add read() operation
|
||||||
option::WriteOperations, // add write() operation
|
option::WriteOperations, // add write() operation
|
||||||
option::WriteId, // write id before data
|
option::WriteId, // write id before data
|
||||||
option::Handler<PacketHandler>, // add dispatch() operation
|
option::Handler<PacketHandler> // add dispatch() operation
|
||||||
option::DebugPrint // add ToString() operator
|
|
||||||
>;
|
>;
|
||||||
|
|
||||||
#define PacketConstructor(packetName) \
|
#define PacketConstructor(packetName) \
|
||||||
@@ -24,8 +23,7 @@ using PacketMessage = Message<
|
|||||||
|
|
||||||
#define DeclarePacket(packetName) \
|
#define DeclarePacket(packetName) \
|
||||||
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
|
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
|
||||||
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>>, \
|
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>>
|
||||||
sp::option::ToStringImpl<packetName##Packet>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class IOInterface<TcpTag> : private NonCopyable {
|
|||||||
IOInterface();
|
IOInterface();
|
||||||
IOInterface(const std::string& a_Host, std::uint16_t a_Port);
|
IOInterface(const std::string& a_Host, std::uint16_t a_Port);
|
||||||
IOInterface(IOInterface&& a_Other);
|
IOInterface(IOInterface&& a_Other);
|
||||||
IOInterface& operator=(IOInterface&& a_Other);
|
|
||||||
virtual ~IOInterface();
|
virtual ~IOInterface();
|
||||||
|
|
||||||
DataBuffer Read(std::size_t a_Amount);
|
DataBuffer Read(std::size_t a_Amount);
|
||||||
|
|||||||
@@ -48,12 +48,11 @@ Stream<IOTag, MessageDispatcher, MessageFactory, TOptions...>::Stream(
|
|||||||
template <typename IOTag, typename MessageDispatcher, typename MessageFactory, typename... TOptions>
|
template <typename IOTag, typename MessageDispatcher, typename MessageFactory, typename... TOptions>
|
||||||
void Stream<IOTag, MessageDispatcher, MessageFactory, TOptions...>::SendMessage(const MessageBase& a_Message) {
|
void Stream<IOTag, MessageDispatcher, MessageFactory, TOptions...>::SendMessage(const MessageBase& a_Message) {
|
||||||
DataBuffer data = a_Message.Write();
|
DataBuffer data = a_Message.Write();
|
||||||
TupleForEach([&data](const auto&... a_Options) {
|
DataBuffer encapsulated = std::apply([&data](const auto&... a_Options) {
|
||||||
data = Encapsulate(data, a_Options...);
|
return Encapsulate(data, a_Options...);
|
||||||
}, m_Options);
|
}, m_Options);
|
||||||
DataBuffer finalData;
|
DataBuffer finalData;
|
||||||
finalData.Reserve(data.GetSize() + sizeof(VarInt::MAX_VALUE));
|
finalData << VarInt{encapsulated.GetSize()} << encapsulated;
|
||||||
finalData << VarInt{data.GetSize()} << data;
|
|
||||||
m_Interface.Write(finalData);
|
m_Interface.Write(finalData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +93,8 @@ void Stream<IOTag, MessageDispatcher, MessageFactory, TOptions...>::RecieveMessa
|
|||||||
DataBuffer buffer;
|
DataBuffer buffer;
|
||||||
buffer = m_Interface.Read(lenghtValue);
|
buffer = m_Interface.Read(lenghtValue);
|
||||||
|
|
||||||
TupleForEach([&buffer, lenghtValue](const auto&... a_Options) {
|
buffer = std::apply([&buffer, lenghtValue](const auto&... a_Options) {
|
||||||
buffer = Decapsulate(buffer, a_Options...);
|
return Decapsulate(buffer, a_Options...);
|
||||||
}, m_Options);
|
}, m_Options);
|
||||||
|
|
||||||
VarInt packetType;
|
VarInt packetType;
|
||||||
|
|||||||
@@ -70,32 +70,29 @@ class BitField {
|
|||||||
* \tparam ValueType the type of the value to store
|
* \tparam ValueType the type of the value to store
|
||||||
* \tparam IAlignment 0 means no alignment
|
* \tparam IAlignment 0 means no alignment
|
||||||
*/
|
*/
|
||||||
template <typename ValueType, std::size_t IAlignment>
|
template <typename ValueType, int IAlignment>
|
||||||
class Field {
|
class Field {
|
||||||
public:
|
public:
|
||||||
using StorageType = ValueType;
|
|
||||||
static constexpr std::size_t AlignmentValue = IAlignment;
|
|
||||||
|
|
||||||
// Provide an access to the stored value
|
// Provide an access to the stored value
|
||||||
StorageType& GetValue() {
|
ValueType& GetValue() {
|
||||||
return m_Value;
|
return m_Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StorageType& GetValue() const {
|
const ValueType& GetValue() const {
|
||||||
return m_Value;
|
return m_Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Field& operator=(const StorageType& value) {
|
Field& operator=(const ValueType& value) {
|
||||||
m_Value = value;
|
m_Value = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr std::size_t GetAlignment() const {
|
constexpr int GetAlignment() const {
|
||||||
return IAlignment;
|
return IAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StorageType m_Value;
|
ValueType m_Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|||||||
@@ -14,5 +14,3 @@ template <typename TBase, typename... TOptions>
|
|||||||
class MessageBase : public details::MessageImplBuilder<TBase, TOptions...>::Type {};
|
class MessageBase : public details::MessageImplBuilder<TBase, TOptions...>::Type {};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
||||||
#include <sp/protocol/message/MessagePrinterImpl.h>
|
|
||||||
@@ -17,7 +17,7 @@ namespace sp {
|
|||||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||||
class MessageDispatcher {
|
class MessageDispatcher {
|
||||||
private:
|
private:
|
||||||
std::map<MessageIdType, std::vector<MessageHandler*>> m_Handlers;
|
std::map<MessageIdType, std::vector<std::shared_ptr<MessageHandler>>> m_Handlers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using MessageBaseType = MessageBase;
|
using MessageBaseType = MessageBase;
|
||||||
@@ -38,20 +38,18 @@ class MessageDispatcher {
|
|||||||
* \param type The packet type
|
* \param type The packet type
|
||||||
* \param handler The packet handler
|
* \param handler The packet handler
|
||||||
*/
|
*/
|
||||||
void RegisterHandler(MessageIdType a_MessageType, MessageHandler* a_Handler);
|
void RegisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Unregister a packet handler
|
* \brief Unregister a packet handler
|
||||||
* \param type The packet type
|
* \param type The packet type
|
||||||
* \param handler The packet handler
|
* \param handler The packet handler
|
||||||
*/
|
*/
|
||||||
void UnregisterHandler(MessageIdType a_MessageType, MessageHandler* a_Handler);
|
void UnregisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Unregister a packet handler
|
* \brief Unregister a packet handler
|
||||||
* \param handler The packet handler
|
* \param handler The packet handler
|
||||||
*/
|
*/
|
||||||
void UnregisterHandler(MessageHandler* a_Handler);
|
void UnregisterHandler(const std::shared_ptr<MessageHandler>& a_Handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <sp/protocol/message/MessageDispatcherImpl.inl>
|
#include <sp/protocol/message/MessageDispatcherImpl.inl>
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <sp/common/Templates.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
template <typename T, std::enable_if_t<details::is_general_t<T>::value, bool> = true>
|
|
||||||
inline std::string PrintData(const T& a_Data);
|
|
||||||
|
|
||||||
template <typename T, std::enable_if_t<details::is_primitive<T>::value, bool> = true>
|
|
||||||
inline std::string PrintData(T a_Data) {
|
|
||||||
return std::to_string(a_Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline std::string PrintData(const std::string& a_Data) {
|
|
||||||
return "\"" + a_Data + "\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
std::string PrintData(const std::pair<K, V>& a_Data);
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
std::string PrintData(const std::map<K, V>& a_Data);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::string PrintData(const std::vector<T>& a_Data);
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
std::string PrintData(const std::pair<K, V>& a_Data) {
|
|
||||||
return "{" + PrintData(a_Data.first) + " => " + PrintData(a_Data.second) + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
std::string PrintData(const std::map<K, V>& a_Data) {
|
|
||||||
std::string result = "{";
|
|
||||||
for (const auto& pair : a_Data) {
|
|
||||||
result += PrintData(pair) + ", ";
|
|
||||||
}
|
|
||||||
return result.substr(0, result.size() - 2) + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::string PrintData(const std::vector<T>& a_Data) {
|
|
||||||
std::string result = "{";
|
|
||||||
for (const T& value : a_Data) {
|
|
||||||
result += PrintData(value) + ", ";
|
|
||||||
}
|
|
||||||
return result.substr(0, result.size() - 2) + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
@@ -31,7 +31,7 @@ struct ArrayFiller<TBase, TMessage, TMessages...> {
|
|||||||
template <typename TBase, typename TMessage>
|
template <typename TBase, typename TMessage>
|
||||||
struct ArrayFiller<TBase, TMessage> {
|
struct ArrayFiller<TBase, TMessage> {
|
||||||
static void ArrayAppend(details::ArrayType<TBase>& array) {
|
static void ArrayAppend(details::ArrayType<TBase>& array) {
|
||||||
array.emplace_back([]() -> std::unique_ptr<TBase> { return std::make_unique<TMessage>(); });
|
array.push_back([]() -> std::unique_ptr<TBase> { return std::make_unique<TMessage>(); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||||
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::RegisterHandler(MessageIdType a_MessageType, MessageHandler* a_Handler) {
|
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::RegisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler) {
|
||||||
assert(a_Handler);
|
|
||||||
auto found = std::find(m_Handlers[a_MessageType].begin(), m_Handlers[a_MessageType].end(), a_Handler);
|
auto found = std::find(m_Handlers[a_MessageType].begin(), m_Handlers[a_MessageType].end(), a_Handler);
|
||||||
if (found == m_Handlers[a_MessageType].end())
|
if (found == m_Handlers[a_MessageType].end())
|
||||||
m_Handlers[a_MessageType].push_back(a_Handler);
|
m_Handlers[a_MessageType].push_back(a_Handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||||
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::UnregisterHandler(MessageIdType a_MessageType, MessageHandler* a_Handler) {
|
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::UnregisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler) {
|
||||||
auto found = std::find(m_Handlers[a_MessageType].begin(), m_Handlers[a_MessageType].end(), a_Handler);
|
auto found = std::find(m_Handlers[a_MessageType].begin(), m_Handlers[a_MessageType].end(), a_Handler);
|
||||||
if (found != m_Handlers[a_MessageType].end())
|
if (found != m_Handlers[a_MessageType].end())
|
||||||
m_Handlers[a_MessageType].erase(found);
|
m_Handlers[a_MessageType].erase(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||||
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::UnregisterHandler(MessageHandler* a_Handler) {
|
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::UnregisterHandler(const std::shared_ptr<MessageHandler>& a_Handler) {
|
||||||
for (auto& pair : m_Handlers) {
|
for (auto& pair : m_Handlers) {
|
||||||
if (pair.second.empty())
|
if (pair.second.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MessageIdType type = pair.first;
|
MessageIdType type = pair.first;
|
||||||
|
|
||||||
pair.second.erase(std::remove(pair.second.begin(), pair.second.end(), a_Handler), pair.second.end());
|
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), a_Handler), m_Handlers[type].end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||||
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::Dispatch(const MessageBase& a_Message) {
|
void MessageDispatcher<MessageIdType, MessageBase, MessageHandler>::Dispatch(const MessageBase& a_Message) {
|
||||||
MessageIdType type = a_Message.GetId();
|
MessageIdType type = a_Message.GetId();
|
||||||
for (auto& handler : m_Handlers[type]) {
|
for (auto& handler : m_Handlers[type])
|
||||||
a_Message.Dispatch(*handler);
|
a_Message.Dispatch(*handler);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,12 +37,8 @@ struct MessageImplBuilder {
|
|||||||
static const bool HasValidImpl = InterfaceOptions::HasValid && ImplOptions::HasFieldsImpl;
|
static const bool HasValidImpl = InterfaceOptions::HasValid && ImplOptions::HasFieldsImpl;
|
||||||
using Base6 = typename MessageImplProcessValidFields<Base5, HasValidImpl>::Type;
|
using Base6 = typename MessageImplProcessValidFields<Base5, HasValidImpl>::Type;
|
||||||
|
|
||||||
// Provide ToStringImpl() if possible
|
|
||||||
static const bool HasToStringImpl = InterfaceOptions::HasToString;
|
|
||||||
using Base7 = typename MessageImplProcessToString<Base6, ImplOptions, HasToStringImpl>::Type;
|
|
||||||
|
|
||||||
// The last BaseN must be taken as final type.
|
// The last BaseN must be taken as final type.
|
||||||
using Type = Base7;
|
using Type = Base6;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace sp {
|
|||||||
namespace option {
|
namespace option {
|
||||||
|
|
||||||
// Provide static numeric ID, to facilitate implementation of GetIdImpl()
|
// Provide static numeric ID, to facilitate implementation of GetIdImpl()
|
||||||
template <std::uintmax_t TId>
|
template <std::intmax_t TId>
|
||||||
struct StaticNumIdImpl {};
|
struct StaticNumIdImpl {};
|
||||||
|
|
||||||
// Facilitate implementation of DispatchImpl()
|
// Facilitate implementation of DispatchImpl()
|
||||||
@@ -16,11 +16,6 @@ struct DispatchImpl {};
|
|||||||
template <typename TFields>
|
template <typename TFields>
|
||||||
struct FieldsImpl {};
|
struct FieldsImpl {};
|
||||||
|
|
||||||
// Print fields of the message, facilitate implementation of
|
|
||||||
// ToStringImpl()
|
|
||||||
template <typename TActual>
|
|
||||||
struct ToStringImpl {};
|
|
||||||
|
|
||||||
} // namespace option
|
} // namespace option
|
||||||
|
|
||||||
|
|
||||||
@@ -44,10 +39,10 @@ struct MessageImplParsedOptions<> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <std::uintmax_t TId, typename... TOptions>
|
template <std::intmax_t TId, typename... TOptions>
|
||||||
struct MessageImplParsedOptions<option::StaticNumIdImpl<TId>, TOptions...> : public MessageImplParsedOptions<TOptions...> {
|
struct MessageImplParsedOptions<option::StaticNumIdImpl<TId>, TOptions...> : public MessageImplParsedOptions<TOptions...> {
|
||||||
static const bool HasStaticNumIdImpl = true;
|
static const bool HasStaticNumIdImpl = true;
|
||||||
static const std::uintmax_t MsgId = TId;
|
static const std::intmax_t MsgId = TId;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename TActual, typename... TOptions>
|
template <typename TActual, typename... TOptions>
|
||||||
|
|||||||
@@ -4,20 +4,6 @@ namespace sp {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
// ToString impl
|
|
||||||
template <typename TBase, typename ParsedImplOptions, bool TImplement>
|
|
||||||
struct MessageImplProcessToString;
|
|
||||||
|
|
||||||
template <typename TBase, typename ParsedImplOptions>
|
|
||||||
struct MessageImplProcessToString<TBase, ParsedImplOptions, true> {
|
|
||||||
using Type = MessageImplToStringBase<TBase, typename ParsedImplOptions::ActualMessage>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename TBase, typename ParsedImplOptions>
|
|
||||||
struct MessageImplProcessToString<TBase, ParsedImplOptions, false> {
|
|
||||||
using Type = TBase;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// id impl
|
// id impl
|
||||||
template <typename TBase, typename ParsedImplOptions, bool TImplement>
|
template <typename TBase, typename ParsedImplOptions, bool TImplement>
|
||||||
|
|||||||
@@ -33,11 +33,8 @@ struct MessageInterfaceBuilder {
|
|||||||
// add write id functionality if write id and write was provided
|
// add write id functionality if write id and write was provided
|
||||||
using Base7 = typename MessageInterfaceProcessWriteId<Base6, ParsedOptions::HasWriteId && ParsedOptions::HasWriteOperations>::Type;
|
using Base7 = typename MessageInterfaceProcessWriteId<Base6, ParsedOptions::HasWriteId && ParsedOptions::HasWriteOperations>::Type;
|
||||||
|
|
||||||
// add ToString() if HasToString was provided
|
// The last Base7 must be taken as final type.
|
||||||
using Base8 = typename MessageInterfaceProcessToString<Base7, ParsedOptions::HasToString>::Type;
|
using Type = Base7;
|
||||||
|
|
||||||
// The last Base8 must be taken as final type.
|
|
||||||
using Type = Base8;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|||||||
@@ -101,19 +101,5 @@ struct MessageInterfaceProcessWriteId<TBase, false> {
|
|||||||
using Type = TBase;
|
using Type = TBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build to string
|
|
||||||
template <typename TBase, bool THasToString>
|
|
||||||
struct MessageInterfaceProcessToString;
|
|
||||||
|
|
||||||
template <typename TBase>
|
|
||||||
struct MessageInterfaceProcessToString<TBase, true> {
|
|
||||||
using Type = MessageInterfaceToStringBase<TBase>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename TBase>
|
|
||||||
struct MessageInterfaceProcessToString<TBase, false> {
|
|
||||||
using Type = TBase;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
@@ -129,17 +129,5 @@ class MessageInterfaceWriteIdBase : public TBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug print functionality chunk
|
|
||||||
template <typename TBase>
|
|
||||||
class MessageInterfaceToStringBase : public TBase {
|
|
||||||
public:
|
|
||||||
std::string ToString() const {
|
|
||||||
return ToStringImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual std::string ToStringImpl() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ struct MessageInterfaceParsedOptions<> {
|
|||||||
static const bool HasWriteId = false;
|
static const bool HasWriteId = false;
|
||||||
static const bool HasHandler = false;
|
static const bool HasHandler = false;
|
||||||
static const bool HasValid = false;
|
static const bool HasValid = false;
|
||||||
static const bool HasToString = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +59,5 @@ struct MessageInterfaceParsedOptions<option::ValidCheckInterface, TOptions...> :
|
|||||||
static const bool HasValid = true;
|
static const bool HasValid = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename... TOptions>
|
|
||||||
struct MessageInterfaceParsedOptions<option::DebugPrint, TOptions...> : public MessageInterfaceParsedOptions<TOptions...> {
|
|
||||||
static const bool HasToString = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ struct LittleEndian {};
|
|||||||
// Include validity check in public interface
|
// Include validity check in public interface
|
||||||
struct ValidCheckInterface {};
|
struct ValidCheckInterface {};
|
||||||
|
|
||||||
// Add a ToString() method containing fields
|
|
||||||
struct DebugPrint {};
|
|
||||||
|
|
||||||
// Define handler class
|
// Define handler class
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Handler {
|
struct Handler {
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <sp/common/Reflection.h>
|
|
||||||
#include <sp/common/Templates.h>
|
|
||||||
#include <sp/protocol/MessagePrinter.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
namespace details {
|
|
||||||
|
|
||||||
template <typename... TOptions>
|
|
||||||
struct IdPrinter {};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct IdPrinter<> {
|
|
||||||
static std::string PrintMessageId() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename TOption, typename... TOptions>
|
|
||||||
struct IdPrinter<TOption, TOptions...> {
|
|
||||||
static std::string PrintMessageId() {
|
|
||||||
return IdPrinter<TOptions...>::PrintMessageId();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... TOptions, std::uintmax_t TId>
|
|
||||||
struct IdPrinter<option::StaticNumIdImpl<TId>, TOptions...> {
|
|
||||||
static std::string PrintMessageId() {
|
|
||||||
return "(Id: " + std::to_string(TId) + ")";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... TFields>
|
|
||||||
std::string PrintFields(const std::tuple<TFields...>& a_Fields);
|
|
||||||
|
|
||||||
template <typename TField, unsigned int IAlignment>
|
|
||||||
struct FieldPrinter {
|
|
||||||
static std::string PrintField(const sp::Field<TField, IAlignment>& a_Field) {
|
|
||||||
return Reflector<TField>::GetClassName() + "=" + PrintData(a_Field.GetValue());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <unsigned int IAlignment, typename TContainer, typename... TFields>
|
|
||||||
struct FieldPrinter<BitField<TContainer, TFields...>, IAlignment> {
|
|
||||||
static std::string PrintField(const Field<BitField<TContainer, TFields...>, IAlignment>& a_Field) {
|
|
||||||
return "BitField<" + Reflector<TContainer>::GetClassName() + ">[" + PrintFields(a_Field.GetValue().GetFields()) + "]";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... TFields>
|
|
||||||
std::string PrintFields(const std::tuple<TFields...>& a_Fields) {
|
|
||||||
std::string concat;
|
|
||||||
TupleForEach(
|
|
||||||
[&concat](const auto& a_Field) {
|
|
||||||
using TField = typename std::decay<decltype(a_Field)>::type;
|
|
||||||
constexpr std::size_t alignment = TField::AlignmentValue;
|
|
||||||
concat += FieldPrinter<typename TField::StorageType, alignment>::PrintField(a_Field) + ", ";
|
|
||||||
},
|
|
||||||
a_Fields);
|
|
||||||
return concat.substr(0, concat.size() - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TBase, typename... TOptions>
|
|
||||||
std::string PrintMessage(const MessageBase<TBase, TOptions...>& a_Message) {
|
|
||||||
return sp::GetBasicClassName(a_Message) + sp::details::IdPrinter<TOptions...>::PrintMessageId() + "[" +
|
|
||||||
sp::details::PrintFields(a_Message.GetFields()) + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
} // namespace sp
|
|
||||||
@@ -1,24 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
template <typename TBase, typename... TOptions>
|
|
||||||
class MessageBase;
|
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
template <typename TBase, typename... TOptions>
|
|
||||||
std::string PrintMessage(const MessageBase<TBase, TOptions...>& a_Message);
|
|
||||||
|
|
||||||
// ID information chunk
|
|
||||||
template <typename TBase, typename TActual>
|
|
||||||
class MessageImplToStringBase : public TBase {
|
|
||||||
protected:
|
|
||||||
virtual std::string ToStringImpl() const override {
|
|
||||||
return PrintMessage(static_cast<const TActual&>(*this));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ID information chunk
|
// ID information chunk
|
||||||
@@ -34,8 +18,6 @@ class MessageImplStaticNumIdBase : public TBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Dispatch implementation chunk
|
// Dispatch implementation chunk
|
||||||
template <typename TBase, typename TActual>
|
template <typename TBase, typename TActual>
|
||||||
class MessageImplDispatchBase : public TBase {
|
class MessageImplDispatchBase : public TBase {
|
||||||
@@ -99,7 +81,7 @@ class MessageImplFieldsReadBase : public TBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reading field in bitfield
|
// reading field in bitfield
|
||||||
template <typename TFieldType, typename TField, std::size_t IAlignment>
|
template <typename TFieldType, typename TField, int IAlignment>
|
||||||
void ReadField(Field<TField, IAlignment>& field, TFieldType data, std::size_t offset) {
|
void ReadField(Field<TField, IAlignment>& field, TFieldType data, std::size_t offset) {
|
||||||
static constexpr std::size_t TotalBitCount = sizeof(TFieldType) * 8;
|
static constexpr std::size_t TotalBitCount = sizeof(TFieldType) * 8;
|
||||||
// we suppose that the first element is at the highest bits
|
// we suppose that the first element is at the highest bits
|
||||||
@@ -136,7 +118,7 @@ class MessageImplFieldsWriteBase : public TBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// writing field in bitfield
|
// writing field in bitfield
|
||||||
template <typename TFieldType, typename TField, std::size_t IAlignment>
|
template <typename TFieldType, typename TField, int IAlignment>
|
||||||
void WriteField(const Field<TField, IAlignment>& field, TFieldType& data, std::size_t offset) const {
|
void WriteField(const Field<TField, IAlignment>& field, TFieldType& data, std::size_t offset) const {
|
||||||
static constexpr std::size_t TotalBitCount = sizeof(TFieldType) * 8;
|
static constexpr std::size_t TotalBitCount = sizeof(TFieldType) * 8;
|
||||||
// we suppose that the first element is at the highest bits
|
// we suppose that the first element is at the highest bits
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <sp/common/VarInt.h>
|
#include <sp/common/VarInt.h>
|
||||||
|
|
||||||
#include <sp/common/DataBuffer.h>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <sp/common/DataBuffer.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,7 @@ TcpSocket::IOInterface(const std::string& a_Host, std::uint16_t a_Port) : IOInte
|
|||||||
Connect(a_Host, a_Port);
|
Connect(a_Host, a_Port);
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpSocket::IOInterface(IOInterface&& a_Other) {
|
TcpSocket::IOInterface(IOInterface&& a_Other) {}
|
||||||
std::swap(m_Handle, a_Other.m_Handle);
|
|
||||||
std::swap(m_Status, a_Other.m_Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
TcpSocket::~IOInterface() {}
|
TcpSocket::~IOInterface() {}
|
||||||
|
|
||||||
@@ -94,8 +91,7 @@ DataBuffer TcpSocket::Read(std::size_t a_Amount) {
|
|||||||
std::size_t totalRecieved = 0;
|
std::size_t totalRecieved = 0;
|
||||||
|
|
||||||
while (totalRecieved < a_Amount) {
|
while (totalRecieved < a_Amount) {
|
||||||
int recvAmount =
|
int recvAmount = recv(m_Handle, reinterpret_cast<char*>(buffer.data() + totalRecieved), static_cast<int>(a_Amount - totalRecieved), 0);
|
||||||
recv(m_Handle, reinterpret_cast<char*>(buffer.data() + totalRecieved), static_cast<int>(a_Amount - totalRecieved), 0);
|
|
||||||
if (recvAmount <= 0) {
|
if (recvAmount <= 0) {
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
@@ -103,8 +99,8 @@ DataBuffer TcpSocket::Read(std::size_t a_Amount) {
|
|||||||
int err = errno;
|
int err = errno;
|
||||||
#endif
|
#endif
|
||||||
if (err == WOULDBLOCK) {
|
if (err == WOULDBLOCK) {
|
||||||
// we are in non blocking mode and nothing is available
|
m_Status = Status::Error;
|
||||||
return {};
|
throw SocketError("Error while reading");
|
||||||
}
|
}
|
||||||
|
|
||||||
Disconnect();
|
Disconnect();
|
||||||
@@ -123,7 +119,7 @@ void TcpSocket::Write(const sp::DataBuffer& a_Data) {
|
|||||||
std::size_t sent = 0;
|
std::size_t sent = 0;
|
||||||
|
|
||||||
while (sent < a_Data.GetSize()) {
|
while (sent < a_Data.GetSize()) {
|
||||||
int cur = send(m_Handle, reinterpret_cast<const char*>(a_Data.data() + sent), static_cast<int>(a_Data.GetSize() - sent), 0);
|
int cur = send(m_Handle, reinterpret_cast<const char*>(a_Data.GetSize() + sent), static_cast<int>(a_Data.GetSize() - sent), 0);
|
||||||
|
|
||||||
if (cur <= 0) {
|
if (cur <= 0) {
|
||||||
Disconnect();
|
Disconnect();
|
||||||
@@ -154,11 +150,8 @@ void TcpSocket::Disconnect() {
|
|||||||
m_Status = Status::Disconnected;
|
m_Status = Status::Disconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpSocket& TcpSocket::operator=(IOInterface&& a_Other) {
|
|
||||||
std::swap(m_Handle, a_Other.m_Handle);
|
|
||||||
std::swap(m_Status, a_Other.m_Status);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace io
|
} // namespace io
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ int main() {
|
|||||||
auto handler = std::make_shared<CustomPacketHandler>();
|
auto handler = std::make_shared<CustomPacketHandler>();
|
||||||
|
|
||||||
FileStream stream(sp::io::File{"test.txt", sp::io::FileTag::In | sp::io::FileTag::Out}, {});
|
FileStream stream(sp::io::File{"test.txt", sp::io::FileTag::In | sp::io::FileTag::Out}, {});
|
||||||
stream.GetDispatcher().RegisterHandler(PacketId::Disconnect, handler.get());
|
stream.GetDispatcher().RegisterHandler(PacketId::Disconnect, handler);
|
||||||
stream.GetDispatcher().RegisterHandler(PacketId::KeepAlive, handler.get());
|
stream.GetDispatcher().RegisterHandler(PacketId::KeepAlive, handler);
|
||||||
|
|
||||||
stream.SendMessage(KeepAlivePacket{96});
|
stream.SendMessage(KeepAlivePacket{96});
|
||||||
stream.SendMessage(KeepAlivePacket{69});
|
stream.SendMessage(KeepAlivePacket{69});
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ int main() {
|
|||||||
auto handler = std::make_shared<CustomPacketHandler>();
|
auto handler = std::make_shared<CustomPacketHandler>();
|
||||||
|
|
||||||
DataBufferStream stream;
|
DataBufferStream stream;
|
||||||
stream.GetDispatcher().RegisterHandler(PacketId::Disconnect, handler.get());
|
stream.GetDispatcher().RegisterHandler(PacketId::Disconnect, handler);
|
||||||
|
|
||||||
// this should not be dispatched
|
// this should not be dispatched
|
||||||
stream.SendMessage(KeepAlivePacket{96});
|
stream.SendMessage(KeepAlivePacket{96});
|
||||||
stream.RecieveMessages();
|
stream.RecieveMessages();
|
||||||
|
|
||||||
stream.GetDispatcher().RegisterHandler(PacketId::KeepAlive, handler.get());
|
stream.GetDispatcher().RegisterHandler(PacketId::KeepAlive, handler);
|
||||||
|
|
||||||
stream.SendMessage(KeepAlivePacket{69});
|
stream.SendMessage(KeepAlivePacket{69});
|
||||||
stream.RecieveMessages();
|
stream.RecieveMessages();
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
class KeepAliveHandler : public sp::PacketHandler {
|
class KeepAliveHandler : public sp::PacketHandler {
|
||||||
void Handle(const KeepAlivePacket& packet) {
|
void Handle(const KeepAlivePacket& packet) {
|
||||||
std::cout << "KeepAlive handled !!\n";
|
std::cout << "KeepAlive handled !\n";
|
||||||
std::cout << packet.ToString() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Handle(const DisconnectPacket& packet) {
|
void Handle(const DisconnectPacket& packet) {
|
||||||
@@ -22,14 +21,12 @@ class KeepAliveHandler : public sp::PacketHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto upgradeTower = std::make_unique<UpgradeTowerPacket>(std::make_tuple(666, 9), 789);
|
auto upgradeTower = std::make_unique<UpgradeTowerPacket>(std::make_tuple(666, 9));
|
||||||
auto keepAlive = std::make_unique<KeepAlivePacket>(6969);
|
|
||||||
|
|
||||||
sp::PacketMessage* msg = upgradeTower.get();
|
sp::PacketMessage* msg = upgradeTower.get();
|
||||||
|
|
||||||
auto handler = std::make_shared<KeepAliveHandler>();
|
auto handler = std::make_shared<KeepAliveHandler>();
|
||||||
msg->Dispatch(*handler);
|
msg->Dispatch(*handler);
|
||||||
keepAlive->Dispatch(*handler);
|
|
||||||
|
|
||||||
sp::DataBuffer buffer = msg->Write();
|
sp::DataBuffer buffer = msg->Write();
|
||||||
|
|
||||||
@@ -39,7 +36,7 @@ int main() {
|
|||||||
auto upgradeTower2 = std::make_unique<UpgradeTowerPacket>();
|
auto upgradeTower2 = std::make_unique<UpgradeTowerPacket>();
|
||||||
upgradeTower2->Read(buffer);
|
upgradeTower2->Read(buffer);
|
||||||
|
|
||||||
std::cout << "Test : " << msg->ToString() << "\n";
|
std::cout << "Test : " << (unsigned)upgradeTower2->GetTowerId() << "\n";
|
||||||
|
|
||||||
sp::PacketFactory factory;
|
sp::PacketFactory factory;
|
||||||
auto packet = factory.CreateMessage(msgId);
|
auto packet = factory.CreateMessage(msgId);
|
||||||
@@ -51,10 +48,10 @@ int main() {
|
|||||||
packet->Dispatch(*handler);
|
packet->Dispatch(*handler);
|
||||||
|
|
||||||
sp::PacketDispatcher dispatcher;
|
sp::PacketDispatcher dispatcher;
|
||||||
dispatcher.RegisterHandler(PacketId::KeepAlive, handler.get());
|
dispatcher.RegisterHandler(PacketId::KeepAlive, handler);
|
||||||
dispatcher.Dispatch(*packet);
|
dispatcher.Dispatch(*packet);
|
||||||
dispatcher.UnregisterHandler(PacketId::KeepAlive, handler.get());
|
dispatcher.UnregisterHandler(PacketId::KeepAlive, handler);
|
||||||
dispatcher.UnregisterHandler(handler.get());
|
dispatcher.UnregisterHandler(handler);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user