Exemplo n.º 1
0
        internal static byte[] serializeMessage(Message msg)
        {
            int len = 0;

            byte[]    buffie;
            FlagsByte flags = new FlagsByte();

            msg.Dest  = null;
            msg.Dests = null;

            RequestCorrelator.HDR rqHeader = (RequestCorrelator.HDR)msg.getHeader(HeaderType.REQUEST_COORELATOR);

            if (rqHeader != null)
            {
                rqHeader.serializeFlag = false;
            }

            Stream stmOut = new MemoryStream();

            stmOut.Write(Util.WriteInt32(len), 0, 4);
            stmOut.Write(Util.WriteInt32(len), 0, 4);

            if (msg.IsUserMsg)
            {
                BinaryWriter msgWriter = new BinaryWriter(stmOut, new UTF8Encoding(true));
                flags.SetOn(FlagsByte.Flag.TRANS);
                msgWriter.Write(flags.DataByte);
                msg.SerializeLocal(msgWriter);
            }
            else
            {
                flags.SetOff(FlagsByte.Flag.TRANS);
                stmOut.WriteByte(flags.DataByte);
                CompactBinaryFormatter.Serialize(stmOut, msg, null, false);
            }

            len = (int)stmOut.Position - 4;

            int payloadLength = 0;

            // the user payload size. payload is passed on untill finally send on the socket.
            if (msg.Payload != null)
            {
                for (int i = 0; i < msg.Payload.Length; i++)
                {
                    payloadLength += ((byte[])msg.Payload.GetValue(i)).Length;
                }
                len += payloadLength;
            }

            stmOut.Position = 0;
            stmOut.Write(Util.WriteInt32(len), 0, 4);
            stmOut.Write(Util.WriteInt32(len - 4 - payloadLength), 0, 4);
            stmOut.Position = 0;
            buffie          = new byte[len + 4 - payloadLength];
            stmOut.Read(buffie, 0, len + 4 - payloadLength);
            stmOut.Position = 0;

            return(buffie);
        }
Exemplo n.º 2
0
        /// <summary>Tries to read an object from the message's buffer and prints it </summary>
        public static string printMessage(Message msg)
        {
            if (msg == null)
            {
                return("");
            }
            if (msg.Length == 0)
            {
                return(null);
            }

            try
            {
                return(msg.getObject().ToString());
            }
            catch (System.Exception ex)
            {
                return("");
            }
        }
Exemplo n.º 3
0
        internal static byte[] serializeMessage(Message msg)
        {
            int len = 0;
            byte[] buffie;
            FlagsByte flags = new FlagsByte();

            msg.Dest = null;
            msg.Dests = null;

            RequestCorrelator.HDR rqHeader = (RequestCorrelator.HDR)msg.getHeader(HeaderType.REQUEST_COORELATOR);

            if (rqHeader != null)
            {
                rqHeader.serializeFlag = false;
            }

            Stream stmOut = new MemoryStream();
            stmOut.Write(Util.WriteInt32(len), 0, 4);
            stmOut.Write(Util.WriteInt32(len), 0, 4);

            if (msg.IsUserMsg)
            {
                BinaryWriter msgWriter = new BinaryWriter(stmOut, new UTF8Encoding(true));
                flags.SetOn(FlagsByte.Flag.TRANS);
                msgWriter.Write(flags.DataByte);
                msg.SerializeLocal(msgWriter);
            }
            else
            {
                flags.SetOff(FlagsByte.Flag.TRANS);
                stmOut.WriteByte(flags.DataByte);
                CompactBinaryFormatter.Serialize(stmOut, msg, null, false);
            }

            len = (int)stmOut.Position - 4;

            int payloadLength = 0;
            // the user payload size. payload is passed on untill finally send on the socket.
            if (msg.Payload != null)
            {
                for (int i = 0; i < msg.Payload.Length; i++)
                {
                    payloadLength += ((byte[])msg.Payload.GetValue(i)).Length;
                }
                len += payloadLength;
            }

            stmOut.Position = 0;
            stmOut.Write(Util.WriteInt32(len), 0, 4);
            stmOut.Write(Util.WriteInt32(len - 4 - payloadLength), 0, 4);
            stmOut.Position = 0;
            buffie = new byte[len + 4 - payloadLength];
            stmOut.Read(buffie, 0, len + 4 - payloadLength);
            stmOut.Position = 0;

            return buffie;
        }
Exemplo n.º 4
0
		/// <summary>Tries to read an object from the message's buffer and prints it </summary>
		public static string printMessage(Message msg)
		{
			if (msg == null)
				return "";
			if (msg.Length == 0)
				return null;
			
			try
			{
				return msg.getObject().ToString();
			}
			catch (System.Exception ex)
			{
				
				return "";
			}
		}