Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Sync changes from internal repo. (#96)
Browse files Browse the repository at this point in the history
* Added enumValues to FieldInfo. Fixes google/protobuf.dart#63.
  • Loading branch information
jakobr-google authored Oct 25, 2017
1 parent 9bcb838 commit 1d0dd74
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.7.8 - 2017-10-25

* Added enumValues to FieldInfo.

## 0.7.7 - 2017-09-25

* Avoid name clashes between import prefix and field names.
Expand Down
3 changes: 2 additions & 1 deletion lib/code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class CodeGenerator extends ProtobufContainer {
Dart_options.registerAllExtensions(extensions);

_streamIn
.fold(new BytesBuilder(), (builder, data) => builder..add(data))
.fold(new BytesBuilder(),
(BytesBuilder builder, data) => builder..add(data))
.then((builder) => builder.takeBytes())
.then((List<int> bytes) {
var request = new CodeGeneratorRequest.fromBuffer(bytes, extensions);
Expand Down
7 changes: 4 additions & 3 deletions lib/extension_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class ExtensionGenerator {
if (type.isMessage || type.isGroup) {
out.println(', $dartType.$checkItem, $dartType.create);');
} else if (type.isEnum) {
out.println(', $dartType.$checkItem, null, $dartType.valueOf);');
out.println(', $dartType.$checkItem, null, '
'$dartType.valueOf, $dartType.values);');
} else {
out.println(", getCheckFunction(${_field.typeConstant}));");
}
Expand All @@ -102,8 +103,8 @@ class ExtensionGenerator {
out.println(', $initializer, $dartType.create);');
} else if (type.isEnum) {
var dartEnum = type.getDartType(package);
String valueOf = '(var v) => $dartEnum.valueOf(v)';
out.println(", $initializer, null, $valueOf);");
String enumParams = '(var v) => $dartEnum.valueOf(v), $dartEnum.values';
out.println(", $initializer, null, $enumParams);");
} else if (initializer != null) {
out.println(", $initializer);");
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/protobuf_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ class ProtobufField {
' $type.$checkItem, $type.create)';
} else if (baseType.isEnum) {
return '..pp<$type>($number, $quotedName, $typeConstant,'
' $type.$checkItem, null, $type.valueOf)';
' $type.$checkItem, null, $type.valueOf, $type.values)';
} else {
return '..p<$type>($number, $quotedName, $typeConstant)';
}
}

String makeDefault = generateDefaultFunction(package);
if (baseType.isEnum) {
String valueOf = '$type.valueOf';
String enumParams = '$type.valueOf, $type.values';
return '..e<$type>('
'$number, $quotedName, $typeConstant, $makeDefault, $valueOf)';
'$number, $quotedName, $typeConstant, $makeDefault, $enumParams)';
}

String prefix = '..a<$type>($number, $quotedName, $typeConstant';
Expand Down
36 changes: 27 additions & 9 deletions lib/src/descriptor.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,15 @@ class FieldDescriptorProto extends GeneratedMessage {
'label',
PbFieldType.OE,
FieldDescriptorProto_Label.LABEL_OPTIONAL,
FieldDescriptorProto_Label.valueOf)
FieldDescriptorProto_Label.valueOf,
FieldDescriptorProto_Label.values)
..e<FieldDescriptorProto_Type>(
5,
'type',
PbFieldType.OE,
FieldDescriptorProto_Type.TYPE_DOUBLE,
FieldDescriptorProto_Type.valueOf)
FieldDescriptorProto_Type.valueOf,
FieldDescriptorProto_Type.values)
..a<String>(6, 'typeName', PbFieldType.OS)
..a<String>(7, 'defaultValue', PbFieldType.OS)
..a<FieldOptions>(8, 'options', PbFieldType.OM, FieldOptions.getDefault,
Expand Down Expand Up @@ -786,8 +788,13 @@ class FileOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FileOptions')
..a<String>(1, 'javaPackage', PbFieldType.OS)
..a<String>(8, 'javaOuterClassname', PbFieldType.OS)
..e<FileOptions_OptimizeMode>(9, 'optimizeFor', PbFieldType.OE,
FileOptions_OptimizeMode.SPEED, FileOptions_OptimizeMode.valueOf)
..e<FileOptions_OptimizeMode>(
9,
'optimizeFor',
PbFieldType.OE,
FileOptions_OptimizeMode.SPEED,
FileOptions_OptimizeMode.valueOf,
FileOptions_OptimizeMode.values)
..a<bool>(10, 'javaMultipleFiles', PbFieldType.OB)
..a<String>(11, 'goPackage', PbFieldType.OS)
..a<bool>(16, 'ccGenericServices', PbFieldType.OB)
Expand Down Expand Up @@ -1041,13 +1048,23 @@ class _ReadonlyMessageOptions extends MessageOptions with ReadonlyMessageMixin {

class FieldOptions extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('FieldOptions')
..e<FieldOptions_CType>(1, 'ctype', PbFieldType.OE,
FieldOptions_CType.STRING, FieldOptions_CType.valueOf)
..e<FieldOptions_CType>(
1,
'ctype',
PbFieldType.OE,
FieldOptions_CType.STRING,
FieldOptions_CType.valueOf,
FieldOptions_CType.values)
..a<bool>(2, 'packed', PbFieldType.OB)
..a<bool>(3, 'deprecated', PbFieldType.OB)
..a<bool>(5, 'lazy', PbFieldType.OB)
..e<FieldOptions_JSType>(6, 'jstype', PbFieldType.OE,
FieldOptions_JSType.JS_NORMAL, FieldOptions_JSType.valueOf)
..e<FieldOptions_JSType>(
6,
'jstype',
PbFieldType.OE,
FieldOptions_JSType.JS_NORMAL,
FieldOptions_JSType.valueOf,
FieldOptions_JSType.values)
..a<bool>(10, 'weak', PbFieldType.OB)
..pp<UninterpretedOption>(999, 'uninterpretedOption', PbFieldType.PM,
UninterpretedOption.$checkItem, UninterpretedOption.create)
Expand Down Expand Up @@ -1307,7 +1324,8 @@ class MethodOptions extends GeneratedMessage {
'idempotencyLevel',
PbFieldType.OE,
MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN,
MethodOptions_IdempotencyLevel.valueOf)
MethodOptions_IdempotencyLevel.valueOf,
MethodOptions_IdempotencyLevel.values)
..pp<UninterpretedOption>(999, 'uninterpretedOption', PbFieldType.PM,
UninterpretedOption.$checkItem, UninterpretedOption.create)
..hasExtensions = true;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: protoc_plugin
version: 0.7.7
version: 0.7.8
author: Dart Team <misc@dartlang.org>
description: Protoc compiler plugin to generate Dart code
homepage: https://github.com/dart-lang/dart-protoc-plugin
Expand All @@ -8,7 +8,7 @@ environment:
dependencies:
fixnum: ^0.10.5
path: ^1.0.0
protobuf: ^0.5.5
protobuf: ^0.6.0
dart_style: ^1.0.6
dev_dependencies:
browser: any
Expand Down
2 changes: 1 addition & 1 deletion test/message_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PhoneNumber_PhoneType extends ProtobufEnum {
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
..a<String>(1, 'number', PbFieldType.QS)
..e<PhoneNumber_PhoneType>(2, 'type', PbFieldType.OE, PhoneNumber_PhoneType.MOBILE, PhoneNumber_PhoneType.valueOf)
..e<PhoneNumber_PhoneType>(2, 'type', PbFieldType.OE, PhoneNumber_PhoneType.MOBILE, PhoneNumber_PhoneType.valueOf, PhoneNumber_PhoneType.values)
..a<String>(3, 'name', PbFieldType.OS, '\$')
;
Expand Down

0 comments on commit 1d0dd74

Please sign in to comment.