Commit a4bf78c6 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

Added Packet:: getBSPrefix(), getBSHeader(), getBSDataFieldHeader(),...

Added Packet:: getBSPrefix(), getBSHeader(), getBSDataFieldHeader(), getBSSourceDataFieldsFixedPart(), getBSSourceDataFieldsVariablePart(), getBSTail() and some internal changes in bool setPacketValue(ByteStreamPtr stream, int decodeType)
parent 66d70e76
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -53,15 +53,13 @@ public:
    /// This method verifies if the ByteStream on argument contains the correct value
    /// in the identifiers. If this is true, the method return true and the stream
    /// contains a packet of this type. This method overloads another method.
    /// \post A side effects of this method is that the value of fields of packet are set with
    /// correct value.
	/// \post the bytestream is decoded
    virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);

    /// This method verifies if the ByteStream on argument contains the correct value
    /// in the identifiers. If this is true, the method returns true and the stream
    /// contains a packet of this type. This method overloads another method.
    /// \post A side effect of this method is that the values of fields of packet are set with
    /// correct value
    /// \post the bytestream is decoded
    virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet);

    /// Sets all the fields of the packet with correct value contained into the input ByteStream.
@@ -70,7 +68,7 @@ public:
    /// \param packetHeader This is the header of the packet
    /// \param packetDataField This is the data field of the packet
	/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
    /// \post If return is true all the fields are set with the correct value.
    /// \post the bytestream is decoded
    virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, int decodeType);

    /// Sets all the fields of the packet with correct value contained into the input ByteStream.
@@ -78,7 +76,7 @@ public:
    /// \param prefix This is the prefix of the packet
    /// \param packet This is the packet
	/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
    /// \post If return is true all the fields are set with the correct value.
    /// \post the bytestream is decoded
    virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet, int decodeType);

    /// Verifies if within the ByteStream passed with arguments it's present a correct packet.
@@ -106,6 +104,24 @@ public:
    /// \return True if the ByteStream contains a packet.
    virtual bool verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);
	
	///Get the prefix as a ByteStream
	ByteStreamPtr getBSPrefix();
	
	///Get the header as a ByteStream
	ByteStreamPtr getBSHeader();
	
	///Get the data field header as a ByteStream
	ByteStreamPtr getBSDataFieldHeader();
	
	///Get the fixed part of the source data field as a ByteStream
	ByteStreamPtr getBSSourceDataFieldsFixedPart();
	
	///Get the the variable part of the source data field as a ByteStream
	ByteStreamPtr getBSSourceDataFieldsVariablePart();
	
	///Get the tail as a ByteStream
	ByteStreamPtr getBSTail();

    /// Prints to stdout the value of packet data field in a formatted mode.
    virtual void printPacketValue();

+41 −15
Original line number Diff line number Diff line
@@ -603,11 +603,8 @@ bool Packet::setPacketValuePrefix(ByteStreamPtr prefix)
bool Packet::setPacketValueDataFieldHeader(ByteStreamPtr packetDataField)
{
    bool b;
    dword packetLength;
    /// 4) data field header
    packetLength = dataField->dataFieldHeader->getDimension();
    /// Reading and setting the data field header
    b = tempDataFieldHeader->setStream(packetDataField, 0, packetLength-1);
    b = tempDataFieldHeader->setStream(packetDataField, 0, dimPacketDataFieldHeader-1);
    /// It releases the memory from b only if it goes wrong
    if(b)
    {
@@ -835,20 +832,49 @@ bool Packet::setPacketValue(ByteStreamPtr stream, int decodeType) {
		return true;
	}
	
	dword dimPre = 0;
	if(thereisprefix)
		dimPre = dimPrefix;

	ByteStreamPtr prefix = ByteStreamPtr(new ByteStream(stream->stream, dimPre, bigendian));
		prefix = ByteStreamPtr(new ByteStream(stream->stream, dimPrefix, bigendian));
	else
		prefix = 0;
	
	dword dim = 0;
	dword dimHeader = header->getDimension();
	dim += dimHeader;
	tempHeader->setStream(stream->stream+dimPre, dimHeader, bigendian);
	tempHeader->setStream(stream->stream + dimPrefix, dimPacketHeader, bigendian);
	header->setByteStream(tempHeader);
	dim += header->getPacketLength() + 1;
	ByteStreamPtr packet = ByteStreamPtr(new ByteStream(stream->stream+dimPre, dim, bigendian));
	dword dim = dimPacketHeader + header->getPacketLength() + 1;
	packet = ByteStreamPtr(new ByteStream(stream->stream + dimPrefix, dim, bigendian));

	//return true;
	
	return setPacketValue(prefix, packet, decodeType);

}

ByteStreamPtr Packet::getBSPrefix() {
	return prefix;
}

ByteStreamPtr Packet::getBSHeader() {
	ByteStreamPtr header = ByteStreamPtr(new ByteStream(packet->stream + dimPrefix, dimPacketHeader, bigendian));
	return header;
}

ByteStreamPtr Packet::getBSDataFieldHeader() {
	ByteStreamPtr dfh = ByteStreamPtr(new ByteStream(packet->stream + dimPrefix + dimPacketHeader, dimPacketDataFieldHeader, bigendian));
	return dfh;
}

ByteStreamPtr Packet::getBSSourceDataFieldsFixedPart() {
	ByteStreamPtr sdff = ByteStreamPtr(new ByteStream(packet->stream + dimPrefix + dimPacketHeader + dimPacketDataFieldHeader, dimPacketSourceDataFieldFixed, bigendian));
	return sdff;
}

ByteStreamPtr Packet::getBSSourceDataFieldsVariablePart() {
	dword dimvariablepart = packet->getDimension() - dimPrefix - dimPacketStartingFixedPart - dimPacketTail;
	ByteStreamPtr sdff = ByteStreamPtr(new ByteStream(packet->stream + dimPrefix + dimPacketStartingFixedPart, dimvariablepart, bigendian));
	return sdff;
}

ByteStreamPtr Packet::getBSTail() {
	dword dimvariablepart = packet->getDimension() - dimPrefix - dimPacketStartingFixedPart - dimPacketTail;
	ByteStreamPtr tail = ByteStreamPtr(new ByteStream(packet->stream + packet->getDimension() - dimPacketTail, dimPacketTail, bigendian));
	return tail;
}