namespace Renci.SshNet.Messages.Transport
{
///
/// Represents SSH_MSG_DISCONNECT message.
///
[Message("SSH_MSG_DISCONNECT", 1)]
public class DisconnectMessage : Message, IKeyExchangedAllowed
{
private byte[] _description;
private byte[] _language;
///
/// Gets disconnect reason code.
///
public DisconnectReason ReasonCode { get; private set; }
///
/// Gets disconnect description.
///
public string Description
{
get { return Utf8.GetString(_description, 0, _description.Length); }
private set { _description = Utf8.GetBytes(value); }
}
///
/// Gets message language.
///
public string Language
{
get { return Utf8.GetString(_language, 0, _language.Length); }
private set { _language = Utf8.GetBytes(value); }
}
///
/// 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; // ReasonCode
capacity += 4; // Description length
capacity += _description.Length; // Description
capacity += 4; // Language length
capacity += _language.Length; // Language
return capacity;
}
}
///
/// Initializes a new instance of the class.
///
public DisconnectMessage()
{
}
///
/// Initializes a new instance of the class.
///
/// The reason code.
/// The message.
public DisconnectMessage(DisconnectReason reasonCode, string message)
{
ReasonCode = reasonCode;
Description = message;
Language = "en";
}
///
/// Called when type specific data need to be loaded.
///
protected override void LoadData()
{
ReasonCode = (DisconnectReason) ReadUInt32();
_description = ReadBinary();
_language = ReadBinary();
}
///
/// Called when type specific data need to be saved.
///
protected override void SaveData()
{
Write((uint) ReasonCode);
WriteBinaryString(_description);
WriteBinaryString(_language);
}
internal override void Process(Session session)
{
session.OnDisconnectReceived(this);
}
}
}