Skip to content

Avoid storing the BuilderInfo in _FieldSet #212

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ FrozenMessageErrorHandler frozenMessageModificationHandler =
/// be faster when compiled to JavaScript.
class _FieldSet {
final GeneratedMessage _message;
final BuilderInfo _meta;
final EventPlugin _eventPlugin;
bool _isReadOnly = false;

Expand All @@ -53,8 +52,9 @@ class _FieldSet {
final Map<int, int> oneofCases = <int, int>{};

_FieldSet(this._message, BuilderInfo meta, this._eventPlugin)
Copy link
Member

Choose a reason for hiding this comment

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

Remove the meta parameter?

: this._meta = meta,
_values = _makeValueList(meta.byIndex.length);
: _values = _makeValueList(_message.info_.byIndex.length);

BuilderInfo get _meta => _message.info_;

static _makeValueList(int length) {
if (length == 0) return _zeroList;
Expand Down
19 changes: 18 additions & 1 deletion protobuf/lib/src/protobuf/pb_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

part of protobuf;

class _PBMapEntry extends GeneratedMessage {
_PBMapEntry(this.info_);

@override
GeneratedMessage clone() {
throw StateError('This method should not have been called');
}

@override
GeneratedMessage createEmptyInstance() {
throw StateError('This method should not have been called');
}

@override
final BuilderInfo info_;
}

class PbMap<K, V> extends MapBase<K, V> {
final int keyFieldType;
final int valueFieldType;
Expand All @@ -15,7 +32,7 @@ class PbMap<K, V> extends MapBase<K, V> {
final BuilderInfo _entryBuilderInfo;

bool _isReadonly = false;
_FieldSet _entryFieldSet() => new _FieldSet(null, _entryBuilderInfo, null);
_FieldSet _entryFieldSet() => new _FieldSet(_PBMapEntry(_entryBuilderInfo), null, null);

PbMap(this.keyFieldType, this.valueFieldType, this._entryBuilderInfo)
: _wrappedMap = <K, V>{};
Expand Down
27 changes: 27 additions & 0 deletions protoc_plugin/test/isolate_communication.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:isolate' as isolate;
import '../out/protos/foo.pb.dart';
import 'package:test/test.dart';

runInIsolate(isolate.SendPort sendPort) {
sendPort.send(Outer()
..inner = (Inner()..value = 'pip')
..inners.add(Inner()..value = 'pop'));
}

main() async {
test('Messages can be sent across isolates', () async {
isolate.ReceivePort receivePort = isolate.ReceivePort();
isolate.Isolate.spawn(runInIsolate, receivePort.sendPort);
Outer received = await receivePort.first;
expect(received.inner.value, 'pip');
expect(received.inners.single.value, 'pop');
}, onPlatform: {
'js': Skip(
'Dart compiled to javascript does not allow complex objects to be sent '
'between isolates.')
});
}