2013-11-21 14:49:30 +01:00
|
|
|
#include "Translator.h"
|
|
|
|
|
|
|
|
using namespace Oyster::Network;
|
|
|
|
using namespace ::Protocols;
|
|
|
|
using namespace ::Messages;
|
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
void Translator::Pack( ProtocolHeader &header, OysterByte& bytes )
|
2013-11-21 14:49:30 +01:00
|
|
|
{
|
|
|
|
MessageHeader *message = NULL;
|
|
|
|
|
|
|
|
switch(header.packageType)
|
|
|
|
{
|
2013-11-28 08:51:21 +01:00
|
|
|
case PackageType_header:
|
2013-11-21 14:49:30 +01:00
|
|
|
message = new MessageHeader();
|
|
|
|
break;
|
|
|
|
|
2013-11-28 08:51:21 +01:00
|
|
|
case PackageType_test:
|
2013-11-21 14:49:30 +01:00
|
|
|
message = new MessageTest();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-22 14:23:08 +01:00
|
|
|
if(message != NULL)
|
|
|
|
{
|
2013-11-27 11:01:22 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-11-28 16:15:28 +01:00
|
|
|
void 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();
|
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
message->Unpack(bytes, *header);
|
2013-11-22 11:40:55 +01:00
|
|
|
delete message;
|
|
|
|
message = NULL;
|
2013-11-21 14:49:30 +01:00
|
|
|
|
2013-11-22 11:40:55 +01:00
|
|
|
//Switch to the correct package.
|
2013-11-25 19:00:33 +01:00
|
|
|
set->type = (PackageType)header->packageType;
|
|
|
|
switch(set->type)
|
2013-11-21 14:49:30 +01:00
|
|
|
{
|
2013-11-28 08:51:21 +01:00
|
|
|
case PackageType_header:
|
2013-11-21 14:49:30 +01:00
|
|
|
message = new MessageHeader();
|
2013-11-22 11:40:55 +01:00
|
|
|
set->Protocol.pHeader = new ProtocolHeader;
|
2013-11-27 11:01:22 +01:00
|
|
|
message->Unpack(bytes, *set->Protocol.pHeader);
|
2013-11-21 14:49:30 +01:00
|
|
|
break;
|
|
|
|
|
2013-11-28 08:51:21 +01:00
|
|
|
case PackageType_test:
|
2013-11-21 14:49:30 +01:00
|
|
|
message = new MessageTest();
|
2013-11-22 11:40:55 +01:00
|
|
|
set->Protocol.pTest = new ProtocolTest;
|
2013-11-27 11:01:22 +01:00
|
|
|
message->Unpack(bytes, *set->Protocol.pTest);
|
2013-11-21 14:49:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:40:55 +01:00
|
|
|
if(message)
|
2013-11-25 19:00:33 +01:00
|
|
|
{
|
2013-11-22 11:40:55 +01:00
|
|
|
delete message;
|
2013-11-25 19:00:33 +01:00
|
|
|
}
|
2013-11-22 11:40:55 +01:00
|
|
|
delete header;
|
|
|
|
|
2013-11-28 16:15:28 +01:00
|
|
|
//return set;
|
2013-11-22 08:56:00 +01:00
|
|
|
}
|