About packetFactory functor

Dear all

I think the createPacket function itself should call the parse function ( so it can completely determine the kind of packet to return )

So only createPacket would remain..

A little refactoring ( I think that applies to current code too )
bool Packet::parse (const QByteArray &rawHeader,
const QByteArray &rawPayload,
const QByteArray &rawTrailer)
{
Q_SD (Data);
bool isValid = true;

isValid = isValid && readHeader (d->rawHeader);
isValid = isValid && readPayload (d->rawPayload);
isValid = isValid && readTrailer (d->rawTrailer);

d->isValid = isValid;
return isValid;
}
Could be reduced to
bool Packet::parse (const QByteArray &rawHeader,
const QByteArray &rawPayload,
const QByteArray &rawTrailer)
{
Q_SD (Data);
d->isValid = readHeader (d->rawHeader)     &&
readPayload (d->rawPayload)  &&                             readTrailer (d->rawTrailer);

return d->isValid;

}
Or am I missing something? ;-)

— cheers atul

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: About packetFactory functor
Hi Atul, You mean that the implementation of the pure virtual createPacket() should be allowed to return e.g. Protocols::Gnutella::Packets::BadPacket instead of Protocols::Generics::BadPacket? What would be different between the bad packets of (more...)