Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: sdk/lib/io/websocket_impl.dart

Issue 2260073002: RFC: Sending pre-encoded text over a web socket. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sdk/lib/io/websocket.dart ('K') | « sdk/lib/io/websocket.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/websocket_impl.dart
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart
index d593b58558962d77187f304a90e267c8c2674921..d255d7bde63863c1217b8d591d75d47eeee2c175 100644
--- a/sdk/lib/io/websocket_impl.dart
+++ b/sdk/lib/io/websocket_impl.dart
@@ -36,6 +36,11 @@ class _WebSocketOpcode {
static const int RESERVED_F = 15;
}
+class _EncodedString {
+ final List<int> bytes;
+ _EncodedString(this.bytes);
+}
+
/**
* Stores the header and integer value derived from negotiation of
* client_max_window_bits and server_max_window_bits. headerValue will be
@@ -670,13 +675,14 @@ class _WebSocketOutgoingTransformer
if (message is String) {
opcode = _WebSocketOpcode.TEXT;
data = UTF8.encode(message);
+ } else if (message is List<int>) {
+ opcode = _WebSocketOpcode.BINARY;
+ data = message;
+ } else if (message is _EncodedString) {
+ opcode = _WebSocketOpcode.TEXT;
+ data = message.bytes;
} else {
- if (message is List<int>) {
- opcode = _WebSocketOpcode.BINARY;
- data = message;
- } else {
- throw new ArgumentError(message);
- }
+ throw new ArgumentError(message);
}
if (_deflateHelper != null) {
@@ -1175,6 +1181,22 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
int get closeCode => _closeCode;
String get closeReason => _closeReason;
+ void sendMessage(WebSocketMessageType type, List<int> bytes) {
+ if (bytes is! List<int>) {
+ throw new ArgumentError(bytes);
+ }
+ switch (type) {
+ case WebSocketMessageType.BINARY:
+ add(bytes);
+ break;
+ case WebSocketMessageType.TEXT:
+ add(new _EncodedString(bytes));
+ break;
+ default:
+ throw new ArgumentError(type);
+ }
+ }
+
void add(data) { _sink.add(data); }
void addError(error, [StackTrace stackTrace]) {
_sink.addError(error, stackTrace);
« sdk/lib/io/websocket.dart ('K') | « sdk/lib/io/websocket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698