2013-12-11 21:45:43 +01:00
|
|
|
#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H
|
|
|
|
#define NETWORK_DEPENDENCIES_TRANSLATOR_H
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
// ----------------------------//
|
|
|
|
// Packs our dynamic protocols //
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
It packs a header in front of the actual message.
|
|
|
|
Header looks like this:
|
|
|
|
- Size of the entire package
|
|
|
|
- String containing all the types of data that is packed in the package.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Possible optimizing:
|
|
|
|
If there are several of the same type of data in a row,
|
|
|
|
we can instead of saving a character for each type we can instead save a number and the character.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
If we are packing 100 floats.
|
|
|
|
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..."
|
|
|
|
Instead of that we can do this:
|
|
|
|
"100F"
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
|
|
|
|
#define NET_PROTOCOL_EXPORT __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define NET_PROTOCOL_EXPORT __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../../Misc/Utilities.h"
|
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Network
|
|
|
|
{
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
class OysterByte;
|
|
|
|
class CustomNetProtocol;
|
|
|
|
class NET_PROTOCOL_EXPORT Translator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Translator ();
|
|
|
|
~Translator();
|
2013-12-12 12:17:39 +01:00
|
|
|
Translator(const Translator& obj);
|
|
|
|
const Translator& operator=(const Translator& obj);
|
2013-12-11 21:45:43 +01:00
|
|
|
|
2013-12-13 23:47:16 +01:00
|
|
|
void Pack(OysterByte &bytes, CustomNetProtocol& protocol);
|
2013-12-11 21:45:43 +01:00
|
|
|
|
|
|
|
//Returns false if it discovers any faulty stuff with the package.
|
2013-12-13 23:47:16 +01:00
|
|
|
bool Unpack(CustomNetProtocol& protocol, OysterByte &bytes);
|
2013-12-11 21:45:43 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct PrivateData;
|
|
|
|
PrivateData* privateData;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|