Skip to content

Commit

Permalink
Declare a return value of Uint8List in BytesBuilder methods
Browse files Browse the repository at this point in the history
Part of the rollout of dart-lang/sdk#36900
  • Loading branch information
tvolkert committed May 20, 2019
1 parent aaa5472 commit 4cf0ace
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.13

* Update `BytesBuilder.takeBytes()` and `BytesBuilder.toBytes()`
to declare a return value of `Uint8List` rather than `List<int>`.

## 1.0.12

* Allow `stream_channel` version 2.x
Expand Down
12 changes: 6 additions & 6 deletions lib/src/copy/bytes_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ abstract class BytesBuilder {
///
/// The list returned is a view of the internal buffer, limited to the
/// [length].
List<int> takeBytes();
Uint8List takeBytes();

/// Returns a copy of the current contents of the builder.
///
/// Leaves the contents of the builder intact.
List<int> toBytes();
Uint8List toBytes();

/// The number of bytes in the builder.
int get length;
Expand Down Expand Up @@ -124,14 +124,14 @@ class _CopyingBytesBuilder implements BytesBuilder {
_buffer = newBuffer;
}

List<int> takeBytes() {
Uint8List takeBytes() {
if (_length == 0) return _emptyList;
var buffer = Uint8List.view(_buffer.buffer, 0, _length);
clear();
return buffer;
}

List<int> toBytes() {
Uint8List toBytes() {
if (_length == 0) return _emptyList;
return Uint8List.fromList(Uint8List.view(_buffer.buffer, 0, _length));
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class _BytesBuilder implements BytesBuilder {
_length++;
}

List<int> takeBytes() {
Uint8List takeBytes() {
if (_length == 0) return _CopyingBytesBuilder._emptyList;
if (_chunks.length == 1) {
var buffer = _chunks[0];
Expand All @@ -196,7 +196,7 @@ class _BytesBuilder implements BytesBuilder {
return buffer;
}

List<int> toBytes() {
Uint8List toBytes() {
if (_length == 0) return _CopyingBytesBuilder._emptyList;
var buffer = Uint8List(_length);
int offset = 0;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: web_socket_channel
version: 1.0.12
version: 1.0.13

description: >-
StreamChannel wrappers for WebSockets. Provides a cross-platform
Expand Down

0 comments on commit 4cf0ace

Please sign in to comment.