SftpReadRequest.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using Renci.SshNet.Sftp.Responses;
  3. namespace Renci.SshNet.Sftp.Requests
  4. {
  5. internal class SftpReadRequest : SftpRequest
  6. {
  7. public override SftpMessageTypes SftpMessageType
  8. {
  9. get { return SftpMessageTypes.Read; }
  10. }
  11. public byte[] Handle { get; private set; }
  12. public UInt64 Offset { get; private set; }
  13. public UInt32 Length { get; private set; }
  14. #if TUNING
  15. /// <summary>
  16. /// Gets the size of the message in bytes.
  17. /// </summary>
  18. /// <value>
  19. /// The size of the messages in bytes.
  20. /// </value>
  21. protected override int BufferCapacity
  22. {
  23. get
  24. {
  25. var capacity = base.BufferCapacity;
  26. capacity += 4; // Handle length
  27. capacity += Handle.Length; // Handle
  28. capacity += 8; // Offset
  29. capacity += 4; // Length
  30. return capacity;
  31. }
  32. }
  33. #endif
  34. public SftpReadRequest(uint protocolVersion, uint requestId, byte[] handle, UInt64 offset, UInt32 length, Action<SftpDataResponse> dataAction, Action<SftpStatusResponse> statusAction)
  35. : base(protocolVersion, requestId, statusAction)
  36. {
  37. this.Handle = handle;
  38. this.Offset = offset;
  39. this.Length = length;
  40. this.SetAction(dataAction);
  41. }
  42. protected override void LoadData()
  43. {
  44. base.LoadData();
  45. #if TUNING
  46. this.Handle = this.ReadBinary();
  47. #else
  48. this.Handle = this.ReadBinaryString();
  49. #endif
  50. this.Offset = this.ReadUInt64();
  51. this.Length = this.ReadUInt32();
  52. }
  53. protected override void SaveData()
  54. {
  55. base.SaveData();
  56. this.WriteBinaryString(this.Handle);
  57. this.Write(this.Offset);
  58. this.Write(this.Length);
  59. }
  60. }
  61. }