Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteBuffer.asUint8List() has incorrect length #82

Open
bliep opened this issue Mar 5, 2024 · 0 comments
Open

ByteBuffer.asUint8List() has incorrect length #82

bliep opened this issue Mar 5, 2024 · 0 comments

Comments

@bliep
Copy link

bliep commented Mar 5, 2024

The following code demonstrates that the length of the Uint8List returned by ByteBuffer.asUint8List() has an unexpected value. Its value is perhaps related to the allocation size of the ByteBuffer, but does not equal the amount of bytes in the ByteBuffer.

import 'dart:typed_data';
import 'package:typed_data/typed_buffers.dart';

void main() {
  Uint8List ul = Uint8List(1);
  var b = Uint8Buffer();
  for (int i = 0; i < 10; i++) {
    b.addAll(ul);
    print("${b.lengthInBytes}, ${b.buffer.asUint8List().length}");
  }
}

will produce:

1, 1
2, 8
3, 8
4, 8
5, 8
6, 8
7, 8
8, 8
9, 16
10, 16

Dart SDK version: 3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64".

pubspec.lock:

# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  collection:
    dependency: transitive
    description:
      name: collection
      sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
      url: "https://pub.dev"
    source: hosted
    version: "1.18.0"
  typed_data:
    dependency: "direct main"
    description:
      name: typed_data
      sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
      url: "https://pub.dev"
    source: hosted
    version: "1.3.2"
sdks:
  dart: ">=3.0.0 <4.0.0"
  flutter: ">=3.3.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant