/// <summary> /// Read stream to the current object include the body and properties using <see cref="IBinaryStreamer"/>, This method is a part of <see cref="ISerialEntity"/> implementation. /// </summary> /// <param name="stream"></param> /// <param name="streamer"></param> public void EntityRead(Stream stream, IBinaryStreamer streamer) { if (streamer == null) { streamer = new BinaryStreamer(stream); } string mmsg = streamer.ReadFixedString(); if (mmsg != TcpReplyStream.MsgReplyBegin) { throw new Exception("Incorrect message format"); } m_ReplyCode = streamer.ReadValue <int>(); m_ReplyType = (TcpReplyType)streamer.ReadValue <byte>(); if (m_ReplyType == TcpReplyType.Stream) { m_ReplyStream = (NetStream)streamer.ReadValue(); } else { m_Text = streamer.ReadString(); } string endmsg = streamer.ReadFixedString(); if (endmsg != TcpReplyStream.MsgReplyEnd) { throw new Exception("Incorrect message format"); } }
/// <summary> /// /// </summary> /// <param name="replyCode">TcpMessage server reply code.</param> /// <param name="stream"></param> /// <param name="isLastLine">Specifies if this line is last line in response.</param> public TcpReplyStream(int replyCode, NetStream stream, bool isLastLine = true) { m_ReplyType = TcpReplyType.Stream; m_ReplyStream = stream; m_ReplyCode = replyCode; m_Text = null; m_IsLastLine = isLastLine; }
/// <summary> /// Default constructor. /// </summary> /// <param name="replyCode">TcpMessage server reply code.</param> /// <param name="text">TcpMessage server reply text.</param> /// <param name="isLastLine">Specifies if this line is last line in response.</param> public TcpReplyStream(int replyCode, string text, bool isLastLine = true) { if (text == null) { text = ""; } m_ReplyType = TcpReplyType.Text; m_ReplyCode = replyCode; m_Text = text; m_ReplyStream = new NetStream(Encoding.UTF8.GetBytes(text)); m_IsLastLine = isLastLine; }