PathInfo.vala 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace LibPeer.Protocols.Mx2 {
  2. public class PathInfo {
  3. public unowned List<InstanceReference> repeaters { get; protected set; }
  4. public PathInfo return_path {
  5. owned get {
  6. var path = repeaters.copy_deep((m) => m);
  7. path.reverse();
  8. return new PathInfo(path);
  9. }
  10. }
  11. public PathInfo(List<InstanceReference> repeaters) {
  12. this.repeaters = repeaters;
  13. }
  14. public void serialise(OutputStream stream) throws IOError {
  15. // Write number of repeaters
  16. stream.write({(uint8)repeaters.length()});
  17. // Write the repeaters
  18. foreach (var repeater in repeaters) {
  19. repeater.serialise(stream);
  20. }
  21. }
  22. public PathInfo.from_stream(InputStream stream) throws IOError, Error {
  23. // Get number of repeaters
  24. uint8 repeater_count = stream.read_bytes(1).get(0);
  25. // Create list
  26. repeaters = new List<InstanceReference>();
  27. // Read repeaters
  28. for (uint8 i = 0; i < repeater_count; i++) {
  29. repeaters.append(new InstanceReference.from_stream(stream));
  30. }
  31. }
  32. public PathInfo.empty() {
  33. this(new List<InstanceReference>());
  34. }
  35. }
  36. }