Пример #1
0
        /// <summary>
        /// Extracts the packet with the specified bitmask of <see cref="PacketExtractionFlags"/> enum.
        /// </summary>
        /// <param name="flags">Bitmask of <see cref="PacketExtractionFlags"/>.</param>
        /// <param name="packetLength">Length of the packet in bytes.</param>
        /// <returns>Packet bytes.</returns>
        public byte[] ExtractPacket(PacketExtractionFlags flags, int packetLength)
        {
            using (var packetStream = new MemoryStream(packetLength + HeaderSize))
            {
                if (flags.HasFlag(PacketExtractionFlags.Header))
                {
                    packetStream.Write(Buffer, 0, HeaderSize);
                }
                if (flags.HasFlag(PacketExtractionFlags.Body))
                {
                    packetStream.Write(Buffer, HeaderSize, packetLength);
                }
                if (flags.HasFlag(PacketExtractionFlags.Remove))
                {
                    var buffer = new byte[Buffer.Length - (packetLength + HeaderSize)];

                    if (!m_InitializedFromByteArray)
                    {
                        Array.Copy(Buffer, packetLength + HeaderSize, buffer, 0, buffer.Length);
                        Array.Resize(ref buffer, m_OriginalBufferSize);
                        m_SocketAsyncEventArgs.SetBuffer(buffer, 0, m_OriginalBufferSize);
                    }
                    else
                    {
                        m_Buffer = buffer;
                    }
                }
                return(packetStream.ToArray());
            }
        }
Пример #2
0
 /// <summary>
 /// Extracts the packet with the specified bitmask of <see cref="PacketExtractionFlags"/> enum.
 /// </summary>
 /// <param name="flags">Bitmask of <see cref="PacketExtractionFlags"/>.</param>
 /// <param name="packetLength">Length of the packet in bytes.</param>
 /// <returns>Packet bytes.</returns>
 public byte[] ExtractPacket(PacketExtractionFlags flags, int packetLength)
 {
     using (var packetStream = new MemoryStream(packetLength + HeaderSize))
     {
         if (flags.HasFlag(PacketExtractionFlags.Header))
         {
             packetStream.Write(Buffer, 0, HeaderSize);
         }
         if (flags.HasFlag(PacketExtractionFlags.Body))
         {
             packetStream.Write(Buffer, HeaderSize, packetLength);
         }
         if (flags.HasFlag(PacketExtractionFlags.Remove))
         {
             var buffer = new byte[Buffer.Length - (packetLength + HeaderSize)];
             Array.Copy(Buffer, packetLength + HeaderSize, buffer, 0, buffer.Length);
             Array.Resize(ref buffer, OriginalBufferSize);
             SocketAsyncEventArgs.SetBuffer(buffer, 0, OriginalBufferSize);
         }
         return packetStream.ToArray();
     }
 }
Пример #3
0
 /// <summary>
 /// Extracts the packet with the specified bitmask of <see cref="PacketExtractionFlags"/> enum.
 /// </summary>
 /// <param name="flags">Bitmask of <see cref="PacketExtractionFlags"/>.</param>
 /// <param name="packetLength">Length of the packet in bytes.</param>
 /// <returns>Packet bytes.</returns>
 public byte[] ExtractPacket(PacketExtractionFlags flags, int packetLength)
 {
     using (var packetStream = new MemoryStream(packetLength + HeaderSize))
     {
         if (flags.HasFlag(PacketExtractionFlags.Header))
         {
             packetStream.Write(Buffer, 0, HeaderSize);
         }
         if (flags.HasFlag(PacketExtractionFlags.Body))
         {
             packetStream.Write(Buffer, HeaderSize, packetLength);
         }
         if (flags.HasFlag(PacketExtractionFlags.Remove))
         {
             var buffer = new byte[Buffer.Length - (packetLength + HeaderSize)];
             Array.Copy(Buffer, packetLength + HeaderSize, buffer, 0, buffer.Length);
             Array.Resize(ref buffer, m_OriginalBufferSize);
             m_Buffer = buffer;
         }
         return(packetStream.ToArray());
     }
 }