private static WebSocketMessageType GetMessageType(WebSocketProtocolComponent.BufferType bufferType)
{
switch (bufferType)
{
case WebSocketProtocolComponent.BufferType.Close:
return WebSocketMessageType.Close;
case WebSocketProtocolComponent.BufferType.BinaryFragment:
case WebSocketProtocolComponent.BufferType.BinaryMessage:
return WebSocketMessageType.Binary;
case WebSocketProtocolComponent.BufferType.UTF8Fragment:
case WebSocketProtocolComponent.BufferType.UTF8Message:
return WebSocketMessageType.Text;
default:
// This indicates a contract violation of the websocket protocol component,
// because we currently don't support any WebSocket extensions and would
// not accept a Websocket handshake requesting extensions
Debug.Assert(false,
string.Format(CultureInfo.InvariantCulture,
"The value of 'bufferType' ({0}) is invalid. Valid buffer types: {1}, {2}, {3}, {4}, {5}.",
bufferType,
WebSocketProtocolComponent.BufferType.Close,
WebSocketProtocolComponent.BufferType.BinaryFragment,
WebSocketProtocolComponent.BufferType.BinaryMessage,
WebSocketProtocolComponent.BufferType.UTF8Fragment,
WebSocketProtocolComponent.BufferType.UTF8Message));
throw new WebSocketException(WebSocketError.NativeError,
SR.Format(SR.net_WebSockets_InvalidBufferType,
bufferType,
WebSocketProtocolComponent.BufferType.Close,
WebSocketProtocolComponent.BufferType.BinaryFragment,
WebSocketProtocolComponent.BufferType.BinaryMessage,
WebSocketProtocolComponent.BufferType.UTF8Fragment,
WebSocketProtocolComponent.BufferType.UTF8Message));
}
}