ErrorMessage.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using SocketIOClient.Transport;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text.Json;
  5. namespace SocketIOClient.Messages
  6. {
  7. public class ErrorMessage : IMessage
  8. {
  9. public MessageType Type => MessageType.ErrorMessage;
  10. public string Message { get; set; }
  11. public string Namespace { get; set; }
  12. public List<byte[]> OutgoingBytes { get; set; }
  13. public List<byte[]> IncomingBytes { get; set; }
  14. public int BinaryCount { get; }
  15. public int Eio { get; set; }
  16. public TransportProtocol Protocol { get; set; }
  17. public void Read(string msg)
  18. {
  19. if (Eio == 3)
  20. {
  21. Message = msg.Trim('"');
  22. }
  23. else
  24. {
  25. int index = msg.IndexOf('{');
  26. if (index > 0)
  27. {
  28. Namespace = msg.Substring(0, index - 1);
  29. msg = msg.Substring(index);
  30. }
  31. var doc = JsonDocument.Parse(msg);
  32. Message = doc.RootElement.GetProperty("message").GetString();
  33. }
  34. }
  35. public string Write()
  36. {
  37. throw new NotImplementedException();
  38. }
  39. }
  40. }