Skip to content

Add optional endian argument for WriteBuffer/ReadBuffer#46661

Merged
fluttergithubbot merged 2 commits intoflutter:masterfrom
Sunbreak:serilization-add-endian
Jan 8, 2020
Merged

Add optional endian argument for WriteBuffer/ReadBuffer#46661
fluttergithubbot merged 2 commits intoflutter:masterfrom
Sunbreak:serilization-add-endian

Conversation

@Sunbreak
Copy link
Copy Markdown
Contributor

Signed-off-by: sunbreak sunbreak.wang@gmail.com

Description

This PR add an optional endian to WriteBuffer/ReadBuffer class for convenience

I'm a IoT developer, writing applications via BLE protocol as below
https://github.com/woodemi/notepad-core-flutter/blob/develop/lib/woodemi/WoodemiClient.dart#L455-L465

var imageId = fileInfo.item1;
var byteData = ByteData(imageId.length + 4 + 4 + 2 + 1 + 2);
var position = 0;
for (var b in imageId)
  byteData.setInt8(position++, b);
byteData.setUint32(position, currentPos, Endian.little);
byteData.setUint32(position += 4, blockSize, Endian.little);
byteData.setUint16(position += 4, maxChunkSize, Endian.little);
byteData.setUint8(position += 2, transferMethod);
byteData.setUint16(position += 1, l2capChannelOrPsm, Endian.little);
var request = Uint8List.fromList([0x04] + byteData.buffer.asUint8List());

I find WriteBuffer/ReadBuffer in package:flutter/foundation with similiar methods, except for the endians

With this PR merged

var writeBuffer = WriteBuffer();
writeBuffer.putUint8List(imageId);
writeBuffer.putUint32(currentPos, Endian.little);
writeBuffer.putUint32(blockSize, Endian.little);
writeBuffer.putUint16(maxChunkSize, Endian.little);
writeBuffer.putUint8(transferMethod);
writeBuffer.putUint16(l2capChannelOrPsm, Endian.little);
var request = Uint8List.fromList([0x04] + writeBuffer.done().buffer.asUint8List());

Related Issues

Tests

I added the following tests:

  • of 32-bit integer in big endian
  • of 64-bit integer in big endian
  • of double in big endian

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

Signed-off-by: sunbreak <sunbreak.wang@gmail.com>
@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 10, 2019
@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@Sunbreak
Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@goderbauer
Copy link
Copy Markdown
Member

If you already have a way of doing this, why do you need this change in the framework?

@Sunbreak
Copy link
Copy Markdown
Contributor Author

If you already have a way of doing this, why do you need this change in the framework?

WriteBuffer/ReadBuffer are introduced for some byte operations in the framework from the beginning, I suppose. A little improvement may help others as well.

Comment thread packages/flutter/lib/src/foundation/serialization.dart Outdated
Signed-off-by: sunbreak <sunbreak.wang@gmail.com>
@Sunbreak
Copy link
Copy Markdown
Contributor Author

Update the PR with an appended commit.
@chunhtai should I rebase into one commit, and/or rebase onto branch master commit?

Comment thread packages/flutter/lib/src/foundation/serialization.dart
Copy link
Copy Markdown
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fluttergithubbot fluttergithubbot merged commit 4e6d649 into flutter:master Jan 8, 2020
@Sunbreak Sunbreak deleted the serilization-add-endian branch January 9, 2020 01:13
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants