Modified Opcode enum values to PascalCase values

This commit is contained in:
sta 2014-03-06 17:07:30 +09:00
parent da44141e02
commit 0a9010df86
8 changed files with 92 additions and 86 deletions

View File

@ -85,11 +85,11 @@ namespace Example1
{ {
switch (e.Type) switch (e.Type)
{ {
case Opcode.TEXT: case Opcode.Text:
var msg = parseTextMessage(e.Data); var msg = parseTextMessage(e.Data);
_msgQ.Enqueue(msg); _msgQ.Enqueue(msg);
break; break;
case Opcode.BINARY: case Opcode.Binary:
var audioMsg = parseAudioMessage(e.RawData); var audioMsg = parseAudioMessage(e.RawData);
if (audioMsg.user_id == _user_id) goto default; if (audioMsg.user_id == _user_id) goto default;
if (_audioBox.ContainsKey(audioMsg.user_id)) if (_audioBox.ContainsKey(audioMsg.user_id))

View File

@ -126,19 +126,19 @@ ws.OnMessage += (sender, e) => {
`e` has passed as a `WebSocketSharp.MessageEventArgs`. `e` has passed as a `WebSocketSharp.MessageEventArgs`.
`e.Type` property returns either `WebSocketSharp.Opcode.TEXT` or `WebSocketSharp.Opcode.BINARY` that represents the type of the received message. So by checking it, you determine which item you should use. `e.Type` property returns either `WebSocketSharp.Opcode.Text` or `WebSocketSharp.Opcode.Binary` that represents the type of the received message. So by checking it, you determine which item you should use.
If `e.Type` is `Opcode.TEXT`, you should use `e.Data` property (returns a `string`) that represents the received **Text** message. If `e.Type` is `Opcode.Text`, you should use `e.Data` property (returns a `string`) that represents the received **Text** message.
Or if `e.Type` is `Opcode.BINARY`, you should use `e.RawData` property (returns a `byte []`) that represents the received **Binary** message. Or if `e.Type` is `Opcode.Binary`, you should use `e.RawData` property (returns a `byte []`) that represents the received **Binary** message.
```cs ```cs
if (e.Type == Opcode.TEXT) { if (e.Type == Opcode.Text) {
// Do something with e.Data // Do something with e.Data
return; return;
} }
if (e.Type == Opcode.BINARY) { if (e.Type == Opcode.Binary) {
// Do something with e.RawData // Do something with e.RawData
return; return;
} }

View File

@ -117,7 +117,7 @@ namespace WebSocketSharp
{ {
return data.LongLength == 0 return data.LongLength == 0
? String.Empty ? String.Empty
: opcode == Opcode.TEXT : opcode == Opcode.Text
? Encoding.UTF8.GetString (data) ? Encoding.UTF8.GetString (data)
: opcode.ToString (); : opcode.ToString ();
} }

View File

@ -4,7 +4,7 @@
* *
* The MIT License * The MIT License
* *
* Copyright (c) 2012-2013 sta.blockhead * Copyright (c) 2012-2014 sta.blockhead
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -28,40 +28,46 @@
using System; using System;
namespace WebSocketSharp { namespace WebSocketSharp
{
/// <summary> /// <summary>
/// Contains the values of the opcodes that denotes the frame type of the WebSocket frame. /// Contains the values of the opcode that indicates the type of a WebSocket frame.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The <b>Opcode</b> enumeration contains the values of the opcodes defined in /// The values of the opcode are defined in
/// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">RFC 6455</see> for the WebSocket protocol. /// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
/// </remarks> /// </remarks>
public enum Opcode : byte public enum Opcode : byte
{ {
/// <summary> /// <summary>
/// Equivalent to numeric value 0. Indicates a continuation frame. /// Equivalent to numeric value 0.
/// Indicates a continuation frame.
/// </summary> /// </summary>
CONT = 0x0, Cont = 0x0,
/// <summary> /// <summary>
/// Equivalent to numeric value 1. Indicates a text frame. /// Equivalent to numeric value 1.
/// Indicates a text frame.
/// </summary> /// </summary>
TEXT = 0x1, Text = 0x1,
/// <summary> /// <summary>
/// Equivalent to numeric value 2. Indicates a binary frame. /// Equivalent to numeric value 2.
/// Indicates a binary frame.
/// </summary> /// </summary>
BINARY = 0x2, Binary = 0x2,
/// <summary> /// <summary>
/// Equivalent to numeric value 8. Indicates a connection close frame. /// Equivalent to numeric value 8.
/// Indicates a connection close frame.
/// </summary> /// </summary>
CLOSE = 0x8, Close = 0x8,
/// <summary> /// <summary>
/// Equivalent to numeric value 9. Indicates a ping frame. /// Equivalent to numeric value 9.
/// Indicates a ping frame.
/// </summary> /// </summary>
PING = 0x9, Ping = 0x9,
/// <summary> /// <summary>
/// Equivalent to numeric value 10. Indicates a pong frame. /// Equivalent to numeric value 10.
/// Indicates a pong frame.
/// </summary> /// </summary>
PONG = 0xa Pong = 0xa
} }
} }

View File

@ -364,9 +364,9 @@ namespace WebSocketSharp.Server
} }
if (data.LongLength <= WebSocket.FragmentLength) if (data.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, null); broadcast (Opcode.Binary, data, null);
else else
broadcast (Opcode.BINARY, new MemoryStream (data), null); broadcast (Opcode.Binary, new MemoryStream (data), null);
} }
/// <summary> /// <summary>
@ -386,9 +386,9 @@ namespace WebSocketSharp.Server
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= WebSocket.FragmentLength) if (rawData.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.TEXT, rawData, null); broadcast (Opcode.Text, rawData, null);
else else
broadcast (Opcode.TEXT, new MemoryStream (rawData), null); broadcast (Opcode.Text, new MemoryStream (rawData), null);
} }
/// <summary> /// <summary>
@ -414,9 +414,9 @@ namespace WebSocketSharp.Server
} }
if (data.LongLength <= WebSocket.FragmentLength) if (data.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.BINARY, data, completed); broadcastAsync (Opcode.Binary, data, completed);
else else
broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); broadcastAsync (Opcode.Binary, new MemoryStream (data), completed);
} }
/// <summary> /// <summary>
@ -443,9 +443,9 @@ namespace WebSocketSharp.Server
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= WebSocket.FragmentLength) if (rawData.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.TEXT, rawData, completed); broadcastAsync (Opcode.Text, rawData, completed);
else else
broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed);
} }
/// <summary> /// <summary>
@ -493,9 +493,9 @@ namespace WebSocketSharp.Server
len)); len));
if (len <= WebSocket.FragmentLength) if (len <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, completed); broadcast (Opcode.Binary, data, completed);
else else
broadcast (Opcode.BINARY, new MemoryStream (data), completed); broadcast (Opcode.Binary, new MemoryStream (data), completed);
}, },
ex => _logger.Fatal (ex.ToString ())); ex => _logger.Fatal (ex.ToString ()));
} }

View File

@ -406,9 +406,9 @@ namespace WebSocketSharp.Server
} }
if (data.LongLength <= WebSocket.FragmentLength) if (data.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, null); broadcast (Opcode.Binary, data, null);
else else
broadcast (Opcode.BINARY, new MemoryStream (data), null); broadcast (Opcode.Binary, new MemoryStream (data), null);
} }
/// <summary> /// <summary>
@ -427,9 +427,9 @@ namespace WebSocketSharp.Server
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= WebSocket.FragmentLength) if (rawData.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.TEXT, rawData, null); broadcast (Opcode.Text, rawData, null);
else else
broadcast (Opcode.TEXT, new MemoryStream (rawData), null); broadcast (Opcode.Text, new MemoryStream (rawData), null);
} }
/// <summary> /// <summary>
@ -455,9 +455,9 @@ namespace WebSocketSharp.Server
} }
if (data.LongLength <= WebSocket.FragmentLength) if (data.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.BINARY, data, completed); broadcastAsync (Opcode.Binary, data, completed);
else else
broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); broadcastAsync (Opcode.Binary, new MemoryStream (data), completed);
} }
/// <summary> /// <summary>
@ -484,9 +484,9 @@ namespace WebSocketSharp.Server
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= WebSocket.FragmentLength) if (rawData.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.TEXT, rawData, completed); broadcastAsync (Opcode.Text, rawData, completed);
else else
broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed);
} }
/// <summary> /// <summary>
@ -534,9 +534,9 @@ namespace WebSocketSharp.Server
len)); len));
if (len <= WebSocket.FragmentLength) if (len <= WebSocket.FragmentLength)
broadcast (Opcode.BINARY, data, completed); broadcast (Opcode.Binary, data, completed);
else else
broadcast (Opcode.BINARY, new MemoryStream (data), completed); broadcast (Opcode.Binary, new MemoryStream (data), completed);
}, },
ex => _logger.Fatal (ex.ToString ())); ex => _logger.Fatal (ex.ToString ()));
} }

View File

@ -1186,7 +1186,7 @@ namespace WebSocketSharp
// Mid // Mid
for (long i = 0; i < times; i++) { for (long i = 0; i < times; i++) {
if (stream.Read (buffer, 0, FragmentLength) != FragmentLength || if (stream.Read (buffer, 0, FragmentLength) != FragmentLength ||
!send (WsFrame.CreateFrame (Fin.More, Opcode.CONT, mask, buffer, compressed))) !send (WsFrame.CreateFrame (Fin.More, Opcode.Cont, mask, buffer, compressed)))
return false; return false;
} }
@ -1196,7 +1196,7 @@ namespace WebSocketSharp
buffer = new byte [tmpLen = rem]; buffer = new byte [tmpLen = rem];
return stream.Read (buffer, 0, tmpLen) == tmpLen && return stream.Read (buffer, 0, tmpLen) == tmpLen &&
send (WsFrame.CreateFrame (Fin.Final, Opcode.CONT, mask, buffer, compressed)); send (WsFrame.CreateFrame (Fin.Final, Opcode.Cont, mask, buffer, compressed));
} }
// As client // As client
@ -1849,10 +1849,10 @@ namespace WebSocketSharp
var len = data.LongLength; var len = data.LongLength;
if (len <= FragmentLength) if (len <= FragmentLength)
send ( send (
Opcode.BINARY, Opcode.Binary,
len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data); len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data);
else else
send (Opcode.BINARY, new MemoryStream (data)); send (Opcode.Binary, new MemoryStream (data));
} }
/// <summary> /// <summary>
@ -1872,7 +1872,7 @@ namespace WebSocketSharp
return; return;
} }
send (Opcode.BINARY, file.OpenRead ()); send (Opcode.Binary, file.OpenRead ());
} }
/// <summary> /// <summary>
@ -1893,9 +1893,9 @@ namespace WebSocketSharp
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= FragmentLength) if (rawData.LongLength <= FragmentLength)
send (Opcode.TEXT, rawData); send (Opcode.Text, rawData);
else else
send (Opcode.TEXT, new MemoryStream (rawData)); send (Opcode.Text, new MemoryStream (rawData));
} }
/// <summary> /// <summary>
@ -1925,11 +1925,11 @@ namespace WebSocketSharp
var len = data.LongLength; var len = data.LongLength;
if (len <= FragmentLength) if (len <= FragmentLength)
sendAsync ( sendAsync (
Opcode.BINARY, Opcode.Binary,
len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data, len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data,
completed); completed);
else else
sendAsync (Opcode.BINARY, new MemoryStream (data), completed); sendAsync (Opcode.Binary, new MemoryStream (data), completed);
} }
/// <summary> /// <summary>
@ -1957,7 +1957,7 @@ namespace WebSocketSharp
return; return;
} }
sendAsync (Opcode.BINARY, file.OpenRead (), completed); sendAsync (Opcode.Binary, file.OpenRead (), completed);
} }
/// <summary> /// <summary>
@ -1986,9 +1986,9 @@ namespace WebSocketSharp
var rawData = Encoding.UTF8.GetBytes (data); var rawData = Encoding.UTF8.GetBytes (data);
if (rawData.LongLength <= FragmentLength) if (rawData.LongLength <= FragmentLength)
sendAsync (Opcode.TEXT, rawData, completed); sendAsync (Opcode.Text, rawData, completed);
else else
sendAsync (Opcode.TEXT, new MemoryStream (rawData), completed); sendAsync (Opcode.Text, new MemoryStream (rawData), completed);
} }
/// <summary> /// <summary>
@ -2042,8 +2042,8 @@ namespace WebSocketSharp
len)); len));
var sent = len <= FragmentLength var sent = len <= FragmentLength
? send (Opcode.BINARY, data) ? send (Opcode.Binary, data)
: send (Opcode.BINARY, new MemoryStream (data)); : send (Opcode.Binary, new MemoryStream (data));
if (completed != null) if (completed != null)
completed (sent); completed (sent);

View File

@ -128,13 +128,13 @@ namespace WebSocketSharp
internal bool IsBinary { internal bool IsBinary {
get { get {
return Opcode == Opcode.BINARY; return Opcode == Opcode.Binary;
} }
} }
internal bool IsClose { internal bool IsClose {
get { get {
return Opcode == Opcode.CLOSE; return Opcode == Opcode.Close;
} }
} }
@ -146,21 +146,21 @@ namespace WebSocketSharp
internal bool IsContinuation { internal bool IsContinuation {
get { get {
return Opcode == Opcode.CONT; return Opcode == Opcode.Cont;
} }
} }
internal bool IsControl { internal bool IsControl {
get { get {
var opcode = Opcode; var opcode = Opcode;
return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG; return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong;
} }
} }
internal bool IsData { internal bool IsData {
get { get {
var opcode = Opcode; var opcode = Opcode;
return opcode == Opcode.BINARY || opcode == Opcode.TEXT; return opcode == Opcode.Binary || opcode == Opcode.Text;
} }
} }
@ -172,7 +172,7 @@ namespace WebSocketSharp
internal bool IsFragmented { internal bool IsFragmented {
get { get {
return Fin == Fin.More || Opcode == Opcode.CONT; return Fin == Fin.More || Opcode == Opcode.Cont;
} }
} }
@ -185,25 +185,25 @@ namespace WebSocketSharp
internal bool IsPerMessageCompressed { internal bool IsPerMessageCompressed {
get { get {
var opcode = Opcode; var opcode = Opcode;
return (opcode == Opcode.BINARY || opcode == Opcode.TEXT) && Rsv1 == Rsv.On; return (opcode == Opcode.Binary || opcode == Opcode.Text) && Rsv1 == Rsv.On;
} }
} }
internal bool IsPing { internal bool IsPing {
get { get {
return Opcode == Opcode.PING; return Opcode == Opcode.Ping;
} }
} }
internal bool IsPong { internal bool IsPong {
get { get {
return Opcode == Opcode.PONG; return Opcode == Opcode.Pong;
} }
} }
internal bool IsText { internal bool IsText {
get { get {
return Opcode == Opcode.TEXT; return Opcode == Opcode.Text;
} }
} }
@ -322,27 +322,27 @@ namespace WebSocketSharp
private static bool isBinary (Opcode opcode) private static bool isBinary (Opcode opcode)
{ {
return opcode == Opcode.BINARY; return opcode == Opcode.Binary;
} }
private static bool isClose (Opcode opcode) private static bool isClose (Opcode opcode)
{ {
return opcode == Opcode.CLOSE; return opcode == Opcode.Close;
} }
private static bool isContinuation (Opcode opcode) private static bool isContinuation (Opcode opcode)
{ {
return opcode == Opcode.CONT; return opcode == Opcode.Cont;
} }
private static bool isControl (Opcode opcode) private static bool isControl (Opcode opcode)
{ {
return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG; return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong;
} }
private static bool isData (Opcode opcode) private static bool isData (Opcode opcode)
{ {
return opcode == Opcode.TEXT || opcode == Opcode.BINARY; return opcode == Opcode.Text || opcode == Opcode.Binary;
} }
private static bool isFinal (Fin fin) private static bool isFinal (Fin fin)
@ -357,17 +357,17 @@ namespace WebSocketSharp
private static bool isPing (Opcode opcode) private static bool isPing (Opcode opcode)
{ {
return opcode == Opcode.PING; return opcode == Opcode.Ping;
} }
private static bool isPong (Opcode opcode) private static bool isPong (Opcode opcode)
{ {
return opcode == Opcode.PONG; return opcode == Opcode.Pong;
} }
private static bool isText (Opcode opcode) private static bool isText (Opcode opcode)
{ {
return opcode == Opcode.TEXT; return opcode == Opcode.Text;
} }
private static WsFrame parse (byte [] header, Stream stream, bool unmask) private static WsFrame parse (byte [] header, Stream stream, bool unmask)
@ -556,12 +556,12 @@ Extended Payload Len: {7}
internal static WsFrame CreateCloseFrame (Mask mask, PayloadData payload) internal static WsFrame CreateCloseFrame (Mask mask, PayloadData payload)
{ {
return new WsFrame (Opcode.CLOSE, mask, payload); return new WsFrame (Opcode.Close, mask, payload);
} }
internal static WsFrame CreatePongFrame (Mask mask, PayloadData payload) internal static WsFrame CreatePongFrame (Mask mask, PayloadData payload)
{ {
return new WsFrame (Opcode.PONG, mask, payload); return new WsFrame (Opcode.Pong, mask, payload);
} }
#endregion #endregion
@ -570,12 +570,12 @@ Extended Payload Len: {7}
public static WsFrame CreateCloseFrame (Mask mask, byte [] data) public static WsFrame CreateCloseFrame (Mask mask, byte [] data)
{ {
return new WsFrame (Opcode.CLOSE, mask, new PayloadData (data)); return new WsFrame (Opcode.Close, mask, new PayloadData (data));
} }
public static WsFrame CreateCloseFrame (Mask mask, CloseStatusCode code, string reason) public static WsFrame CreateCloseFrame (Mask mask, CloseStatusCode code, string reason)
{ {
return new WsFrame (Opcode.CLOSE, mask, new PayloadData (((ushort) code).Append (reason))); return new WsFrame (Opcode.Close, mask, new PayloadData (((ushort) code).Append (reason)));
} }
public static WsFrame CreateFrame ( public static WsFrame CreateFrame (
@ -586,12 +586,12 @@ Extended Payload Len: {7}
public static WsFrame CreatePingFrame (Mask mask) public static WsFrame CreatePingFrame (Mask mask)
{ {
return new WsFrame (Opcode.PING, mask, new PayloadData ()); return new WsFrame (Opcode.Ping, mask, new PayloadData ());
} }
public static WsFrame CreatePingFrame (Mask mask, byte [] data) public static WsFrame CreatePingFrame (Mask mask, byte [] data)
{ {
return new WsFrame (Opcode.PING, mask, new PayloadData (data)); return new WsFrame (Opcode.Ping, mask, new PayloadData (data));
} }
public IEnumerator<byte> GetEnumerator () public IEnumerator<byte> GetEnumerator ()