Beispiel #1
0
void SocketMessage::compilePacketHeader(char *buffer, size_t *buffer_size, const void *payload, size_t payload_size, bool is_compressed) const
{
	if (*buffer_size<24) throw BufferTooSmallException();
	bzero(buffer,24);
	int flags=0;
	if (UseCompression) flags|=2;		// Bit 1: Client supports ZLib
	if (SupportMsgChannel) flags|=4;	// Bit 2: Client supports MsgChannel
	if (is_compressed) flags|=1;
	PokeN8(buffer,'V');							// Byte 0:  "V"							(1 Byte)
	PokeN8(buffer+1,2);							// Byte 1:  Version=2					(1 Byte)
	PokeN16(buffer+2,commandId);				// Byte 2:  CommandId					(2 Byte)
	PokeN32(buffer+4,Id);						// Byte 4:  Id							(4 Byte)
	PokeN32(buffer+8,payload_size);				// Byte 8:  Bytes Nutzdaten				(4 Byte)
	PokeN8(buffer+12,flags);					// Byte 12: Flags						(1 Byte)
	//  											        Bit 0: Zlib-Kompression
	//														Bit 1: Client supports ZLib
	//														Bit 2: Client supports MsgChannel
	PokeN8(buffer+13,payload_type);				// Byte 13: Datatype, PPL_ARRAY, usw.	(1 Byte)
	PokeN16(buffer+14,rand(177,65534));			// Byte 14: Zufallszahl					(2 Byte)
	ppluint32 crc_data=0;
	if (payload_size) crc_data=Crc32(payload,payload_size);
	PokeN32(buffer+16,crc_data);				// Byte 16: CRC-Summe ueber die Daten	(4 Byte)
	PokeN32(buffer+20,Crc32(buffer,20));		// Byte 20: CRC-Summe ueber den Header	(4 Byte)
	*buffer_size=24;
}
	void ReadWriteMemory::copy(const AbstractReadMemory &memory_buffer,
		const Uint64 size, const Uint64 source_offset,
		const Uint64 dest_offset)
	{
		if (memory_buffer.get_size() < (source_offset + size))
		{
			EL_THROW_EXCEPTION(BufferTooSmallException()
				<< errinfo_size(memory_buffer.get_size()));
		}

		if (get_size() < (dest_offset + size))
		{
			EL_THROW_EXCEPTION(BufferTooSmallException()
				<< errinfo_size(get_size()));
		}

		memcpy(static_cast<Uint8*>(get_ptr()) + dest_offset,
			static_cast<const Uint8* const>(
			memory_buffer.get_ptr()) + source_offset, size);
	}