< Summary

Information
Class: Renci.SshNet.Sftp.SftpMessage
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Sftp\SftpMessage.cs
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 78
Line coverage: 87.5%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_BufferCapacity()100%1100%
LoadData()100%1100%
SaveData()100%1100%
WriteBytes(...)100%1100%
ReadAttributes()100%1100%
ToString()100%10%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Sftp\SftpMessage.cs

#LineLine coverage
 1using System.Globalization;
 2using System.IO;
 3
 4using Renci.SshNet.Common;
 5
 6namespace Renci.SshNet.Sftp
 7{
 8    internal abstract class SftpMessage : SshData
 9    {
 10        /// <summary>
 11        /// Gets the size of the message in bytes.
 12        /// </summary>
 13        /// <value>
 14        /// The size of the messages in bytes.
 15        /// </value>
 16        protected override int BufferCapacity
 17        {
 18            get
 3240519            {
 20                // 4 bytes for the length of the SFTP data
 21                // 1 byte for the SFTP message type
 3240522                return 5;
 3240523            }
 24        }
 25
 26        public abstract SftpMessageTypes SftpMessageType { get; }
 27
 28        protected override void LoadData()
 3217729        {
 3217730        }
 31
 32        protected override void SaveData()
 3240533        {
 3240534            Write((byte) SftpMessageType);
 3240535        }
 36
 37        /// <summary>
 38        /// Writes the current message to the specified <see cref="SshDataStream"/>.
 39        /// </summary>
 40        /// <param name="stream">The <see cref="SshDataStream"/> to write the message to.</param>
 41        protected override void WriteBytes(SshDataStream stream)
 3240542        {
 43            const int sizeOfDataLengthBytes = 4;
 44
 3240545            var startPosition = stream.Position;
 46
 47            // skip 4 bytes for the length of the SFTP message data
 3240548            _ = stream.Seek(sizeOfDataLengthBytes, SeekOrigin.Current);
 49
 50            // write the SFTP message data to the stream
 3240551            base.WriteBytes(stream);
 52
 53            // save where we were positioned when we finished writing the SSH message data
 3240554            var endPosition = stream.Position;
 55
 56            // determine the length of the SSH message data
 3240557            var dataLength = endPosition - startPosition - sizeOfDataLengthBytes;
 58
 59            // write the length of the SFTP message where we were positioned before we started
 60            // writing the SFTP message data
 3240561            stream.Position = startPosition;
 3240562            stream.Write((uint) dataLength);
 63
 64            // move back to we were positioned when we finished writing the SFTP message data
 3240565            stream.Position = endPosition;
 3240566        }
 67
 68        protected SftpFileAttributes ReadAttributes()
 2215069        {
 2215070            return SftpFileAttributes.FromBytes(DataStream);
 2215071        }
 72
 73        public override string ToString()
 074        {
 075            return string.Format(CultureInfo.CurrentCulture, "SFTP Message : {0}", SftpMessageType);
 076        }
 77    }
 78}