SocketLibrary.Packets.Packet.GetFullData C# (CSharp) Method

GetFullData() public method

Converts the data in this packet to a byte array, this includes the header.
public GetFullData ( ) : byte[]
return byte[]
        public byte[] GetFullData()
        {
            LinkedList<byte> fullData = new LinkedList<byte>();
            // Header first
            fullData.AddLast(this.header);
            foreach (byte b in this.packetID)
            {
                // Packet ID next
                fullData.AddLast(b);
            }

            foreach (byte b in this.data)
            {
                // Now the data we wanted to send
                fullData.AddLast(b);
            }

            fullData.AddLast(SocketClient.END_OF_PACKET);

            return fullData.ToArray();
        }

Usage Example

 /// <summary>
 /// Attempts to send a packet to the server.
 /// </summary>
 /// <returns>If the packet was sent or not.</returns>
 /// <param name="packet">The packet to send</param>
 public Boolean SendPacket(Packet packet)
 {
     if (packet.GetFullData().Length == 0)
     {
         Console.Error.WriteLine("Cannot send a packet with length = 0");
         return false;
     }
     this.connection.SendPacket(packet);
     return true;
 }
All Usage Examples Of SocketLibrary.Packets.Packet::GetFullData