using System; namespace Renci.SshNet.Messages.Connection { /// /// Represents SSH_MSG_CHANNEL_DATA message. /// [Message("SSH_MSG_CHANNEL_DATA", MessageNumber)] public class ChannelDataMessage : ChannelMessage { internal const byte MessageNumber = 94; /// /// Gets or sets message data. /// /// /// The data. /// /// /// The actual data to read or write depends on the and . /// public byte[] Data { get; private set; } /// /// Gets the zero-based offset in at which the data begins. /// /// /// The zero-based offset in at which the data begins. /// public int Offset { get; set; } /// /// Gets the number of bytes of to read or write. /// /// /// The number of bytes of to read or write. /// public int Size { get; 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; // Data length capacity += Size; // Data return capacity; } } internal override void Process(Session session) { session.OnChannelDataReceived(this); } /// /// Initializes a new instance of the class. /// public ChannelDataMessage() { } /// /// Initializes a new instance of the class. /// /// The local channel number. /// Message data. public ChannelDataMessage(uint localChannelNumber, byte[] data) : base(localChannelNumber) { if (data == null) throw new ArgumentNullException("data"); Data = data; Offset = 0; Size = data.Length; } /// /// Initializes a new instance of the class. /// /// The local channel number. /// The message data. /// The zero-based byte offset in at which to begin reading or writing data from. /// The number of bytes of to read or write. public ChannelDataMessage(uint localChannelNumber, byte[] data, int offset, int size) : base(localChannelNumber) { if (data == null) throw new ArgumentNullException("data"); Data = data; Offset = offset; Size = size; } /// /// Loads the data. /// protected override void LoadData() { base.LoadData(); Data = ReadBinary(); Offset = 0; Size = Data.Length; } /// /// Saves the data. /// protected override void SaveData() { base.SaveData(); WriteBinary(Data, Offset, Size); } } }