Ejemplo n.º 1
0
int SFProtobufProtocol::frameOutgoingPacket( BasePacket& packet, DataBuffer& buffer, unsigned int& nWrittenBytes )
{
	SFProtobufPacketImpl& gPacket = (SFProtobufPacketImpl&) packet;

	nWrittenBytes = (unsigned int)(6 + gPacket.getEncodedStream()->size() + 2);

	if(nWrittenBytes > buffer.getRemainingSize())
		return SFProtocol::eInsufficientBuffer;
	//
	unsigned int sStart = SignatureStart;
	unsigned int packetLen = gPacket.getEncodedStreamSize() + 8;
	unsigned int commandID = gPacket.getServiceId();
	unsigned int sEnd = SignatureEnd;

	buffer.Append((char*) &sStart, 2);
	buffer.Append((char*)&packetLen, 2);
	buffer.Append((char*)&commandID, 2);

	buffer.Append((char*)gPacket.getEncodedStream()->c_str(), gPacket.getEncodedStreamSize());

	buffer.Append((char*)&sEnd, 2);


	return SFProtocol::Success;
	
}