当前位置: 首页>>代码示例>>C++>>正文


C++ Packet::Erase方法代码示例

本文整理汇总了C++中Packet::Erase方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::Erase方法的具体用法?C++ Packet::Erase怎么用?C++ Packet::Erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Packet的用法示例。


在下文中一共展示了Packet::Erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _HelperTestClass

/**
 * @brief	Helps to test NetModeUdp objects.
 *
 * Client ID used with DealWithData is 10, and operation ID is 5.
 *
 * @param [in,out]	obj				The object. 
 * @param [in,out]	packet			The packet. 
 * @param str						The string stored in @a packet.
 * @param dealWithDataClientID		Client ID to use with DealWithData().
 * @param expectedClientID			Expected result of destination.GetClientFrom().
 * @param operationID				Operation ID to use with DealWithData().
 *
 * @return	false if the test was failed and a problem was found while testing, true if not.
 */
bool NetModeUdp::_HelperTestClass(NetModeUdp & obj, Packet & packet, const char * str, size_t dealWithDataClientID, size_t expectedClientID, size_t operationID)
{
	Packet destination;
	WSABUF buffer;

	bool problem = false;

	// Counter: 500
	packet.SetCursor(0);
	packet.AddSizeT(500);
	packet.PtrIntoWSABUF(buffer);
	obj.DealWithData(buffer,packet.GetUsedSize(),NULL,dealWithDataClientID,1);
	
	if(obj.GetPacketFromStore(&destination,expectedClientID,operationID) != 1 ||
	   destination.GetClientFrom() != expectedClientID ||
	   destination.GetInstance() != 1||
	   destination.GetAge() != 500 ||
	   (destination.GetOperation() != operationID && destination.GetOperation() != 0))
	{
		cout << "DealWithData is bad (packet 1)\n";
		problem = true;
	}
	else
	{
		destination.Erase(0,destination.GetCursor());
		if(destination != str)
		{
			cout << "DealWithData is bad due to contents (packet 1)\n";
			problem = true;
		}
		else
		{
			cout << "DealWithData is good (packet 1)\n";
		}
	}

	// Counter: 499
	packet.SetCursor(0);
	packet.AddSizeT(499);
	packet.PtrIntoWSABUF(buffer);
	obj.DealWithData(buffer,packet.GetUsedSize(),NULL,dealWithDataClientID,1);
	
	if(obj.GetPacketFromStore(&destination,expectedClientID,operationID) != 0)
	{
		cout << "DealWithData is bad (packet 2)\n";
		problem = true;
	}
	else
	{
		cout << "DealWithData is good (packet 2)\n";
	}

	// Counter: 501
	packet.SetCursor(0);
	packet.AddSizeT(501);
	packet.PtrIntoWSABUF(buffer);
	obj.DealWithData(buffer,packet.GetUsedSize(),NULL,dealWithDataClientID,3);
	
	if(obj.GetPacketFromStore(&destination,expectedClientID,operationID) != 1 ||
	   destination.GetClientFrom() != expectedClientID ||
	   destination.GetInstance() != 3 ||
	   destination.GetAge() != 501 ||
	   (destination.GetOperation() != operationID && destination.GetOperation() != 0))
	{
		cout << "DealWithData is bad (packet 3)\n";
		problem = true;
	}
	else
	{
		destination.Erase(0,destination.GetCursor());
		if(destination != str)
		{
			cout << "DealWithData is bad due to contents (packet 3)\n";
			problem = true;
		}
		else
		{
			cout << "DealWithData is good (packet 3)\n";
		}
	}
	
	// Counter: very large (1000 from maximum) 
	packet.SetCursor(0);
	packet.AddSizeT(-1000);
	packet.PtrIntoWSABUF(buffer);
	obj.DealWithData(buffer,packet.GetUsedSize(),NULL,dealWithDataClientID,3);
//.........这里部分代码省略.........
开发者ID:watfordxp,项目名称:MikeNet,代码行数:101,代码来源:NetModeUdp.cpp


注:本文中的Packet::Erase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。