Loading include/Packet.h +3 −3 Original line number Diff line number Diff line Loading @@ -74,12 +74,12 @@ public: /// \param checkPacketLenght if true check the packet lenght and set the packet stream, if false do not check the packet lenght virtual bool decode(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, bool checkPacketLenght = false); ///return true is the packet contained into the stream is recognized using identifiers. ///\return true is the packet contained into the stream is recognized using identifiers. ///\pre the ByteStream is set with one of set(ByteStream) methods virtual bool verify(); virtual void compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel); ///\return compress the data section (the variable part or the "data" part) virtual ByteStreamPtr compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel); virtual word getCompressionAlgorithm(); Loading include/PacketHeader.h +2 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,8 @@ public: /// Returns the total lenght of packet data field (data field header plus source data field) dword getPacketLength(); //set the length of the packet in the 'packet lenght' field (the data field dimension - 1) //set the length of the packet in the 'packet lenght' field (the data field dimension) //It is encoded as "data field dimension - 1 void setPacketLength(dword dim); Field * getFieldWithPacketDimension(); Loading src/ByteStream.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -136,6 +136,8 @@ PacketLib::ByteStream::~ByteStream() ByteStreamPtr PacketLib::ByteStream::compress(enum CompressionAlgorithms, byte compressionLevel) { ByteStreamPtr b = ByteStreamPtr( new ByteStream(stream, size()/2, bigendian) ); return b; } Loading src/Packet.cpp +26 −12 Original line number Diff line number Diff line Loading @@ -140,12 +140,10 @@ bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) thr dimPacketTail = dataField->getPacketTail()->size(); line = file.getLastLineRead(); if(strcmp(line, "[Compression]") == 0) { compressionAlgorithmsSection = atoi(file.getLine()); compressionAlgorithmsIndex = atoi(file.getLine()); compressionLevelSection = atoi(file.getLine()); compressionAlgorithmsSection = atoi(file.getLine()); compressionLevelIndex = atoi(file.getLine()); //TODO compressionLevelSection = atoi(file.getLine()); } } } Loading Loading @@ -613,14 +611,10 @@ ByteStreamPtr Packet::encodeAndSetData(ByteStreamPtr sourceDataVariable) if(sourceDataVariable->size() != size() - dimPacketStartingFixedPart - dimPacketTail) throw new PacketException("the size of the sourceDataVariable is wrong"); memcpy( packet_output->stream + dimPacketStartingFixedPart, sourceDataVariable->stream, sourceDataVariable->size()); memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimPacketStartingFixedPart, sourceDataVariable->stream, sourceDataVariable->size()); b = ByteStreamPtr(new ByteStream(packet_output->stream, dimpacket + (thereisprefix?dimPrefix:0), bigendian)); } //COMPRESSION HERE //add compression algorithm here of the variable part of the source data field and do not use size() of packet //TODO return b; } Loading Loading @@ -903,7 +897,7 @@ word Packet::getCompressionLevel() { } } void Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel) { ByteStreamPtr Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel) { //set the algorithm Loading Loading @@ -950,13 +944,33 @@ void Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte comp ByteStreamPtr original = getBSSourceDataFieldsVariablePart(); ByteStreamPtr compressed = original->compress(compressionAlgorithm, compressionLevel); cout << "original: " << original->size() << " compressed: " << compressed->size() << endl; ByteStreamPtr tail = getBSTail(); ByteStreamPtr b; if(compressed != 0) { //the variable part of the sourcedatafield //cout << "packet size " << size() << " " << dimpacket << " " << dimPacketStartingFixedPart << " " << sourceDataVariable->size() << endl; memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimPacketStartingFixedPart, compressed->stream, compressed->size()); dword dimpacket = dimPacketStartingFixedPart + compressed->size() + dimPacketTail; if(dimPacketTail != 0) memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimpacket - dimPacketTail, tail->stream, tail->size()); //set packet length dword dimDataField = dimPacketDataFieldHeader + dimPacketSourceDataFieldFixed + dimPacketTail + compressed->size(); header->setPacketLength(dimDataField); header->generateStream(bigendian); b = ByteStreamPtr(new ByteStream(packet_output->stream, dimpacket + (thereisprefix?dimPrefix:0), bigendian)); } return compressed; } ByteStreamPtr Packet::getBSTail() { //dword dimvariablepart = packet->size() - dimPrefix - dimPacketStartingFixedPart - dimPacketTail; ByteStreamPtr tail = 0; if(dimPacketTail > 0) ByteStreamPtr tail = ByteStreamPtr(new ByteStream(packet->stream + packet->size() - dimPacketTail, dimPacketTail, bigendian)); return tail; } Loading Loading
include/Packet.h +3 −3 Original line number Diff line number Diff line Loading @@ -74,12 +74,12 @@ public: /// \param checkPacketLenght if true check the packet lenght and set the packet stream, if false do not check the packet lenght virtual bool decode(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, bool checkPacketLenght = false); ///return true is the packet contained into the stream is recognized using identifiers. ///\return true is the packet contained into the stream is recognized using identifiers. ///\pre the ByteStream is set with one of set(ByteStream) methods virtual bool verify(); virtual void compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel); ///\return compress the data section (the variable part or the "data" part) virtual ByteStreamPtr compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel); virtual word getCompressionAlgorithm(); Loading
include/PacketHeader.h +2 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,8 @@ public: /// Returns the total lenght of packet data field (data field header plus source data field) dword getPacketLength(); //set the length of the packet in the 'packet lenght' field (the data field dimension - 1) //set the length of the packet in the 'packet lenght' field (the data field dimension) //It is encoded as "data field dimension - 1 void setPacketLength(dword dim); Field * getFieldWithPacketDimension(); Loading
src/ByteStream.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -136,6 +136,8 @@ PacketLib::ByteStream::~ByteStream() ByteStreamPtr PacketLib::ByteStream::compress(enum CompressionAlgorithms, byte compressionLevel) { ByteStreamPtr b = ByteStreamPtr( new ByteStream(stream, size()/2, bigendian) ); return b; } Loading
src/Packet.cpp +26 −12 Original line number Diff line number Diff line Loading @@ -140,12 +140,10 @@ bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) thr dimPacketTail = dataField->getPacketTail()->size(); line = file.getLastLineRead(); if(strcmp(line, "[Compression]") == 0) { compressionAlgorithmsSection = atoi(file.getLine()); compressionAlgorithmsIndex = atoi(file.getLine()); compressionLevelSection = atoi(file.getLine()); compressionAlgorithmsSection = atoi(file.getLine()); compressionLevelIndex = atoi(file.getLine()); //TODO compressionLevelSection = atoi(file.getLine()); } } } Loading Loading @@ -613,14 +611,10 @@ ByteStreamPtr Packet::encodeAndSetData(ByteStreamPtr sourceDataVariable) if(sourceDataVariable->size() != size() - dimPacketStartingFixedPart - dimPacketTail) throw new PacketException("the size of the sourceDataVariable is wrong"); memcpy( packet_output->stream + dimPacketStartingFixedPart, sourceDataVariable->stream, sourceDataVariable->size()); memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimPacketStartingFixedPart, sourceDataVariable->stream, sourceDataVariable->size()); b = ByteStreamPtr(new ByteStream(packet_output->stream, dimpacket + (thereisprefix?dimPrefix:0), bigendian)); } //COMPRESSION HERE //add compression algorithm here of the variable part of the source data field and do not use size() of packet //TODO return b; } Loading Loading @@ -903,7 +897,7 @@ word Packet::getCompressionLevel() { } } void Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel) { ByteStreamPtr Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte compressionLevel) { //set the algorithm Loading Loading @@ -950,13 +944,33 @@ void Packet::compress(enum CompressionAlgorithms compressionAlgorithm, byte comp ByteStreamPtr original = getBSSourceDataFieldsVariablePart(); ByteStreamPtr compressed = original->compress(compressionAlgorithm, compressionLevel); cout << "original: " << original->size() << " compressed: " << compressed->size() << endl; ByteStreamPtr tail = getBSTail(); ByteStreamPtr b; if(compressed != 0) { //the variable part of the sourcedatafield //cout << "packet size " << size() << " " << dimpacket << " " << dimPacketStartingFixedPart << " " << sourceDataVariable->size() << endl; memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimPacketStartingFixedPart, compressed->stream, compressed->size()); dword dimpacket = dimPacketStartingFixedPart + compressed->size() + dimPacketTail; if(dimPacketTail != 0) memcpy( packet_output->stream + (thereisprefix?dimPrefix:0) + dimpacket - dimPacketTail, tail->stream, tail->size()); //set packet length dword dimDataField = dimPacketDataFieldHeader + dimPacketSourceDataFieldFixed + dimPacketTail + compressed->size(); header->setPacketLength(dimDataField); header->generateStream(bigendian); b = ByteStreamPtr(new ByteStream(packet_output->stream, dimpacket + (thereisprefix?dimPrefix:0), bigendian)); } return compressed; } ByteStreamPtr Packet::getBSTail() { //dword dimvariablepart = packet->size() - dimPrefix - dimPacketStartingFixedPart - dimPacketTail; ByteStreamPtr tail = 0; if(dimPacketTail > 0) ByteStreamPtr tail = ByteStreamPtr(new ByteStream(packet->stream + packet->size() - dimPacketTail, dimPacketTail, bigendian)); return tail; } Loading