Cakewalk.NetEntity.DeserializePacket C# (CSharp) Метод

DeserializePacket() приватный Метод

Deserializes a packet from the given buffer. Returns the amount of bytes consumed.
private DeserializePacket ( IntPtr buffer ) : int
buffer System.IntPtr
Результат int
        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;
        }