RarNode.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Text;
  2. using SharpCompress.Converters;
  3. namespace SharpCompress.Compressors.PPMd.H
  4. {
  5. internal class RarNode : Pointer
  6. {
  7. private int _next; //rarnode pointer
  8. public const int SIZE = 4;
  9. public RarNode(byte[] memory)
  10. : base(memory)
  11. {
  12. }
  13. internal int GetNext()
  14. {
  15. if (Memory != null)
  16. {
  17. _next = DataConverter.LittleEndian.GetInt32(Memory, Address);
  18. }
  19. return _next;
  20. }
  21. internal void SetNext(RarNode next)
  22. {
  23. SetNext(next.Address);
  24. }
  25. internal void SetNext(int next)
  26. {
  27. _next = next;
  28. if (Memory != null)
  29. {
  30. DataConverter.LittleEndian.PutBytes(Memory, Address, next);
  31. }
  32. }
  33. public override string ToString()
  34. {
  35. StringBuilder buffer = new StringBuilder();
  36. buffer.Append("State[");
  37. buffer.Append("\n Address=");
  38. buffer.Append(Address);
  39. buffer.Append("\n size=");
  40. buffer.Append(SIZE);
  41. buffer.Append("\n next=");
  42. buffer.Append(GetNext());
  43. buffer.Append("\n]");
  44. return buffer.ToString();
  45. }
  46. }
  47. }