google / google/protobuf.dart

Generate `bytes` with `Uint8List`

Open
#219 20 comments 16 reactions 0 assignees View on GitHub
feature request perf
Dominant language
Dart
Stars
572
Forks
196
Avg merge
1h 59m
Merged PRs (30d)
2

Description

Ref: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/JpNkRRLI9_w, https://github.com/Daegalus/dart-uuid/issues/35

More and more packages are explicitly switching to Uint8List

Right now, with the folling proto
```proto
message BluetoothCharacteristic {
bytes value = 6;
}
```

The generated dart code (by `Activated protoc_plugin 16.0.1.`) is
```dart
import 'dart:core' show int, bool, double, String, List, Map, override;

import 'package:protobuf/protobuf.dart' as $pb;

class BluetoothCharacteristic extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = new $pb.BuilderInfo('BluetoothCharacteristic')
..a>(6, 'value', $pb.PbFieldType.OY)
..hasRequiredFields = false
;

BluetoothCharacteristic() : super();
BluetoothCharacteristic.fromBuffer(List i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r);
BluetoothCharacteristic.fromJson(String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) : super.fromJson(i, r);
BluetoothCharacteristic clone() => new BluetoothCharacteristic()..mergeFromMessage(this);
BluetoothCharacteristic copyWith(void Function(BluetoothCharacteristic) updates) => super.copyWith((message) => updates(message as BluetoothCharacteristic));
$pb.BuilderInfo get info_ => _i;
static BluetoothCharacteristic create() => new BluetoothCharacteristic();
BluetoothCharacteristic createEmptyInstance() => create();
static $pb.PbList createRepeated() => new $pb.PbList();
static BluetoothCharacteristic getDefault() => _defaultInstance ??= create()..freeze();
static BluetoothCharacteristic _defaultInstance;

List get value => $_getN(0);
set value(List v) { $_setBytes(0, v); }
bool hasValue() => $_has(0);
void clearValue() => clearField(6);
}
```

We can see that we still have
```dart
List get value => $_getN(0);
set value(List v) { $_setBytes(0, v); }
```

Expected generated code:
```dart
Uint8List get value => $_getN(0);
set value(Uint8List v) { $_setBytes(0, v); }
```

One concern might be that this is more or less a breaking change in strong mode.

Contributor guide

Open the contributing guide

Research direction

Start in the protoc_plugin code path that emits Dart types for protobuf bytes fields, using the BluetoothCharacteristic example as the reference case. Check existing generated-code coverage for bytes fields and determine how Uint8List affects strong-mode compatibility. Done means generated bytes accessors use Uint8List with appropriate coverage and the compatibility concern is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.