Added Tests project, Callback functions are in progress, NetworkBuffer is done, Network Message is WIP but already has a lot of code, Serializer is done (subject to change), Utility classes are being made, and TcpClientWindows is WIP.

Every single piece of code wrote today may or not change, but it will probably change because ill find a better way to do it xD
This commit is contained in:
xX-TheDoctor-Xx
2016-07-17 02:46:42 +01:00
parent 97262ee8c6
commit 16ed3619b3
37 changed files with 483 additions and 45 deletions

17
include/Callbacks.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef CALLBACKS_HPP
#define CALLBACKS_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
#include "Serializer.hpp"
void OnMessage(byte sender, byte tag, uint16 subject, byte *data);
void OnDisconnect(byte id);
void OnConnect(byte id);
#endif

View File

@ -2,10 +2,7 @@
#define DEFS_HPP
#ifdef _MSC_VER
#pragma once
#endif
#ifdef _MSC_VER
#pragma once
#define WIN32_LEAN_AND_MEAN
#define _WINSOCKAPI_
#include <windows.h>
@ -185,4 +182,14 @@ enum VoidCode
VOID_COULDNT_CONNECT,
};
enum DistributionType
{
All,
Server,
Others,
ID,
Reply,
Custom,
}
#endif // DEFS_HPP

19
include/NetworkBuffer.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef NETWORK_BUFFER_HPP
#define NETWORK_BUFFER_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
struct NetworkBuffer
{
NetworkBuffer();
~NetworkBuffer();
int body_size;
byte *body = nullptr;
};
#endif

View File

@ -5,12 +5,30 @@
#pragma once
#endif
class NetworkMessage
{
public:
NetworkMessage();
#include "Defs.hpp"
#include "NetworkBuffer.hpp"
private:
struct NetworkMessage
{
NetworkMessage();
NetworkMessage(uint16 sender, byte distribution_mode, uint16 destination_id, byte tag, uint16 subject, NetworkBuffer buffer);
~NetworkMessage();
const NetworkMessage &EncodeMessage();
const NetworkMessage &NetworkMessage::DecodeMessage(const NetworkBuffer &buffer);
const NetworkMessage &NetworkMessage::DecodeMessageHeader(const NetworkBuffer &buffer);
void *DecodeMessageData(const NetworkBuffer &buffer);
uint16 sender;
uint16 destination_id;
byte distribution_mode;
uint16 tag;
uint16 subject;
void *data;
NetworkBuffer buffer;
};
#endif
#endif

18
include/Serializer.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef SERIALIZER_HPP
#define SERIALIZER_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
#include <array>
class Serializer
{
template<typename T> std::array<byte, sizeof(T)> to_bytes(const T& object);
template<typename T> T& from_bytes(const std::array<byte, sizeof(T)> &bytes, T& object);
};
#endif

View File

@ -23,7 +23,7 @@ public:
uint16 GetPort();
void SetPort(uint16 port);
VoidCode Connect(); // this function is used if Initialize was not called
VoidCode Connect();
char *ReceiveDataArray();
const NetworkMessage &ReceiveData();

View File

@ -5,10 +5,24 @@
#pragma once
#endif
#include "Defs.hpp"
#include <streambuf>
#include <istream>
struct Utility
{
static void Delete(void *pointer);
static void DeleteArray(void *pointer);
struct BitConverter
{
static byte *FromUint8(uint8 number);
static uint8 ToUint8(byte *bytes, uint16 start_index);
static byte *FromUint16(uint16 number);
static uint16 ToUint16(byte *bytes, uint16 start_index);
};
};
#endif

View File

@ -1,11 +0,0 @@
#ifndef VOID_NET_HPP
#define VOID_NET_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include <Defs.hpp>
#include <Init.hpp>
#endif

15
include/VoidNetClient.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef VOID_NET_HPP
#define VOID_NET_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
#include "Init.hpp"
#include "TcpClient.hpp"
#include "Callbacks.hpp"
#include "NetworkBuffer.hpp"
#include "NetworkMessage.hpp"
#endif

View File

@ -0,0 +1,8 @@
#ifndef VOID_NET_SERVER_HPP
#define VOID_NET_SERVER_HPP
#ifdef _MSC_VER
#pragma once
#endif
#endif