CMethodId.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace SharpCompress.Common.SevenZip
  2. {
  3. internal struct CMethodId
  4. {
  5. public const ulong K_COPY_ID = 0;
  6. public const ulong K_LZMA_ID = 0x030101;
  7. public const ulong K_LZMA2_ID = 0x21;
  8. public const ulong K_AES_ID = 0x06F10701;
  9. public static readonly CMethodId K_COPY = new CMethodId(K_COPY_ID);
  10. public static readonly CMethodId K_LZMA = new CMethodId(K_LZMA_ID);
  11. public static readonly CMethodId K_LZMA2 = new CMethodId(K_LZMA2_ID);
  12. public static readonly CMethodId K_AES = new CMethodId(K_AES_ID);
  13. public readonly ulong _id;
  14. public CMethodId(ulong id)
  15. {
  16. _id = id;
  17. }
  18. public override int GetHashCode()
  19. {
  20. return _id.GetHashCode();
  21. }
  22. public override bool Equals(object obj)
  23. {
  24. return obj is CMethodId && (CMethodId)obj == this;
  25. }
  26. public bool Equals(CMethodId other)
  27. {
  28. return _id == other._id;
  29. }
  30. public static bool operator ==(CMethodId left, CMethodId right)
  31. {
  32. return left._id == right._id;
  33. }
  34. public static bool operator !=(CMethodId left, CMethodId right)
  35. {
  36. return left._id != right._id;
  37. }
  38. public int GetLength()
  39. {
  40. int bytes = 0;
  41. for (ulong value = _id; value != 0; value >>= 8)
  42. {
  43. bytes++;
  44. }
  45. return bytes;
  46. }
  47. }
  48. }