[Modify] Move them to the extension methods
This commit is contained in:
		| @@ -508,6 +508,16 @@ namespace WebSocketSharp | ||||
|       return value.StartsWith (method.ToExtensionString ()); | ||||
|     } | ||||
|  | ||||
|     internal static bool IsControl (this byte opcode) | ||||
|     { | ||||
|       return opcode > 0x7 && opcode < 0x10; | ||||
|     } | ||||
|  | ||||
|     internal static bool IsData (this byte opcode) | ||||
|     { | ||||
|       return opcode == 0x1 || opcode == 0x2; | ||||
|     } | ||||
|  | ||||
|     internal static bool IsPortNumber (this int value) | ||||
|     { | ||||
|       return value > 0 && value < 65536; | ||||
| @@ -529,6 +539,11 @@ namespace WebSocketSharp | ||||
|              code == CloseStatusCode.TlsHandshakeFailure; | ||||
|     } | ||||
|  | ||||
|     internal static bool IsSupported (this byte opcode) | ||||
|     { | ||||
|       return Enum.IsDefined (typeof (Opcode), opcode); | ||||
|     } | ||||
|  | ||||
|     internal static bool IsText (this string value) | ||||
|     { | ||||
|       var len = value.Length; | ||||
|   | ||||
| @@ -377,33 +377,16 @@ namespace WebSocketSharp | ||||
|       return output.ToString (); | ||||
|     } | ||||
|  | ||||
|     private static bool isControl (byte opcode) | ||||
|     { | ||||
|       return opcode == (byte) Opcode.Close || | ||||
|              opcode == (byte) Opcode.Ping || | ||||
|              opcode == (byte) Opcode.Pong; | ||||
|     } | ||||
|  | ||||
|     private static bool isControl (Opcode opcode) | ||||
|     { | ||||
|       return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong; | ||||
|     } | ||||
|  | ||||
|     private static bool isData (byte opcode) | ||||
|     { | ||||
|       return opcode == (byte) Opcode.Text || opcode == (byte) Opcode.Binary; | ||||
|     } | ||||
|  | ||||
|     private static bool isData (Opcode opcode) | ||||
|     { | ||||
|       return opcode == Opcode.Text || opcode == Opcode.Binary; | ||||
|     } | ||||
|  | ||||
|     private static bool isSupported (byte opcode) | ||||
|     { | ||||
|       return Enum.IsDefined (typeof (Opcode), opcode); | ||||
|     } | ||||
|  | ||||
|     private static string print (WebSocketFrame frame) | ||||
|     { | ||||
|       // Payload Length | ||||
| @@ -478,13 +461,13 @@ Extended Payload Length: {7} | ||||
|       var payloadLen = (byte) (header[1] & 0x7f); | ||||
|  | ||||
|       // Check if valid header. | ||||
|       var err = !isSupported (opcode) | ||||
|       var err = !opcode.IsSupported () | ||||
|                 ? "An unsupported opcode." | ||||
|                 : isControl (opcode) && fin == Fin.More | ||||
|                 : opcode.IsControl () && fin == Fin.More | ||||
|                   ? "A control frame is fragmented." | ||||
|                   : isControl (opcode) && payloadLen > 125 | ||||
|                   : opcode.IsControl () && payloadLen > 125 | ||||
|                     ? "A control frame has a long payload length." | ||||
|                     : !isData (opcode) && rsv1 == Rsv.On | ||||
|                     : !opcode.IsData () && rsv1 == Rsv.On | ||||
|                       ? "A non data frame is compressed." | ||||
|                       : null; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user