Constants.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Text;
  2. namespace Mirror.SimpleWeb
  3. {
  4. /// <summary>
  5. /// Constant values that should never change
  6. /// <para>
  7. /// Some values are from https://tools.ietf.org/html/rfc6455
  8. /// </para>
  9. /// </summary>
  10. internal static class Constants
  11. {
  12. /// <summary>
  13. /// Header is at most 4 bytes
  14. /// <para>
  15. /// If message is less than 125 then header is 2 bytes, else header is 4 bytes
  16. /// </para>
  17. /// </summary>
  18. public const int HeaderSize = 4;
  19. /// <summary>
  20. /// Smallest size of header
  21. /// <para>
  22. /// If message is less than 125 then header is 2 bytes, else header is 4 bytes
  23. /// </para>
  24. /// </summary>
  25. public const int HeaderMinSize = 2;
  26. /// <summary>
  27. /// bytes for short length
  28. /// </summary>
  29. public const int ShortLength = 2;
  30. /// <summary>
  31. /// Message mask is always 4 bytes
  32. /// </summary>
  33. public const int MaskSize = 4;
  34. /// <summary>
  35. /// Max size of a message for length to be 1 byte long
  36. /// <para>
  37. /// payload length between 0-125
  38. /// </para>
  39. /// </summary>
  40. public const int BytePayloadLength = 125;
  41. /// <summary>
  42. /// if payload length is 126 when next 2 bytes will be the length
  43. /// </summary>
  44. public const int UshortPayloadLength = 126;
  45. /// <summary>
  46. /// if payload length is 127 when next 8 bytes will be the length
  47. /// </summary>
  48. public const int UlongPayloadLength = 127;
  49. /// <summary>
  50. /// Guid used for WebSocket Protocol
  51. /// </summary>
  52. public const string HandshakeGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  53. public static readonly int HandshakeGUIDLength = HandshakeGUID.Length;
  54. public static readonly byte[] HandshakeGUIDBytes = Encoding.ASCII.GetBytes(HandshakeGUID);
  55. /// <summary>
  56. /// Handshake messages will end with \r\n\r\n
  57. /// </summary>
  58. public static readonly byte[] endOfHandshake = new byte[4] { (byte)'\r', (byte)'\n', (byte)'\r', (byte)'\n' };
  59. }
  60. }