I have a data structure that looks like this:
typedef struct
{
unsigned short m_short1;
unsigned short m_short2;
unsigned char m_character;
} MyDataType;
>
For such simple structure, boost::serialization is overkill and huge overhead.
Do simpler:
vector net(3,0);
net[0]=htons(data.m_short1);
net[1]=htons(data.m_short2);
net[2]=htons(data.character);
asio::async_write(socket,buffer((char*)&net.front(),6),callback);
vector net(3,0);
asio::async_read(socket,buffer((char*)&net.front(),6),callback);
callback:
data.m_short1=ntohs(net[0]);
data.m_short2=ntohs(net[1]);
data.character=ntohs(net[2]);
And Save yourself HUGE overhead that boost::serialization has
And if you private protocol where computers with same order of bytes work (big/little) that just send structure as is -- POD.