Massive update:
Changed all byte pointers to vectors NetworkMessage: DecodeMessage and EncodeMessage are now static TcpClient: Fixed OnMessage function NetworkMessage: merged both private methods into 1 method
This commit is contained in:
@ -7,13 +7,15 @@
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct NetworkBuffer
|
||||
{
|
||||
NetworkBuffer();
|
||||
~NetworkBuffer();
|
||||
|
||||
byte *header = nullptr;
|
||||
byte *body = nullptr;
|
||||
std::vector<byte> header; // contains the size of the body
|
||||
std::vector<byte> body;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -17,7 +17,7 @@ struct NetworkMessage
|
||||
|
||||
static const NetworkBuffer &EncodeMessage(const NetworkMessage &message);
|
||||
|
||||
const NetworkMessage &NetworkMessage::DecodeMessage(const NetworkBuffer &buffer);
|
||||
static const NetworkMessage &DecodeMessage(const NetworkBuffer &buffer);
|
||||
|
||||
uint16 sender = -2;
|
||||
byte distribution_mode;
|
||||
@ -29,8 +29,6 @@ struct NetworkMessage
|
||||
bool valid = false;
|
||||
|
||||
private:
|
||||
const NetworkMessage &decode_message_header(const NetworkBuffer &buffer);
|
||||
void *decode_message_data(const NetworkBuffer &buffer);
|
||||
NetworkBuffer buffer;
|
||||
};
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
struct Serializer
|
||||
{
|
||||
template<typename T> static const std::vector<byte> &to_bytes(const T &object);
|
||||
template<typename T> static const T& from_bytes(byte *bytes, T& object);
|
||||
template<typename T> static const T& from_bytes(const std::vector<byte> &bytes, T& object);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
std::function<void(uint16)> OnDisconnect;
|
||||
std::function<void(uint16)> OnConnect;
|
||||
std::function<void(uint16, uint16, uint16, void*)> OnMessage;
|
||||
std::function<void(uint16, byte, uint16, void*)> OnMessage;
|
||||
|
||||
private:
|
||||
const NetworkBuffer &receive_data_array();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
struct Utility
|
||||
{
|
||||
@ -17,29 +18,29 @@ struct Utility
|
||||
|
||||
struct BitConverter
|
||||
{
|
||||
static byte *FromUint8(uint8 number);
|
||||
static uint8 ToUint8(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromUint8(uint8 number);
|
||||
static uint8 ToUint8(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromUint16(uint16 number);
|
||||
static uint16 ToUint16(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromUint16(uint16 number);
|
||||
static uint16 ToUint16(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromUint32(uint32 number);
|
||||
static uint32 *ToUint32(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromUint32(uint32 number);
|
||||
static uint32 ToUint32(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromUint64(uint64 number);
|
||||
static uint64 ToUint64(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromUint64(uint64 number);
|
||||
static uint64 ToUint64(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromInt8(int8 number);
|
||||
static int8 ToInt8(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromInt8(int8 number);
|
||||
static int8 ToInt8(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromInt16(int16 number);
|
||||
static int16 ToInt16(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromInt16(int16 number);
|
||||
static int16 ToInt16(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromInt32(int32 number);
|
||||
static int32 ToInt32(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromInt32(int32 number);
|
||||
static int32 ToInt32(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
|
||||
static byte *FromInt64(int64 number);
|
||||
static int64 ToInt64(byte *bytes, uint16 start_index);
|
||||
static const std::vector<byte> &FromInt64(int64 number);
|
||||
static int64 ToInt64(const std::vector<byte> &bytes, uint16 start_index = 0);
|
||||
};
|
||||
|
||||
struct StringConverter
|
||||
@ -54,7 +55,7 @@ struct Utility
|
||||
static const std::string &ToString(int32 value);
|
||||
static const std::string &ToString(int64 value);
|
||||
|
||||
static const std::string &ToString(byte *bytes, uint16 start_index = 0, uint16 lenght = 0);
|
||||
static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0);
|
||||
};
|
||||
|
||||
struct ConfigReader
|
||||
|
||||
Reference in New Issue
Block a user