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
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;
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;
QDataStream & operator << (QDataStream &out, const hShakeAckPkt &hand_shake_pkt);
QDataStream & operator >> (QDataStream &in, hShakeAckPkt &hand_shake_pkt);
To copy to clipboard, switch view to plain text mode
And the code for reading the data from the socket is
{
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;
}
QDataStream &operator <<(QDataStream &out, const hShakeAckPkt &hand_shake_pkt)
{
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;
}
QDataStream &operator >>(QDataStream &in, hShakeAckPkt &hand_shake_pkt)
{
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;
}
To copy to clipboard, switch view to plain text mode
Now i want to know that, is there any other fastest way to read all the data in structure memory. (With or without QDataStream)
?????
Bookmarks