예제 #1
0
        /// <summary>
        ///     Writes the packet to a byte-array
        /// </summary>
        /// <returns>The packet in byte array</returns>
        public byte[] GetBytes()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriterExt(ms))
                {
                    var bodyBytes = Encoding.ASCII.GetBytes(Payload + '\0');
                    writer.WriteLittleEndian(bodyBytes.Length + 9);
                    writer.WriteLittleEndian(Id);
                    writer.WriteLittleEndian((int)Type);
                    writer.Write(bodyBytes);
                    writer.Write('\0');

                    return(ms.ToArray());
                }
            }
        }