Danbias/Code/Network/NetworkDependencies/Translator.cpp

64 lines
1.2 KiB
C++
Raw Normal View History

2013-11-21 14:49:30 +01:00
#include "Translator.h"
using namespace Oyster::Network;
using namespace ::Protocols;
using namespace ::Messages;
unsigned char* Translator::Translate( ProtocolHeader &header )
{
MessageHeader *message = NULL;
switch(header.packageType)
{
case package_type_header:
message = new MessageHeader();
break;
case package_type_test:
message = new MessageTest();
break;
}
2013-11-22 14:23:08 +01:00
if(message != NULL)
{
2013-11-22 14:31:07 +01:00
message->Translate(header, this->msg);
2013-11-22 14:23:08 +01:00
delete message;
message = NULL;
}
2013-11-21 14:49:30 +01:00
2013-11-22 14:23:08 +01:00
return msg;
2013-11-21 14:49:30 +01:00
}
ProtocolSet* Translator::Translate(ProtocolSet* set, unsigned char msg[] )
2013-11-21 14:49:30 +01:00
{
2013-11-22 08:56:00 +01:00
ProtocolHeader *header = new ProtocolHeader();
2013-11-21 14:49:30 +01:00
MessageHeader *message = new MessageHeader();
message->Translate(msg, *header);
delete message;
message = NULL;
2013-11-21 14:49:30 +01:00
//Switch to the correct package.
set->t = (PackageType)header->packageType;
switch(set->t)
2013-11-21 14:49:30 +01:00
{
case package_type_header:
message = new MessageHeader();
set->Protocol.pHeader = new ProtocolHeader;
message->Translate(msg, *set->Protocol.pHeader);
2013-11-21 14:49:30 +01:00
break;
case package_type_test:
message = new MessageTest();
set->Protocol.pTest = new ProtocolTest;
message->Translate(msg, *set->Protocol.pTest);
2013-11-21 14:49:30 +01:00
break;
}
if(message)
delete message;
delete header;
return set;
2013-11-22 08:56:00 +01:00
}