Modified Opcode enum values to PascalCase values
This commit is contained in:
parent
da44141e02
commit
0a9010df86
@ -85,11 +85,11 @@ namespace Example1
|
||||
{
|
||||
switch (e.Type)
|
||||
{
|
||||
case Opcode.TEXT:
|
||||
case Opcode.Text:
|
||||
var msg = parseTextMessage(e.Data);
|
||||
_msgQ.Enqueue(msg);
|
||||
break;
|
||||
case Opcode.BINARY:
|
||||
case Opcode.Binary:
|
||||
var audioMsg = parseAudioMessage(e.RawData);
|
||||
if (audioMsg.user_id == _user_id) goto default;
|
||||
if (_audioBox.ContainsKey(audioMsg.user_id))
|
||||
|
10
README.md
10
README.md
@ -126,19 +126,19 @@ ws.OnMessage += (sender, e) => {
|
||||
|
||||
`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
|
||||
if (e.Type == Opcode.TEXT) {
|
||||
if (e.Type == Opcode.Text) {
|
||||
// Do something with e.Data
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Type == Opcode.BINARY) {
|
||||
if (e.Type == Opcode.Binary) {
|
||||
// Do something with e.RawData
|
||||
return;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ namespace WebSocketSharp
|
||||
{
|
||||
return data.LongLength == 0
|
||||
? String.Empty
|
||||
: opcode == Opcode.TEXT
|
||||
: opcode == Opcode.Text
|
||||
? Encoding.UTF8.GetString (data)
|
||||
: opcode.ToString ();
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -15,7 +15,7 @@
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@ -28,40 +28,46 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace WebSocketSharp {
|
||||
|
||||
namespace WebSocketSharp
|
||||
{
|
||||
/// <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>
|
||||
/// <remarks>
|
||||
/// The <b>Opcode</b> enumeration contains the values of the opcodes defined in
|
||||
/// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">RFC 6455</see> for the WebSocket protocol.
|
||||
/// The values of the opcode are defined in
|
||||
/// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
|
||||
/// </remarks>
|
||||
public enum Opcode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 0. Indicates a continuation frame.
|
||||
/// Equivalent to numeric value 0.
|
||||
/// Indicates a continuation frame.
|
||||
/// </summary>
|
||||
CONT = 0x0,
|
||||
Cont = 0x0,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 1. Indicates a text frame.
|
||||
/// Equivalent to numeric value 1.
|
||||
/// Indicates a text frame.
|
||||
/// </summary>
|
||||
TEXT = 0x1,
|
||||
Text = 0x1,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 2. Indicates a binary frame.
|
||||
/// Equivalent to numeric value 2.
|
||||
/// Indicates a binary frame.
|
||||
/// </summary>
|
||||
BINARY = 0x2,
|
||||
Binary = 0x2,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 8. Indicates a connection close frame.
|
||||
/// Equivalent to numeric value 8.
|
||||
/// Indicates a connection close frame.
|
||||
/// </summary>
|
||||
CLOSE = 0x8,
|
||||
Close = 0x8,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 9. Indicates a ping frame.
|
||||
/// Equivalent to numeric value 9.
|
||||
/// Indicates a ping frame.
|
||||
/// </summary>
|
||||
PING = 0x9,
|
||||
Ping = 0x9,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 10. Indicates a pong frame.
|
||||
/// Equivalent to numeric value 10.
|
||||
/// Indicates a pong frame.
|
||||
/// </summary>
|
||||
PONG = 0xa
|
||||
Pong = 0xa
|
||||
}
|
||||
}
|
||||
|
@ -364,9 +364,9 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
if (data.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.BINARY, data, null);
|
||||
broadcast (Opcode.Binary, data, null);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), null);
|
||||
broadcast (Opcode.Binary, new MemoryStream (data), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -386,9 +386,9 @@ namespace WebSocketSharp.Server
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.TEXT, rawData, null);
|
||||
broadcast (Opcode.Text, rawData, null);
|
||||
else
|
||||
broadcast (Opcode.TEXT, new MemoryStream (rawData), null);
|
||||
broadcast (Opcode.Text, new MemoryStream (rawData), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -414,9 +414,9 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
if (data.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.BINARY, data, completed);
|
||||
broadcastAsync (Opcode.Binary, data, completed);
|
||||
else
|
||||
broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
broadcastAsync (Opcode.Binary, new MemoryStream (data), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -443,9 +443,9 @@ namespace WebSocketSharp.Server
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.TEXT, rawData, completed);
|
||||
broadcastAsync (Opcode.Text, rawData, completed);
|
||||
else
|
||||
broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed);
|
||||
broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -493,9 +493,9 @@ namespace WebSocketSharp.Server
|
||||
len));
|
||||
|
||||
if (len <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.BINARY, data, completed);
|
||||
broadcast (Opcode.Binary, data, completed);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
broadcast (Opcode.Binary, new MemoryStream (data), completed);
|
||||
},
|
||||
ex => _logger.Fatal (ex.ToString ()));
|
||||
}
|
||||
|
@ -406,9 +406,9 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
if (data.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.BINARY, data, null);
|
||||
broadcast (Opcode.Binary, data, null);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), null);
|
||||
broadcast (Opcode.Binary, new MemoryStream (data), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -427,9 +427,9 @@ namespace WebSocketSharp.Server
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.TEXT, rawData, null);
|
||||
broadcast (Opcode.Text, rawData, null);
|
||||
else
|
||||
broadcast (Opcode.TEXT, new MemoryStream (rawData), null);
|
||||
broadcast (Opcode.Text, new MemoryStream (rawData), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -455,9 +455,9 @@ namespace WebSocketSharp.Server
|
||||
}
|
||||
|
||||
if (data.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.BINARY, data, completed);
|
||||
broadcastAsync (Opcode.Binary, data, completed);
|
||||
else
|
||||
broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
broadcastAsync (Opcode.Binary, new MemoryStream (data), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -484,9 +484,9 @@ namespace WebSocketSharp.Server
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= WebSocket.FragmentLength)
|
||||
broadcastAsync (Opcode.TEXT, rawData, completed);
|
||||
broadcastAsync (Opcode.Text, rawData, completed);
|
||||
else
|
||||
broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed);
|
||||
broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -534,9 +534,9 @@ namespace WebSocketSharp.Server
|
||||
len));
|
||||
|
||||
if (len <= WebSocket.FragmentLength)
|
||||
broadcast (Opcode.BINARY, data, completed);
|
||||
broadcast (Opcode.Binary, data, completed);
|
||||
else
|
||||
broadcast (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
broadcast (Opcode.Binary, new MemoryStream (data), completed);
|
||||
},
|
||||
ex => _logger.Fatal (ex.ToString ()));
|
||||
}
|
||||
|
@ -1186,7 +1186,7 @@ namespace WebSocketSharp
|
||||
// Mid
|
||||
for (long i = 0; i < times; i++) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1196,7 +1196,7 @@ namespace WebSocketSharp
|
||||
buffer = new byte [tmpLen = rem];
|
||||
|
||||
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
|
||||
@ -1849,10 +1849,10 @@ namespace WebSocketSharp
|
||||
var len = data.LongLength;
|
||||
if (len <= FragmentLength)
|
||||
send (
|
||||
Opcode.BINARY,
|
||||
Opcode.Binary,
|
||||
len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data);
|
||||
else
|
||||
send (Opcode.BINARY, new MemoryStream (data));
|
||||
send (Opcode.Binary, new MemoryStream (data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1872,7 +1872,7 @@ namespace WebSocketSharp
|
||||
return;
|
||||
}
|
||||
|
||||
send (Opcode.BINARY, file.OpenRead ());
|
||||
send (Opcode.Binary, file.OpenRead ());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1893,9 +1893,9 @@ namespace WebSocketSharp
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= FragmentLength)
|
||||
send (Opcode.TEXT, rawData);
|
||||
send (Opcode.Text, rawData);
|
||||
else
|
||||
send (Opcode.TEXT, new MemoryStream (rawData));
|
||||
send (Opcode.Text, new MemoryStream (rawData));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1925,11 +1925,11 @@ namespace WebSocketSharp
|
||||
var len = data.LongLength;
|
||||
if (len <= FragmentLength)
|
||||
sendAsync (
|
||||
Opcode.BINARY,
|
||||
Opcode.Binary,
|
||||
len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data,
|
||||
completed);
|
||||
else
|
||||
sendAsync (Opcode.BINARY, new MemoryStream (data), completed);
|
||||
sendAsync (Opcode.Binary, new MemoryStream (data), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1957,7 +1957,7 @@ namespace WebSocketSharp
|
||||
return;
|
||||
}
|
||||
|
||||
sendAsync (Opcode.BINARY, file.OpenRead (), completed);
|
||||
sendAsync (Opcode.Binary, file.OpenRead (), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1986,9 +1986,9 @@ namespace WebSocketSharp
|
||||
|
||||
var rawData = Encoding.UTF8.GetBytes (data);
|
||||
if (rawData.LongLength <= FragmentLength)
|
||||
sendAsync (Opcode.TEXT, rawData, completed);
|
||||
sendAsync (Opcode.Text, rawData, completed);
|
||||
else
|
||||
sendAsync (Opcode.TEXT, new MemoryStream (rawData), completed);
|
||||
sendAsync (Opcode.Text, new MemoryStream (rawData), completed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -2042,8 +2042,8 @@ namespace WebSocketSharp
|
||||
len));
|
||||
|
||||
var sent = len <= FragmentLength
|
||||
? send (Opcode.BINARY, data)
|
||||
: send (Opcode.BINARY, new MemoryStream (data));
|
||||
? send (Opcode.Binary, data)
|
||||
: send (Opcode.Binary, new MemoryStream (data));
|
||||
|
||||
if (completed != null)
|
||||
completed (sent);
|
||||
|
@ -128,13 +128,13 @@ namespace WebSocketSharp
|
||||
|
||||
internal bool IsBinary {
|
||||
get {
|
||||
return Opcode == Opcode.BINARY;
|
||||
return Opcode == Opcode.Binary;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsClose {
|
||||
get {
|
||||
return Opcode == Opcode.CLOSE;
|
||||
return Opcode == Opcode.Close;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,21 +146,21 @@ namespace WebSocketSharp
|
||||
|
||||
internal bool IsContinuation {
|
||||
get {
|
||||
return Opcode == Opcode.CONT;
|
||||
return Opcode == Opcode.Cont;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsControl {
|
||||
get {
|
||||
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 {
|
||||
get {
|
||||
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 {
|
||||
get {
|
||||
return Fin == Fin.More || Opcode == Opcode.CONT;
|
||||
return Fin == Fin.More || Opcode == Opcode.Cont;
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,25 +185,25 @@ namespace WebSocketSharp
|
||||
internal bool IsPerMessageCompressed {
|
||||
get {
|
||||
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 {
|
||||
get {
|
||||
return Opcode == Opcode.PING;
|
||||
return Opcode == Opcode.Ping;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsPong {
|
||||
get {
|
||||
return Opcode == Opcode.PONG;
|
||||
return Opcode == Opcode.Pong;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsText {
|
||||
get {
|
||||
return Opcode == Opcode.TEXT;
|
||||
return Opcode == Opcode.Text;
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,27 +322,27 @@ namespace WebSocketSharp
|
||||
|
||||
private static bool isBinary (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.BINARY;
|
||||
return opcode == Opcode.Binary;
|
||||
}
|
||||
|
||||
private static bool isClose (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.CLOSE;
|
||||
return opcode == Opcode.Close;
|
||||
}
|
||||
|
||||
private static bool isContinuation (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.CONT;
|
||||
return opcode == Opcode.Cont;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return opcode == Opcode.TEXT || opcode == Opcode.BINARY;
|
||||
return opcode == Opcode.Text || opcode == Opcode.Binary;
|
||||
}
|
||||
|
||||
private static bool isFinal (Fin fin)
|
||||
@ -357,17 +357,17 @@ namespace WebSocketSharp
|
||||
|
||||
private static bool isPing (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.PING;
|
||||
return opcode == Opcode.Ping;
|
||||
}
|
||||
|
||||
private static bool isPong (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.PONG;
|
||||
return opcode == Opcode.Pong;
|
||||
}
|
||||
|
||||
private static bool isText (Opcode opcode)
|
||||
{
|
||||
return opcode == Opcode.TEXT;
|
||||
return opcode == Opcode.Text;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return new WsFrame (Opcode.CLOSE, mask, payload);
|
||||
return new WsFrame (Opcode.Close, mask, payload);
|
||||
}
|
||||
|
||||
internal static WsFrame CreatePongFrame (Mask mask, PayloadData payload)
|
||||
{
|
||||
return new WsFrame (Opcode.PONG, mask, payload);
|
||||
return new WsFrame (Opcode.Pong, mask, payload);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -570,12 +570,12 @@ Extended Payload Len: {7}
|
||||
|
||||
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)
|
||||
{
|
||||
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 (
|
||||
@ -586,12 +586,12 @@ Extended Payload Len: {7}
|
||||
|
||||
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)
|
||||
{
|
||||
return new WsFrame (Opcode.PING, mask, new PayloadData (data));
|
||||
return new WsFrame (Opcode.Ping, mask, new PayloadData (data));
|
||||
}
|
||||
|
||||
public IEnumerator<byte> GetEnumerator ()
|
||||
|
Loading…
Reference in New Issue
Block a user