DownloadAgentHelperUpdateBytesEventArgs.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. namespace GameFramework.Download
  8. {
  9. /// <summary>
  10. /// 下载代理辅助器更新数据流事件。
  11. /// </summary>
  12. public sealed class DownloadAgentHelperUpdateBytesEventArgs : GameFrameworkEventArgs
  13. {
  14. private byte[] m_Bytes;
  15. /// <summary>
  16. /// 初始化下载代理辅助器更新数据流事件的新实例。
  17. /// </summary>
  18. public DownloadAgentHelperUpdateBytesEventArgs()
  19. {
  20. m_Bytes = null;
  21. Offset = 0;
  22. Length = 0;
  23. }
  24. /// <summary>
  25. /// 获取数据流的偏移。
  26. /// </summary>
  27. public int Offset
  28. {
  29. get;
  30. private set;
  31. }
  32. /// <summary>
  33. /// 获取数据流的长度。
  34. /// </summary>
  35. public int Length
  36. {
  37. get;
  38. private set;
  39. }
  40. /// <summary>
  41. /// 创建下载代理辅助器更新数据流事件。
  42. /// </summary>
  43. /// <param name="bytes">下载的数据流。</param>
  44. /// <param name="offset">数据流的偏移。</param>
  45. /// <param name="length">数据流的长度。</param>
  46. /// <returns>创建的下载代理辅助器更新数据流事件。</returns>
  47. public static DownloadAgentHelperUpdateBytesEventArgs Create(byte[] bytes, int offset, int length)
  48. {
  49. if (bytes == null)
  50. {
  51. throw new GameFrameworkException("Bytes is invalid.");
  52. }
  53. if (offset < 0 || offset >= bytes.Length)
  54. {
  55. throw new GameFrameworkException("Offset is invalid.");
  56. }
  57. if (length <= 0 || offset + length > bytes.Length)
  58. {
  59. throw new GameFrameworkException("Length is invalid.");
  60. }
  61. DownloadAgentHelperUpdateBytesEventArgs downloadAgentHelperUpdateBytesEventArgs = ReferencePool.Acquire<DownloadAgentHelperUpdateBytesEventArgs>();
  62. downloadAgentHelperUpdateBytesEventArgs.m_Bytes = bytes;
  63. downloadAgentHelperUpdateBytesEventArgs.Offset = offset;
  64. downloadAgentHelperUpdateBytesEventArgs.Length = length;
  65. return downloadAgentHelperUpdateBytesEventArgs;
  66. }
  67. /// <summary>
  68. /// 清理下载代理辅助器更新数据流事件。
  69. /// </summary>
  70. public override void Clear()
  71. {
  72. m_Bytes = null;
  73. Offset = 0;
  74. Length = 0;
  75. }
  76. /// <summary>
  77. /// 获取下载的数据流。
  78. /// </summary>
  79. public byte[] GetBytes()
  80. {
  81. return m_Bytes;
  82. }
  83. }
  84. }