PBroadcastREQ.cpp
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:1k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. // PBroadcastREQ.cpp: implementation of the PBroadcastREQ class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "PBroadcastREQ.h"
  5. //////////////////////////////////////////////////////////////////////
  6. // Construction/Destruction
  7. //////////////////////////////////////////////////////////////////////
  8. PBroadcastREQ::PBroadcastREQ( )
  9. {
  10. this->Tag = PBroadcastREQTAG;
  11. this->broadcast_user_id = 0;
  12. this->recv_user_id = 0;
  13. this->header = NULL;
  14. this->header_size = 0;
  15. }
  16. PBroadcastREQ::~PBroadcastREQ( )
  17. {
  18. }
  19. bool PBroadcastREQ::assembleData( int broadcast_user_id , int recv_user_id , char * header , int size )
  20. {
  21. this->buffer.Resize( 5 * INT_SIZE + size );
  22. char * now = this->buffer.GetBuffer( );
  23. *( int * )now = this->buffer.GetSize( ); now += INT_SIZE;
  24. *( int * )now = this->Tag; now += INT_SIZE;
  25. *( int * )now = broadcast_user_id; now += INT_SIZE;
  26. *( int * )now = recv_user_id; now += INT_SIZE;
  27. *( int * )now = size ; now += INT_SIZE;
  28. if( size > 0 )
  29. memcpy( now , header , size );
  30. return true;
  31. }
  32. bool PBroadcastREQ::parseData( CBuffer & buffer )
  33. {
  34. if( ! buffer.GetSize( ) ) return false;
  35. char * now = buffer.GetBuffer( ) + 2 * INT_SIZE;
  36. this->broadcast_user_id = *( int * )now; now += INT_SIZE;
  37. this->recv_user_id = *( int * )now; now += INT_SIZE;
  38. this->header_size = *( int * )now; now += INT_SIZE;
  39. this->header = this->header_size > 0 ? now : NULL;
  40. return true;
  41. }