示例#1
0
BasePacket* SFProtobufProtocol::GetPacket(int& ErrorCode)
{
	//The Processing Loop.
	int uCommandID;
	BasePacket* pPacket = NULL;
	int iResult;
	unsigned int uExtractedBytes;

	ErrorCode = 0;

	//watch.GetElapsedTime(false);
	iResult = tryDeserializeIncomingPacket(m_Buffer , pPacket, uCommandID, uExtractedBytes);
	//iResult = pProtocol->tryDeframeIncomingPacket(pChannel->GetReceiveBuffer().GetBuffer(), pChannel->GetReceiveBuffer().GetDataSize(),uCommandID, pPacket, uExtractedBytes);
	//wcout << L"Packet deframed : " << watch.GetElapsedTime(false) << std::endl;
	if (iResult == SFProtocol::Success)
	{
		m_Buffer.Pop(uExtractedBytes);
		pPacket->SetPacketID(uCommandID);
	}
	else if (iResult == SFProtocol::eDecodingFailure)
	{
		m_Buffer.Pop(uExtractedBytes);
		ErrorCode = -1;

		return NULL;
	}
	
	return pPacket;

}
示例#2
0
BasePacket* SFAvroProtocol::GetPacket(int& errorCode)
{
	errorCode = PACKETIO_ERROR_NONE;

	SFPacketHeader header;

	if (false == m_pPacketIOBuffer->GetHeader(header, errorCode))
		return NULL;

	BasePacket* pPacket = CreateIncomingPacketFromPacketId(header.packetID);

	if (pPacket == NULL)
		return NULL;

	SFAvroPacketImpl* pAvroPacket = (SFAvroPacketImpl*)pPacket;

	memcpy(pAvroPacket->GetHeader(), &header, sizeof(SFPacketHeader));

	char dataBuffer[8096] = { 0, };

	if (false == m_pPacketIOBuffer->GetPacket(header, dataBuffer, m_packetSize, errorCode))
	{
		DisposePacket(pPacket);
		return NULL;
	}

	if (false == pPacket->Decode(dataBuffer, header.dataSize))
	{
		errorCode = PACKETIO_ERROR_DATA;
		DisposePacket(pPacket);
		return NULL;
	}

	pPacket->SetPacketID(header.packetID);

	return pPacket;
}