Reputation: 2206
I compiled some protobuf code to C++ and it worked fine, but for Dart (using the latest commit as of today day 6), I'm getting lots of errors when trying to compile my project with generated code.
For example, this file:
syntax = "proto3";
import "stream_setup.proto";
import "uuid.proto";
package message;
message Collection {
UUID uuid = 1;
string name = 2;
//Each entry should represent the order in which the StreamSetup appears
//in the collection. Since it's a map it can't have repeated entries
map<sint32, StreamSetup> streams = 3;
}
generates this file: https://pastebin.com/HK70SfGv, which when compiled in my Dart project, gives:
^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:16:20: Error: 'BuilderInfo' isn't a type.
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Collection', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'message'), createEmptyInstance: create)
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:16:157: Error: Method not found: 'PackageName'.
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Collection', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'message'), createEmptyInstance: create)
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:16:37: Error: Method not found: 'BuilderInfo'.
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Collection', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'message'), createEmptyInstance: create)
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:19:180: Error: Getter not found: 'PbFieldType'.
..m<$core.int, $1.StreamSetup>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'streams', entryClassName: 'Collection.StreamsEntry', keyFieldType: $pb.PbFieldType.OS3, valueFieldType: $pb.PbFieldType.OM, valueCreator: $1.StreamSetup.create, packageName: const $pb.PackageName('message'))
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:19:217: Error: Getter not found: 'PbFieldType'.
..m<$core.int, $1.StreamSetup>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'streams', entryClassName: 'Collection.StreamsEntry', keyFieldType: $pb.PbFieldType.OS3, valueFieldType: $pb.PbFieldType.OM, valueCreator: $1.StreamSetup.create, packageName: const $pb.PackageName('message'))
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:19:293: Error: Method not found: 'PackageName'.
..m<$core.int, $1.StreamSetup>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'streams', entryClassName: 'Collection.StreamsEntry', keyFieldType: $pb.PbFieldType.OS3, valueFieldType: $pb.PbFieldType.OM, valueCreator: $1.StreamSetup.create, packageName: const $pb.PackageName('message'))
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:25:63: Error: 'ExtensionRegistry' isn't a type.
factory Collection.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
^^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:25:89: Error: Getter not found: 'ExtensionRegistry'.
factory Collection.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
^^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:25:128: Error: The method 'mergeFromBuffer' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'mergeFromBuffer'.
factory Collection.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:26:52: Error: 'ExtensionRegistry' isn't a type.
factory Collection.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
^^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:26:78: Error: Getter not found: 'ExtensionRegistry'.
factory Collection.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
^^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:26:117: Error: The method 'mergeFromJson' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'mergeFromJson'.
factory Collection.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:31:39: Error: The method 'mergeFromMessage' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'mergeFromMessage'.
Collection clone() => Collection()..mergeFromMessage(this);
^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:36:67: Error: Superclass has no method named 'copyWith'.
Collection copyWith(void Function(Collection) updates) => super.copyWith((message) => updates(message as Collection)); // ignore: deprecated_member_use
^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:41:53: Error: Method not found: 'PbList'.
static $pb.PbList<Collection> createRepeated() => $pb.PbList<Collection>();
^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:43:62: Error: Getter not found: 'GeneratedMessage'.
static Collection getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<Collection>(create);
^^^^^^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:47:23: Error: The method '$_getN' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_getN'.
$0.UUID get uuid => $_getN(0);
^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:49:25: Error: The method 'setField' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setField'.
set uuid($0.UUID v) { setField(1, v); }
^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:51:27: Error: The method '$_has' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_has'.
$core.bool hasUuid() => $_has(0);
^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:53:23: Error: The method 'clearField' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'clearField'.
void clearUuid() => clearField(1);
^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:55:27: Error: The method '$_ensure' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_ensure'.
$0.UUID ensureUuid() => $_ensure(0);
^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:58:28: Error: The method '$_getSZ' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_getSZ'.
$core.String get name => $_getSZ(1);
^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:60:30: Error: The method '$_setString' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_setString'.
set name($core.String v) { $_setString(1, v); }
^^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:62:27: Error: The method '$_has' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_has'.
$core.bool hasName() => $_has(1);
^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:64:23: Error: The method 'clearField' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named 'clearField'.
void clearName() => clearField(2);
^^^^^^^^^^
../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart:67:55: Error: The method '$_getMap' isn't defined for the class 'Collection'.
- 'Collection' is from 'package:liborwellprofile2/collection.pb.dart' ('../liborwell/common/liborwellprofile2/proto_dart/lib/collection.pb.dart').
Try correcting the name to the name of an existing method, or defining a method named '$_getMap'.
$core.Map<$core.int, $1.StreamSetup> get streams => $_getMap(2);
I don't have idea about what's happening. It should work as I didn't modify anything in the generated files, I've simply put them inside a package and loaded into my project.
Upvotes: 1
Views: 756
Reputation: 287
I solved mine.
I have to add those libraries
for convertin .proto to dart
https://pub.dev/packages/protoc_plugin
after converting it showed a lot of errors and added these libraries.
fixnum: ^1.0.0
protobuf: ^2.0.0
After added still it showed some errors but now imports were invalid
import '../../../DartFile.pbenum.dart';
export '../../../DartFile.pbenum.dart';
I changed manually generated files too because they were on the same folder. somehow it generated in wrong path.
import 'DartFile.pbenum.dart';
export 'DartFile.pbenum.dart';
Upvotes: 1