private int DeserializePacket(IntPtr buffer)
{
PacketHeader packetHeader = (PacketHeader)Marshal.PtrToStructure(buffer, typeof(PacketHeader));
//Get the type for the packet sitting in the receive buffer
Type packetType = PacketMap.GetTypeForPacketCode(packetHeader.OpCode);
//If we can deserialize it...
if (packetType != null)
{
try
{
//Block copy the buffer to a struct of the correct type
IPacketBase packet = (IPacketBase)Marshal.PtrToStructure(buffer, packetType);
//Throw the strongly-typed packet into the incoming queue
m_incomingQueue.Enqueue(packet);
return packet.Header.SizeInBytes;
}
catch (Exception ex)
{
Console.Write("Deserialization error! " + ex);
}
}
else
{
Console.WriteLine("Bad packet code: " + packetHeader.OpCode);
}
return 0;
}