PStartSendFile.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:2k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // PStartSendFile.cpp: implementation of the PStartSendFile class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "PStartSendFile.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- PStartSendFile::PStartSendFile()
- {
- this->Tag = PStartSendFileTAG;
- this->user_name = "";
- this->filename = "";
- this->file_id = 0;
- this->file_size = 0;
- this->recv_id = NULL;
- this->id_size = 0;
- }
- PStartSendFile::~PStartSendFile()
- {
- }
- bool PStartSendFile::assembleData( const char * user_name , const char * filename , int file_id , int file_size , int * recvid , int id_size )
- {
- int size = sizeof( int ) + strlen( user_name ) + sizeof( char ) + strlen( filename ) + sizeof( char ) + sizeof( int ) + sizeof( int ) + sizeof( int ) + sizeof( int ) * id_size;
- this->buffer.Resize( size );
- char * now = this->buffer.GetBuffer( );
- *( int * )now = this->Tag; now += sizeof( int );
- strcpy( now , user_name ); now += strlen( user_name ) + sizeof( char );
- strcpy( now , filename ); now += strlen( filename ) + sizeof( char );
- *( int * )now = file_id ; now += sizeof( int );
- *( int * )now = file_size; now += sizeof( int );
- *( int * )now = id_size; now += sizeof( int );
- if( id_size > 0 )
- memcpy( now , recvid , sizeof( int ) * id_size );
- return true;
- }
- bool PStartSendFile::parseData( char * buffer , int size )
- {
- if( *( int * )buffer != this->Tag )
- return false;
- buffer += sizeof( int );
- this->user_name = buffer ; buffer += this->user_name.GetLength( ) + sizeof( char );
- this->filename = buffer ; buffer += this->filename.GetLength( ) + sizeof( char );
- this->file_id = *( int * )buffer; buffer += sizeof( int );
- this->file_size = *( int * )buffer; buffer += sizeof( int );
- this->id_size = *( int * )buffer ; buffer += sizeof( int );
- if( this->id_size > 0 )
- this->recv_id = ( int * )buffer;
- else
- this->recv_id = NULL;
- return true;
- }