示例#1
0
bool	CreateNodeDataByRawData(NodeData & ndata,const char *lpbuf,S_UINT bufsize)
{
	if(lpbuf==NULL)
		return false;

	if(bufsize<sizeof(S_UINT))
		return false;
		
	S_UINT len=0,tlen=sizeof(S_UINT);

	try{

		const char *pend=lpbuf+bufsize;
		const char *pt=lpbuf;
		memmove(&len,pt,tlen);
		pt+=tlen;
		if(pt>pend)
			return false;

		if(len!=bufsize)
		{
			puts("Raw data of NodeData error");
			return false;
		}

		S_UINT count;
		memmove(&count,pt,tlen);
		pt+=tlen;


		std::string str1,str2;
		S_UINT datalen;
		char * data;

		for(S_UINT i=0;i<count;i++)
		{
			str1=pt;
			pt+=strlen(str1.c_str())+1;
			if(pt>pend)
				return true;

			str2=pt;
			pt+=strlen(str2.c_str())+1;
			if(pt>pend)
				return true;

			ndata.insert(std::make_pair(str1,str2));
		}
	}catch(...)
	{
		cout<<"Exception to CreateNodeDataByRawData."<<endl;
		return false;
	}
    
	return true;
}