This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
namespace sp {
|
||||
|
||||
bool IsSystemBigEndian();
|
||||
|
||||
/**
|
||||
* \brief Serialize value to (network byte order) big endian
|
||||
*/
|
||||
@@ -36,19 +34,4 @@ void FromNetwork<std::uint32_t>(std::uint32_t& value);
|
||||
template <>
|
||||
void FromNetwork<std::uint64_t>(std::uint64_t& value);
|
||||
|
||||
/**
|
||||
* \brief Swap bytes if the value is any kind of integer
|
||||
*/
|
||||
template <typename T>
|
||||
void TrySwapBytes(T& value) {}
|
||||
|
||||
template <>
|
||||
void TrySwapBytes<std::uint16_t>(std::uint16_t& value);
|
||||
|
||||
template <>
|
||||
void TrySwapBytes<std::uint32_t>(std::uint32_t& value);
|
||||
|
||||
template <>
|
||||
void TrySwapBytes<std::uint64_t>(std::uint64_t& value);
|
||||
|
||||
} // namespace sp
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/protocol/GenericHandler.h>
|
||||
#include <sp/protocol/Message.h>
|
||||
|
||||
|
||||
namespace sp {
|
||||
class PacketHandler;
|
||||
|
||||
using PacketID = std::uint8_t;
|
||||
|
||||
using PacketMessage = Message<
|
||||
option::MsgIdType<PacketID>, // add id() operation
|
||||
option::Handler<PacketHandler> // add dispatch() operation
|
||||
>;
|
||||
|
||||
#define PacketConstructor(packetName) \
|
||||
packetName##Packet() {} \
|
||||
template <typename... Args> \
|
||||
packetName##Packet(Args... args) { \
|
||||
Construct(args...); \
|
||||
}
|
||||
|
||||
#define DeclarePacket(packetName) \
|
||||
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, \
|
||||
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>>, \
|
||||
sp::option::ToStringImpl<packetName##Packet>
|
||||
|
||||
|
||||
|
||||
} // namespace sp
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/default/DefaultPacket.h>
|
||||
#include <sp/default/DefaultPacketHandler.h>
|
||||
#include <sp/protocol/MessageDispatcher.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
using PacketDispatcher = MessageDispatcher<
|
||||
PacketMessage::ParsedOptions::MsgIdType,
|
||||
PacketMessage,
|
||||
PacketMessage::ParsedOptions::HandlerType::HandlerT
|
||||
>;
|
||||
|
||||
} // namespace sp
|
||||
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/protocol/MessageFactory.h>
|
||||
|
||||
namespace sp {
|
||||
using PacketFactory = sp::MessageFactory<sp::PacketMessage, AllPackets>;
|
||||
} // namespace sp
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/protocol/GenericHandler.h>
|
||||
|
||||
// the tuple AllPackets must be defined !
|
||||
|
||||
namespace sp {
|
||||
class PacketHandler : public sp::GenericHandler<PacketMessage, AllPackets> {};
|
||||
} // namespace sp
|
||||
@@ -14,7 +14,7 @@ class ConcreteMessage : public MessageBase<TMessageID, THandler> {
|
||||
|
||||
virtual ~ConcreteMessage() {}
|
||||
|
||||
virtual constexpr TMessageID GetId() const override {
|
||||
virtual TMessageID GetId() const override {
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/message/OstreamFieldIterator.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T, std::enable_if_t<details::is_primitive<T>::value, bool> = true>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<T>& a_Field) {
|
||||
return a_Stream << std::to_string(a_Field.GetValue());
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<long unsigned int>& a_Field) {
|
||||
return a_Stream << a_Field.GetValue();
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::string>& a_Field) {
|
||||
return a_Stream << "\"" << a_Field.GetValue() << "\"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::pair<K, V>>& a_Data);
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::map<K, V>>& a_Data);
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::vector<T>>& a_Data);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::pair<K, V>>& a_Data) {
|
||||
return a_Stream << PrintableField<K>(a_Data.GetValue().first) << " => " << PrintableField<V>(a_Data.GetValue().second);
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::map<K, V>>& a_Data) {
|
||||
a_Stream << "{";
|
||||
std::copy(a_Data.GetValue().begin(), a_Data.GetValue().end(), OstreamFieldIterator<std::pair<K, V>>(std::cout, ", "));
|
||||
return a_Stream << "}";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& a_Stream, const PrintableField<std::vector<T>>& a_Data) {
|
||||
a_Stream << "{";
|
||||
std::copy(a_Data.GetValue().begin(), a_Data.GetValue().end(), OstreamFieldIterator<T>(std::cout, ", "));
|
||||
return a_Stream << "}";
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
Reference in New Issue
Block a user