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