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;
void Translator::Pack( ProtocolHeader &header, OysterByte& bytes )
2013-11-21 14:49:30 +01:00
{
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)
{
message->Pack(header, bytes);
2013-11-22 14:31:07 +01:00
2013-11-22 14:23:08 +01:00
delete message;
message = NULL;
}
2013-11-21 14:49:30 +01:00
}
ProtocolSet* Translator::Unpack(ProtocolSet* set, OysterByte& bytes )
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->Unpack(bytes, *header);
delete message;
message = NULL;
2013-11-21 14:49:30 +01:00
//Switch to the correct package.
set->type = (PackageType)header->packageType;
switch(set->type)
2013-11-21 14:49:30 +01:00
{
case package_type_header:
message = new MessageHeader();
set->Protocol.pHeader = new ProtocolHeader;
message->Unpack(bytes, *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->Unpack(bytes, *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
}