-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Marfusios/Watfaq-master
Finalize binary message support
- Loading branch information
Showing
10 changed files
with
218 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Net.WebSockets; | ||
|
||
namespace Websocket.Client | ||
{ | ||
/// <summary> | ||
/// Received message, could be Text or Binary | ||
/// </summary> | ||
public class ResponseMessage | ||
{ | ||
private ResponseMessage(byte[] binary, string text, WebSocketMessageType messageType) | ||
{ | ||
Binary = binary; | ||
Text = text; | ||
MessageType = messageType; | ||
} | ||
|
||
/// <summary> | ||
/// Received text message (only if type = WebSocketMessageType.Text) | ||
/// </summary> | ||
public string Text { get; } | ||
|
||
/// <summary> | ||
/// Received text message (only if type = WebSocketMessageType.Binary) | ||
/// </summary> | ||
public byte[] Binary { get; } | ||
|
||
/// <summary> | ||
/// Current message type (Text or Binary) | ||
/// </summary> | ||
public WebSocketMessageType MessageType { get; } | ||
|
||
/// <summary> | ||
/// Return string info about the message | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
if (MessageType == WebSocketMessageType.Text) | ||
{ | ||
return Text; | ||
} | ||
|
||
return $"Type binary, length: {Binary?.Length}"; | ||
} | ||
|
||
/// <summary> | ||
/// Create text response message | ||
/// </summary> | ||
public static ResponseMessage TextMessage(string data) | ||
{ | ||
return new ResponseMessage(null, data, WebSocketMessageType.Text); | ||
} | ||
|
||
/// <summary> | ||
/// Create binary response message | ||
/// </summary> | ||
public static ResponseMessage BinaryMessage(byte[] data) | ||
{ | ||
return new ResponseMessage(data, null, WebSocketMessageType.Binary); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.