DeflateInput.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics;
  5. namespace SharpCompress.Compressors.Deflate64
  6. {
  7. internal sealed class DeflateInput
  8. {
  9. internal byte[] Buffer { get; set; }
  10. internal int Count { get; set; }
  11. internal int StartIndex { get; set; }
  12. internal void ConsumeBytes(int n)
  13. {
  14. Debug.Assert(n <= Count, "Should use more bytes than what we have in the buffer");
  15. StartIndex += n;
  16. Count -= n;
  17. Debug.Assert(StartIndex + Count <= Buffer.Length, "Input buffer is in invalid state!");
  18. }
  19. internal InputState DumpState() => new InputState(Count, StartIndex);
  20. internal void RestoreState(InputState state)
  21. {
  22. Count = state._count;
  23. StartIndex = state._startIndex;
  24. }
  25. internal /*readonly */struct InputState
  26. {
  27. internal readonly int _count;
  28. internal readonly int _startIndex;
  29. internal InputState(int count, int startIndex)
  30. {
  31. _count = count;
  32. _startIndex = startIndex;
  33. }
  34. }
  35. }
  36. }