SftpBlockRequest.cs 2.1 KB

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