Constants.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /// bytes for long length
  32. /// </summary>
  33. public const int LongLength = 8;
  34. /// <summary>
  35. /// Message mask is always 4 bytes
  36. /// </summary>
  37. public const int MaskSize = 4;
  38. /// <summary>
  39. /// Max size of a message for length to be 1 byte long
  40. /// <para>
  41. /// payload length between 0-125
  42. /// </para>
  43. /// </summary>
  44. public const int BytePayloadLength = 125;
  45. /// <summary>
  46. /// if payload length is 126 when next 2 bytes will be the length
  47. /// </summary>
  48. public const int UshortPayloadLength = 126;
  49. /// <summary>
  50. /// if payload length is 127 when next 8 bytes will be the length
  51. /// </summary>
  52. public const int UlongPayloadLength = 127;
  53. /// <summary>
  54. /// Guid used for WebSocket Protocol
  55. /// </summary>
  56. public const string HandshakeGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  57. public static readonly int HandshakeGUIDLength = HandshakeGUID.Length;
  58. public static readonly byte[] HandshakeGUIDBytes = Encoding.ASCII.GetBytes(HandshakeGUID);
  59. /// <summary>
  60. /// Handshake messages will end with \r\n\r\n
  61. /// </summary>
  62. public static readonly byte[] endOfHandshake = new byte[4] { (byte)'\r', (byte)'\n', (byte)'\r', (byte)'\n' };
  63. }
  64. }