Esempio n. 1
0
        public void SerializeLocal(BinaryWriter writer)
        {
            //Check in sequence of headers..
            FlagsByte bFlags = new FlagsByte();

            if (IsUserMsg)
            {
                bFlags.SetOn(FlagsByte.Flag.TRANS);
            }

            object tmpHdr;

            tmpHdr = (Header)headers[(object)(HeaderType.REQUEST_COORELATOR)];
            if (tmpHdr != null)
            {
                RequestCorrelator.HDR corHdr = (RequestCorrelator.HDR)tmpHdr;
                corHdr.SerializeLocal(writer);
                bFlags.SetOn(FlagsByte.Flag.COR);
            }

            tmpHdr = (Header)headers[(object)(HeaderType.TOTAL)];
            if (tmpHdr != null)
            {
                TOTAL.HDR totalHdr = (TOTAL.HDR)tmpHdr;
                totalHdr.SerializeLocal(writer);
                bFlags.SetOn(FlagsByte.Flag.TOTAL);
            }

            tmpHdr = (Header)headers[(object)(HeaderType.TCP)];
            if (tmpHdr != null)
            {
                TcpHeader tcpHdr = (TcpHeader)tmpHdr;
                tcpHdr.SerializeLocal(writer);
                bFlags.SetOn(FlagsByte.Flag.TCP);
            }

            writer.Write(Convert.ToInt16(prio));
            writer.Write(handledAsynchronously);
            writer.Write(arrivalTime.Ticks);
            writer.Write(sendTime.Ticks);
            writer.Write(responseExpected);
            writer.Write(_type);
            if (stream != null)
            {
                writer.Write(length);
                writer.Write(((MemoryStream)stream).GetBuffer(), 0, length);
            }
            else
            {
                int length = buf.Length;
                writer.Write(length);
                writer.Write(buf);
            }
            long curPos = writer.BaseStream.Position;

            writer.BaseStream.Position = 8;             //afte 4 bytes of total size and 4 bytes of message size ..here comes the flag.
            writer.Write(bFlags.DataByte);
            writer.BaseStream.Position = curPos;
        }