Beispiel #1
0
        public override void Write(ref NetworkStream netstream)
        {
            using (Stream stream = new MemoryStream())
            {
                // write id
                stream.Write(BitConverter.GetBytes((ushort)this.ID), 0, 2);

                // write temporary size
                stream.Write(BitConverter.GetBytes(0), 0, 4);

                // write pctypes
                stream.WriteByte((byte)_pctypes[0]);
                stream.WriteByte((byte)_pctypes[1]);
                stream.WriteByte((byte)_pctypes[2]);

                // store header size
                int headersize = (int)stream.Position;

                // write slots
                if (Slot1 != null)
                {
                    Slot1.Write(stream);
                }

                if (Slot2 != null)
                {
                    Slot2.Write(stream);
                }

                if (Slot3 != null)
                {
                    Slot3.Write(stream);
                }

                byte[] result = new byte[stream.Length];

                // go back and write body size
                this.BodySize = (uint)(stream.Length - headersize);

                stream.Position = 2;
                stream.Write(BitConverter.GetBytes(this.BodySize), 0, 4);

                // write memorystream to networkstream
                stream.Position = 0;
                stream.CopyTo(netstream);
            }
        }