SyntaxID.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.RPC
  12. {
  13. /// <summary>
  14. /// p_syntax_id_t
  15. /// </summary>
  16. public struct SyntaxID
  17. {
  18. public const int Length = 20;
  19. public Guid InterfaceUUID; // if_uuid
  20. public uint InterfaceVersion; // if_version
  21. public SyntaxID(Guid interfaceUUID, uint interfaceVersion)
  22. {
  23. InterfaceUUID = interfaceUUID;
  24. InterfaceVersion = interfaceVersion;
  25. }
  26. public SyntaxID(byte[] buffer, int offset)
  27. {
  28. InterfaceUUID = LittleEndianConverter.ToGuid(buffer, offset + 0);
  29. InterfaceVersion = LittleEndianConverter.ToUInt32(buffer, offset + 16);
  30. }
  31. public void WriteBytes(byte[] buffer, int offset)
  32. {
  33. LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, InterfaceUUID);
  34. LittleEndianWriter.WriteUInt32(buffer, offset + 16, InterfaceVersion);
  35. }
  36. public override bool Equals(object obj)
  37. {
  38. if (obj is SyntaxID)
  39. {
  40. return this.InterfaceUUID.Equals(((SyntaxID)obj).InterfaceUUID) && this.InterfaceVersion.Equals(((SyntaxID)obj).InterfaceVersion);
  41. }
  42. return false;
  43. }
  44. public override int GetHashCode()
  45. {
  46. return InterfaceUUID.GetHashCode() * InterfaceVersion.GetHashCode();
  47. }
  48. }
  49. }