ResultList.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_result_list_t
  15. /// </summary>
  16. public class ResultList : List<ResultElement>
  17. {
  18. //byte NumberOfResults;
  19. public byte Reserved;
  20. public ushort Reserved2;
  21. public ResultList() : base()
  22. {}
  23. public ResultList(byte[] buffer, int offset) : base()
  24. {
  25. byte numberOfResults = ByteReader.ReadByte(buffer, offset + 0);
  26. Reserved = ByteReader.ReadByte(buffer, offset + 1);
  27. Reserved2 = LittleEndianConverter.ToUInt16(buffer, offset + 2);
  28. offset += 4;
  29. for (int index = 0; index < numberOfResults; index++)
  30. {
  31. ResultElement element = new ResultElement(buffer, offset);
  32. this.Add(element);
  33. offset += ResultElement.Length;
  34. }
  35. }
  36. public void WriteBytes(byte[] buffer, int offset)
  37. {
  38. byte numberOfResults = (byte)this.Count;
  39. ByteWriter.WriteByte(buffer, offset + 0, numberOfResults);
  40. ByteWriter.WriteByte(buffer, offset + 1, Reserved);
  41. LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved2);
  42. offset += 4;
  43. for (int index = 0; index < numberOfResults; index++)
  44. {
  45. this[index].WriteBytes(buffer, offset);
  46. offset += ResultElement.Length;
  47. }
  48. }
  49. public void WriteBytes(byte[] buffer, ref int offset)
  50. {
  51. WriteBytes(buffer, offset);
  52. offset += this.Length;
  53. }
  54. public int Length
  55. {
  56. get
  57. {
  58. return 4 + ResultElement.Length * this.Count;
  59. }
  60. }
  61. }
  62. }