Commit 095a1f8c authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

Packet changes for compression structure

parent aeb469d7
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -78,6 +78,11 @@ public:
	///\pre the ByteStream is set with one of set(ByteStream) methods
	virtual bool verify();
	
	
	virtual void compress();
	
	virtual void decompress();
		
	///Get the prefix as a ByteStream
	ByteStreamPtr getBSPrefix();
	
@@ -99,6 +104,8 @@ public:
	///Get the the source data field as a ByteStream
	ByteStreamPtr getBSSourceDataField();
	
	///Copy an array of bytes into the source data field. The size must be the same.
	///It is necessary to set the number of blocks of each rblocks before.
	void copyBSSourceDataField(byte* bytestream, dword size);
	
	///Get the tail as a ByteStream
@@ -116,8 +123,6 @@ public:
	///
	PartOfPacket* getPacketTail();

	void compress();


    /// Prints to stdout the value of packet data field in a formatted mode.
    virtual void printPacketValue();
@@ -208,11 +213,15 @@ public:
    	return bigendian;
    }
	
    /// This is the ByteStream generated with generateStream().
    ByteStreamPtr packet_output;
	bool isCompressed() {
		return iscompressed;
	}
	
protected:
	
	/// This is the ByteStream generated with generateStream().
    ByteStreamPtr packet_output;
	
	/// Sets all the fields of the packet with correct value contained into the input ByteStream.
    ///	\pre The structure of the stream must be loaded.
    /// \param prefix This is the prefix of the packet
@@ -325,6 +334,8 @@ private:
	
	bool decodedPacketTail;
	
	bool iscompressed;

};

}
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@

#define ARCH_BIGENDIAN 0

enum CompressionAlgorithms  { NONE, LZH };

/// define NOFIELDSNAME

///define PRINTDEBUG(strprint) if(DEBUGMODE) cout << strprint << endl;
+3 −1
Original line number Diff line number Diff line
@@ -250,10 +250,12 @@ public:
    virtual string* printStructure();

    /// return the related RBBlock structure.
    /*
	SDFBlock* getBBlock()
    {
        return block;
    }
	 */
	
	bool get_reset_output_stream() const;
	
+32 −5
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ Packet::Packet(bool bigendian)
    tempPacketDataField = ByteStreamPtr(new ByteStream);
    tempTail = ByteStreamPtr(new ByteStream);
    first_output_stream_setted = false;
	iscompressed = false;

}

@@ -461,9 +462,6 @@ void Packet::generateStream()
    header->generateStream(bigendian);
    dataField->generateStream(bigendian);
	
	//add compression here of the datafield
	//TODO
	//dataField->compress();
}


@@ -536,6 +534,18 @@ bool Packet::setPacketValueSourceDataField(ByteStreamPtr packetDataField, int de
    b = tempPacketDataField->setStream(packetDataField, packetLength, packetLength+packetLength2-1);
    if(b)
    {
		if(isCompressed()) {
			decompress();
			//6) generate a new tempPacketDataField
			packetLength = dataField->getPacketDataFieldHeader()->size();
			dword pl1 = header->getPacketLength();
			dword pl3 = dataField->getPacketDataFieldHeader()->size();
			dword pl4 = dataField->getPacketTail()->size();
			packetLength2 = pl1 - pl3 -pl4;
			b = tempPacketDataField->setStream(packetDataField, packetLength, packetLength+packetLength2-1);
		}
		
		decodedPacketSourceDataField = true;
        bool ret = dataField->getPacketSourceDataField()->setByteStream(tempPacketDataField, decodeType);
        //word nrd = dataField->sourceDataField->getNumberOfRealDataBlock();
        return ret;
@@ -592,6 +602,11 @@ ByteStreamPtr Packet::getOutputStream()
	//TODO: check
    generateStream();
    ByteStreamPtr b = ByteStreamPtr(new ByteStream(packet_output->stream, size() + (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;
}

@@ -827,10 +842,11 @@ void Packet::copyBSSourceDataField(byte* bytestream, dword size) {
		throw new PacketException("Packet::copyBSSourceDataField(): size of the data is wrong");
	byte* sdfbsp = sdfbs->getStream();
	memcpy(sdfbsp, bytestream, size*sizeof(byte));
	decodedPacketSourceDataField = false;
}

void Packet::compress() {
		ByteStreamPtr sdfbs = getBSSourceDataField();
		
}

ByteStreamPtr Packet::getBSTail() {
@@ -876,3 +892,14 @@ PartOfPacket* Packet::getPacketTail() {
	return dataField->getPacketTail();
}

void Packet::decompress() {
	//decompression algorithm here
	//1) get the fixed and variable part of the source data field, get the tail
	//2) decompress the variable part of the source data field into a new ByteStream
	//3) rebuild a new "newstream" bytestream, taking into account the prefix, (if any) and the tail
	//4) change the size of the packet into the header (manually)
	//5) change the field the indicate if the packet is compressed = 0
	//5) call set(newstream)

}
+2 −1
Original line number Diff line number Diff line
@@ -356,6 +356,7 @@ dword SDFBlock::size()
{
	/// for fixed part
    dword dim = fixed.size();
	///variable part
    word bi = 0;
    word rbi = 0;
    for(int i=0; i < type->nblockmax; i++)