ChannelOpenMessage
Represents SSH_MSG_CHANNEL_OPEN message.
            
                using Renci.SshNet.Common;
using System;
using System.Globalization;
namespace Renci.SshNet.Messages.Connection
{
    public class ChannelOpenMessage : Message
    {
        private byte[] _infoBytes;
        public override string MessageName => "SSH_MSG_CHANNEL_OPEN";
        public override byte MessageNumber => 90;
        public byte[] ChannelType { get; set; }
        public uint LocalChannelNumber { get; set; }
        public uint InitialWindowSize { get; set; }
        public uint MaximumPacketSize { get; set; }
        public ChannelOpenInfo Info { get; set; }
        protected override int BufferCapacity => base.BufferCapacity + 4 + ChannelType.Length + 4 + 4 + 4 + _infoBytes.Length;
        public ChannelOpenMessage()
        {
        }
        public ChannelOpenMessage(uint channelNumber, uint initialWindowSize, uint maximumPacketSize, ChannelOpenInfo info)
        {
            ThrowHelper.ThrowIfNull(info, "info");
            ChannelType = SshData.Ascii.GetBytes(info.ChannelType);
            LocalChannelNumber = channelNumber;
            InitialWindowSize = initialWindowSize;
            MaximumPacketSize = maximumPacketSize;
            Info = info;
            _infoBytes = info.GetBytes();
        }
        protected override void LoadData()
        {
            ChannelType = ReadBinary();
            LocalChannelNumber = ReadUInt32();
            InitialWindowSize = ReadUInt32();
            MaximumPacketSize = ReadUInt32();
            _infoBytes = ReadBytes();
            string string = SshData.Ascii.GetString(ChannelType, 0, ChannelType.Length);
            switch (string) {
            case "session":
                Info = new SessionChannelOpenInfo(_infoBytes);
                break;
            case "x11":
                Info = new X11ChannelOpenInfo(_infoBytes);
                break;
            case "direct-tcpip":
                Info = new DirectTcpipChannelInfo(_infoBytes);
                break;
            case "forwarded-tcpip":
                Info = new ForwardedTcpipChannelInfo(_infoBytes);
                break;
            default:
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Channel type '{0}' is not supported.", string));
            }
        }
        protected override void SaveData()
        {
            WriteBinaryString(ChannelType);
            Write(LocalChannelNumber);
            Write(InitialWindowSize);
            Write(MaximumPacketSize);
            Write(_infoBytes);
        }
        internal override void Process(Session session)
        {
            session.OnChannelOpenReceived(this);
        }
    }
}