This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Resize channel buffers #12402
Merged
Merged
Resize channel buffers #12402
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d451a75
Made it so you can resize channel buffers by sending messages to them.
gaaclarke e98ab1d
Merge branch 'master' into resize-channel-buffers
gaaclarke fb94780
added test for ios
gaaclarke 71eae84
Added android implementation
gaaclarke 07eb398
updated docstring, removed channel name from handleMessage call
gaaclarke a055d93
updated tests for new calls
gaaclarke 88e3ad8
Changed domain from "com.google.flutter" to "dev.flutter"
gaaclarke db100f8
ran formatter
gaaclarke 466519a
fixed formatting
gaaclarke a59725f
updated web_ui
gaaclarke 49b061b
fixed java linter warning
gaaclarke c33b53c
updated documentation and strings
gaaclarke 275d356
Merge branch 'master' into resize-channel-buffers
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -112,6 +112,8 @@ class ChannelBuffers { | |
| /// buffer size that will avoid any overflows. | ||
| static const int kDefaultBufferSize = 1; | ||
|
|
||
| static const String kControlChannelName = 'dev.flutter/channel-buffers'; | ||
|
|
||
| /// A mapping between a channel name and its associated [_RingBuffer]. | ||
| final Map<String, _RingBuffer<_StoredMessage>> _messages = | ||
| <String, _RingBuffer<_StoredMessage>>{}; | ||
|
|
@@ -162,7 +164,7 @@ class ChannelBuffers { | |
| /// | ||
| /// This could result in the dropping of messages if newSize is less | ||
| /// than the current length of the queue. | ||
| void resize(String channel, int newSize) { | ||
| void _resize(String channel, int newSize) { | ||
| _RingBuffer<_StoredMessage> queue = _messages[channel]; | ||
| if (queue == null) { | ||
| queue = _makeRingBuffer(newSize); | ||
|
|
@@ -185,6 +187,30 @@ class ChannelBuffers { | |
| await callback(message.data, message.callback); | ||
| } | ||
| } | ||
|
|
||
| String _getString(ByteData data) { | ||
| final ByteBuffer buffer = data.buffer; | ||
| final Uint8List list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); | ||
| return utf8.decode(list); | ||
| } | ||
|
|
||
| /// Handle a control message. | ||
| /// | ||
| /// This is intended to be called by the platform messages dispatcher. | ||
| /// | ||
| /// Available messages: | ||
| /// - Name: resize | ||
| /// Arity: 2 | ||
| /// Format: `resize\r<channel name>\r<new size>` | ||
| /// Description: Allows you to set the size of a channel's buffer. | ||
| void handleMessage(ByteData data) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the structure of these control messages, name of the channel, etc. documented anywhere or is this a new convention?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's new. I've documented them in the docstring. If there is somewhere else you'd like to see them let me know. The intention is that there is nice API's overtop of them so no one has to create them manually. |
||
| final List<String> command = _getString(data).split('\r'); | ||
| if (command.length == /*arity=*/2 + 1 && command[0] == 'resize') { | ||
| _resize(command[1], int.parse(command[2])); | ||
| } else { | ||
| throw Exception('Unrecognized command $command sent to $kControlChannelName.'); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// [ChannelBuffer]s that allow the storage of messages between the | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A previously public method is now hidden. Isn't this a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was public only for about a week.