namespace Renci.SshNet.Messages.Connection
{
    /// 
    /// Represents SSH_MSG_CHANNEL_REQUEST message.
    /// 
    [Message("SSH_MSG_CHANNEL_REQUEST", 98)]
    public class ChannelRequestMessage : ChannelMessage
    {
        /// 
        /// Gets the name of the request.
        /// 
        /// 
        /// The name of the request.
        /// 
        public string RequestName { get; private set; }
        /// 
        /// Gets channel request data.
        /// 
        public byte[] RequestData { get; private set; }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        public ChannelRequestMessage()
        {
            //  Required for dynamically loading request type when it comes from the server
        }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Name of the local channel.
        /// The info.
        public ChannelRequestMessage(uint localChannelName, RequestInfo info)
        {
            this.LocalChannelNumber = localChannelName;
            this.RequestName = info.RequestName;
            this.RequestData = info.GetBytes();
        }
        /// 
        /// Called when type specific data need to be loaded.
        /// 
        protected override void LoadData()
        {
            base.LoadData();
            this.RequestName = this.ReadAsciiString();
            this.RequestData = this.ReadBytes();
        }
        /// 
        /// Called when type specific data need to be saved.
        /// 
        protected override void SaveData()
        {
            base.SaveData();
            this.WriteAscii(this.RequestName);
            this.Write(this.RequestData);
        }
    }
}