Skip to content

Instantly share code, notes, and snippets.

@aoxu
Created January 18, 2013 09:14
Show Gist options
  • Save aoxu/4563347 to your computer and use it in GitHub Desktop.
Save aoxu/4563347 to your computer and use it in GitHub Desktop.
// return < 0 invalid
// return ==0 not complete
// return > 0 the complete size
inline int checkComplete(void* buf, size_t len)
{
if(len <= 16/*head len*/)
{
return 0; // not complete
}
GameProtocol* gameProtocol = (GameProtocol*)buf;
if(ntohl(gameProtocol->_magic) != 0x7765646F)
return -1; // invalid magic
if(ntohl(gameProtocol->_ver) != 0x1)
return -2; // version not support
if(ntohl(gameProtocol->_len) > len)
return 0; // not complete
// TODO: check checksum here
return ntohl(gameProtocol->_len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment