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

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: error message 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
« no previous file with comments | « 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..17520a1ecfb72bfef75a7ebce21403d8040b1871 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) {
@@ -1176,6 +1182,12 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
String get closeReason => _closeReason;
void add(data) { _sink.add(data); }
+ void addUtf8Text(List<int> bytes) {
+ if (bytes is! List<int>) {
+ throw new ArgumentError(bytes, "bytes", "Is not a list of bytes");
+ }
+ _sink.add(new _EncodedString(bytes));
+ }
void addError(error, [StackTrace stackTrace]) {
_sink.addError(error, stackTrace);
}
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698