Modified MessageEventArgs.cs

This commit is contained in:
sta 2013-05-03 13:29:52 +09:00
parent f38d98f966
commit 7b4e2472de
10 changed files with 11 additions and 24 deletions

Binary file not shown.

View File

@ -56,12 +56,14 @@ namespace WebSocketSharp {
if ((ulong)rawData.LongLength > PayloadData.MaxLength) if ((ulong)rawData.LongLength > PayloadData.MaxLength)
throw new WebSocketException(CloseStatusCode.TOO_BIG); throw new WebSocketException(CloseStatusCode.TOO_BIG);
init(opcode, rawData); _opcode = opcode;
_rawData = rawData;
} }
internal MessageEventArgs(Opcode opcode, PayloadData data) internal MessageEventArgs(Opcode opcode, PayloadData data)
{ {
init(opcode, data.ApplicationData); _opcode = opcode;
_rawData = data.ApplicationData;
} }
#endregion #endregion
@ -76,8 +78,13 @@ namespace WebSocketSharp {
/// </value> /// </value>
public string Data { public string Data {
get { get {
if (_data.IsNull()) _data = _data != null
_data = toString(_opcode, _rawData); ? _data
: _rawData.LongLength == 0
? String.Empty
: _opcode == Opcode.TEXT
? Encoding.UTF8.GetString(_rawData)
: _opcode.ToString();
return _data; return _data;
} }
@ -108,25 +115,5 @@ namespace WebSocketSharp {
} }
#endregion #endregion
#region Private Methods
private void init(Opcode opcode, byte[] rawData)
{
_opcode = opcode;
_rawData = rawData;
}
private static string toString(Opcode opcode, byte[] rawData)
{
if (rawData.LongLength == 0)
return String.Empty;
return opcode == Opcode.TEXT || opcode == Opcode.PING || opcode == Opcode.PONG
? Encoding.UTF8.GetString(rawData)
: opcode.ToString();
}
#endregion
} }
} }