Fastest way to read structure from QTcpSocket
Hello All,
I have got one problem which is resolved in http://www.qtcentre.org/threads/57634-SOLVED-Unable-to-read-data-by-QDataStream .
But i want to know that, is there any other fastest way to read all the data from socket in a structure.
My current structure is
Code:
typedef struct hShakeAckPkt
{
unsigned short Id; // 0XFEFE
unsigned short BlockSize; // 45
int Reserved1[2]; // fill with 0
unsigned short FeedType; // fill with 0
unsigned short Reserved2[3]; // fill with 0
unsigned short Major; // 1
unsigned short Minor; // 4
unsigned char ProgramId[21]; // "CTCL" rest with '\0'
}hShakeAckPkt;
And the code for reading the data from the socket is
Code:
{
out << hand_shake_pkt.Id;
out << hand_shake_pkt.BlockSize;
for(int i = 0; i < 2; ++i)
out << hand_shake_pkt.Reserved1[i];
out << hand_shake_pkt.FeedType;
for(int i = 0; i < 3; ++i)
out << hand_shake_pkt.Reserved2[i];
out << hand_shake_pkt.Major;
out << hand_shake_pkt.Minor;
for(int i = 0; i < 21; ++i)
out << hand_shake_pkt.ProgramId[i];
return out;
}
{
in >> hand_shake_pkt.Id;
in >> hand_shake_pkt.BlockSize;
for(int i = 0; i < 2; ++i)
in >> hand_shake_pkt.Reserved1[i];
in >> hand_shake_pkt.FeedType;
for(int i = 0; i < 3; ++i)
in >> hand_shake_pkt.Reserved2[i];
in >> hand_shake_pkt.Major;
in >> hand_shake_pkt.Minor;
for(int i = 0; i < 21; ++i)
in >> hand_shake_pkt.ProgramId[i];
return in;
}
Now i want to know that, is there any other fastest way to read all the data in structure memory. (With or without QDataStream)
?????
Re: Fastest way to read structure from QTcpSocket
I'll certainly happy to see that too :) But I'm worried that with QDataStream there is no other way to do serialization/deserialization without going after each item of the struct. Now about without the QDataStream, maybe this article will do the trick (depending in which direction you want to do it: http://smartqt.blogspot.com/2014/05/...-and-from.html).