using System;
namespace Renci.SshNet.Messages.Connection
{
///
/// Used to open "x11" channel type
///
internal class X11ChannelOpenInfo : ChannelOpenInfo
{
private byte[] _originatorAddress;
///
/// Specifies channel open type
///
public const string Name = "x11";
///
/// Gets the type of the channel to open.
///
///
/// The type of the channel to open.
///
public override string ChannelType
{
get { return Name; }
}
///
/// Gets the originator address.
///
public string OriginatorAddress
{
get { return Utf8.GetString(_originatorAddress, 0, _originatorAddress.Length); }
private set { _originatorAddress = Utf8.GetBytes(value); }
}
///
/// Gets the originator port.
///
public uint OriginatorPort { get; private set; }
///
/// Gets the size of the message in bytes.
///
///
/// The size of the messages in bytes.
///
protected override int BufferCapacity
{
get
{
var capacity = base.BufferCapacity;
capacity += 4; // OriginatorAddress length
capacity += _originatorAddress.Length; // OriginatorAddress
capacity += 4; // OriginatorPort
return capacity;
}
}
///
/// Initializes a new instance of the class from the
/// specified data.
///
/// is null.
public X11ChannelOpenInfo(byte[] data)
{
Load(data);
}
///
/// Initializes a new instance of the class with the
/// specified originator address and port.
///
/// The originator address.
/// The originator port.
public X11ChannelOpenInfo(string originatorAddress, uint originatorPort)
{
OriginatorAddress = originatorAddress;
OriginatorPort = originatorPort;
}
///
/// Called when type specific data need to be loaded.
///
protected override void LoadData()
{
base.LoadData();
_originatorAddress = ReadBinary();
OriginatorPort = ReadUInt32();
}
///
/// Called when type specific data need to be saved.
///
protected override void SaveData()
{
base.SaveData();
WriteBinaryString(_originatorAddress);
Write(OriginatorPort);
}
}
}