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)
|
|
|
|
{
|
|
|
|
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-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-27 11:01:22 +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();
|
|
|
|
|
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
|
|
|
{
|
|
|
|
case package_type_header:
|
|
|
|
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;
|
|
|
|
|
|
|
|
case package_type_test:
|
|
|
|
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;
|
|
|
|
|
|
|
|
return set;
|
2013-11-22 08:56:00 +01:00
|
|
|
}
|