1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/config/defines.hpp>
11 #include <anna/comm/LiteTransport.hpp>
12 #include <anna/comm/Message.hpp>
13 #include <anna/comm/functions.hpp>
17 comm::TransportFactoryImpl <comm::LiteTransport> comm::LiteTransport::st_transportFactory;
19 comm::LiteTransport::LiteTransport() :
21 setInputMessage(new Message());
24 comm::LiteTransport::~LiteTransport() {
25 delete getInputMessage();
28 int comm::LiteTransport::calculeSize(const DataBlock& dataBlock)
29 throw(RuntimeException) {
30 const char* buffer = dataBlock.getData();
31 return (dataBlock.getSize() >= headerSize) ? functions::decodeShort(buffer) + headerSize : -1;
34 const comm::Message* comm::LiteTransport::decode(const DataBlock& message)
35 throw(RuntimeException) {
36 const int totalSize = message.getSize();
38 if(totalSize < headerSize)
39 throw RuntimeException("Invalid message to decode", ANNA_FILE_LOCATION);
41 const char* buffer = message.getData();
42 const int bodySize = totalSize - headerSize;
45 throw RuntimeException("Invalid message size to decode", ANNA_FILE_LOCATION);
47 return getInputMessage()->setBody(buffer + headerSize, bodySize);
50 const DataBlock& comm::LiteTransport::code(comm::Message& message)
51 throw(RuntimeException) {
52 char aux [sizeof(int)];
53 const DataBlock& data = message.code();
55 a_forCode.append(functions::codeShort(aux, data.getSize()), headerSize);
56 return a_forCode += data;