From 649e1a117b365f9d4567877b75ce33cc7c812eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 09:54:01 +0100 Subject: [PATCH 01/22] Split protobuf package into libraries In preparation for adding conditional imports to be able to use different encoding/decoding implementation based on the platform, this PR creates an "internal" library and exports some of the important types for encoding/decoding like `FieldInfo`, `PbFieldType` (renamed as `PbFieldTypeInternal`). This syncs some of cl/613649886. --- protobuf/lib/protobuf.dart | 69 +----- protobuf/lib/src/protobuf/annotations.dart | 2 +- protobuf/lib/src/protobuf/builder_info.dart | 41 ++-- protobuf/lib/src/protobuf/coded_buffer.dart | 87 ++++---- .../lib/src/protobuf/coded_buffer_reader.dart | 2 +- .../lib/src/protobuf/coded_buffer_writer.dart | 48 ++-- protobuf/lib/src/protobuf/consts.dart | 2 +- protobuf/lib/src/protobuf/exceptions.dart | 2 +- protobuf/lib/src/protobuf/extension.dart | 2 +- .../lib/src/protobuf/extension_field_set.dart | 18 +- .../lib/src/protobuf/extension_registry.dart | 2 +- protobuf/lib/src/protobuf/field_error.dart | 76 +++---- protobuf/lib/src/protobuf/field_info.dart | 60 +++-- protobuf/lib/src/protobuf/field_set.dart | 43 +++- protobuf/lib/src/protobuf/field_type.dart | 23 +- .../lib/src/protobuf/generated_message.dart | 12 +- .../lib/src/protobuf/generated_service.dart | 2 +- protobuf/lib/src/protobuf/internal.dart | 67 ++++++ protobuf/lib/src/protobuf/json.dart | 92 ++++---- protobuf/lib/src/protobuf/message_set.dart | 2 +- protobuf/lib/src/protobuf/pb_list.dart | 2 +- protobuf/lib/src/protobuf/pb_map.dart | 4 +- protobuf/lib/src/protobuf/proto3_json.dart | 130 +++++------ protobuf/lib/src/protobuf/protobuf_enum.dart | 2 +- protobuf/lib/src/protobuf/rpc_client.dart | 2 +- .../lib/src/protobuf/unknown_field_set.dart | 12 +- protobuf/lib/src/protobuf/unpack.dart | 2 +- protobuf/lib/src/protobuf/utils.dart | 2 +- protobuf/lib/src/protobuf/wire_format.dart | 40 ++-- protobuf/test/codec_test.dart | 23 +- protobuf/test/list_test.dart | 12 +- protobuf/test/mock_util.dart | 20 +- protobuf/test/readonly_message_test.dart | 12 +- protoc_plugin/lib/src/base_type.dart | 2 +- .../lib/src/gen/dart_options.pb.dart | 19 +- .../lib/src/gen/google/api/client.pb.dart | 42 ++-- .../lib/src/gen/google/api/http.pb.dart | 7 +- .../lib/src/gen/google/api/routing.pb.dart | 6 +- .../google/protobuf/compiler/plugin.pb.dart | 25 ++- .../gen/google/protobuf/descriptor.pb.dart | 210 ++++++++++-------- .../src/gen/google/protobuf/duration.pb.dart | 3 +- protoc_plugin/lib/src/protobuf_field.dart | 17 +- protoc_plugin/test/goldens/extension.pb.dart | 2 +- .../test/goldens/messageGenerator.pb.dart | 4 +- .../goldens/messageGenerator.pb.dart.meta | 64 +++--- protoc_plugin/test/goldens/oneMessage.pb.dart | 5 +- .../test/goldens/oneMessage.pb.dart.meta | 48 ++-- protoc_plugin/test/reserved_names_test.dart | 6 +- 48 files changed, 758 insertions(+), 617 deletions(-) create mode 100644 protobuf/lib/src/protobuf/internal.dart diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index b500e512c..5936d56df 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -7,61 +7,14 @@ /// [1]: https://developers.google.com/protocol-buffers library; -import 'dart:collection' show ListBase, MapBase; -import 'dart:convert' - show - Utf8Decoder, - Utf8Encoder, - base64Decode, - base64Encode, - jsonDecode, - jsonEncode; -import 'dart:math' as math; -import 'dart:typed_data' show ByteData, Endian, Uint8List; - -import 'package:fixnum/fixnum.dart' show Int64; -import 'package:meta/meta.dart' show UseResult; - -import 'src/protobuf/json_parsing_context.dart'; -import 'src/protobuf/permissive_compare.dart'; -import 'src/protobuf/type_registry.dart'; - -export 'src/protobuf/type_registry.dart' show TypeRegistry; - -part 'src/protobuf/annotations.dart'; -part 'src/protobuf/builder_info.dart'; -part 'src/protobuf/coded_buffer.dart'; -part 'src/protobuf/coded_buffer_reader.dart'; -part 'src/protobuf/coded_buffer_writer.dart'; -part 'src/protobuf/consts.dart'; -part 'src/protobuf/exceptions.dart'; -part 'src/protobuf/extension.dart'; -part 'src/protobuf/extension_field_set.dart'; -part 'src/protobuf/extension_registry.dart'; -part 'src/protobuf/field_error.dart'; -part 'src/protobuf/field_info.dart'; -part 'src/protobuf/field_set.dart'; -part 'src/protobuf/field_type.dart'; -part 'src/protobuf/generated_message.dart'; -part 'src/protobuf/generated_service.dart'; -part 'src/protobuf/json.dart'; -part 'src/protobuf/message_set.dart'; -part 'src/protobuf/pb_list.dart'; -part 'src/protobuf/pb_map.dart'; -part 'src/protobuf/proto3_json.dart'; -part 'src/protobuf/protobuf_enum.dart'; -part 'src/protobuf/rpc_client.dart'; -part 'src/protobuf/unknown_field_set.dart'; -part 'src/protobuf/unpack.dart'; -part 'src/protobuf/utils.dart'; -part 'src/protobuf/wire_format.dart'; - -// TODO(sra): Use `Int64.parse()` when available: -// https://github.com/dart-lang/fixnum/issues/18. -/// @nodoc -Int64 parseLongInt(String text) { - if (text.startsWith('0x')) return Int64.parseHex(text.substring(2)); - if (text.startsWith('+0x')) return Int64.parseHex(text.substring(3)); - if (text.startsWith('-0x')) return -Int64.parseHex(text.substring(3)); - return Int64.parseInt(text); -} +export 'src/protobuf/internal.dart' + hide + BuilderInfoInternalExtension, + EnumFieldInfoExtension, + ExtensionFieldSet, + ExtensionFieldSetInternalExtension, + FieldInfoInternalExtension, + FieldSet, + FieldSetInternalExtension, + GeneratedMessageInternalExtension, + MapFieldInfoInternalExtension; diff --git a/protobuf/lib/src/protobuf/annotations.dart b/protobuf/lib/src/protobuf/annotations.dart index 9ec997b66..fa2745381 100644 --- a/protobuf/lib/src/protobuf/annotations.dart +++ b/protobuf/lib/src/protobuf/annotations.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Annotation for marking accessors that belong together. class TagNumber { diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index 4ac8bc06e..56cce4608 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Per-message type setup. class BuilderInfo { @@ -28,7 +28,7 @@ class BuilderInfo { final Map byName = {}; /// Mapping from `oneof` field [FieldInfo.tagNumber]s to the their indices in - /// [_FieldSet._oneofCases]. + /// [FieldSet._oneofCases]. final Map oneofs = {}; /// Whether the message has extension fields. @@ -105,7 +105,7 @@ class BuilderInfo { name, tagNumber, index, - PbFieldType.M, + PbFieldTypeInternal.M, keyFieldType, valueFieldType, mapEntryBuilderInfo, @@ -179,13 +179,13 @@ class BuilderInfo { ); } - /// Adds PbFieldType.OS String with no default value to reduce generated + /// Adds PbFieldTypeInternal.OS String with no default value to reduce generated /// code size. void aOS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldType.OS, + PbFieldTypeInternal.OS, null, null, null, @@ -194,13 +194,13 @@ class BuilderInfo { ); } - /// Adds PbFieldType.PS String with no default value. + /// Adds PbFieldTypeInternal.PS String with no default value. void pPS(int tagNumber, String name, {String? protoName}) { addRepeated( tagNumber, name, - PbFieldType.PS, - getCheckFunction(PbFieldType.PS), + PbFieldTypeInternal.PS, + getCheckFunction(PbFieldTypeInternal.PS), null, null, null, @@ -208,12 +208,12 @@ class BuilderInfo { ); } - /// Adds PbFieldType.QS String with no default value. + /// Adds PbFieldTypeInternal.QS String with no default value. void aQS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldType.QS, + PbFieldTypeInternal.QS, null, null, null, @@ -227,7 +227,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldType.O6, + PbFieldTypeInternal.O6, Int64.ZERO, null, null, @@ -241,7 +241,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldType.OB, + PbFieldTypeInternal.OB, null, null, null, @@ -321,7 +321,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldType.OM, + PbFieldTypeInternal.OM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, @@ -339,7 +339,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldType.QM, + PbFieldTypeInternal.QM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, @@ -487,3 +487,16 @@ class BuilderInfo { ?.call(rawValue); } } + +extension BuilderInfoInternalExtension on BuilderInfo { + GeneratedMessage makeEmptyMessage( + int tagNumber, + ExtensionRegistry? extensionRegistry, + ) => _makeEmptyMessage(tagNumber, extensionRegistry); + + ProtobufEnum? decodeEnum( + int tagNumber, + ExtensionRegistry? registry, + int rawValue, + ) => _decodeEnum(tagNumber, registry, rawValue); +} diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index 4166228c4..2036142d8 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -2,9 +2,9 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; -void _writeToCodedBufferWriter(_FieldSet fs, CodedBufferWriter out) { +void _writeToCodedBufferWriter(FieldSet fs, CodedBufferWriter out) { // Sorting by tag number isn't required, but it sometimes enables // performance optimizations for the receiver. See: // https://developers.google.com/protocol-buffers/docs/encoding?hl=en#order @@ -31,7 +31,7 @@ void _writeToCodedBufferWriter(_FieldSet fs, CodedBufferWriter out) { void _mergeFromCodedBufferReader( BuilderInfo meta, - _FieldSet fs, + FieldSet fs, CodedBufferReader input, ExtensionRegistry registry, ) { @@ -54,24 +54,25 @@ void _mergeFromCodedBufferReader( // Ignore required/optional packed/unpacked. var fieldType = fi.type; - fieldType &= ~(PbFieldType._PACKED_BIT | PbFieldType._REQUIRED_BIT); + fieldType &= + ~(PbFieldTypeInternal._PACKED_BIT | PbFieldTypeInternal._REQUIRED_BIT); switch (fieldType) { - case PbFieldType._OPTIONAL_BOOL: + case PbFieldTypeInternal._OPTIONAL_BOOL: fs._setFieldUnchecked(meta, fi, input.readBool()); break; - case PbFieldType._OPTIONAL_BYTES: + case PbFieldTypeInternal._OPTIONAL_BYTES: fs._setFieldUnchecked(meta, fi, input.readBytes()); break; - case PbFieldType._OPTIONAL_STRING: + case PbFieldTypeInternal._OPTIONAL_STRING: fs._setFieldUnchecked(meta, fi, input.readString()); break; - case PbFieldType._OPTIONAL_FLOAT: + case PbFieldTypeInternal._OPTIONAL_FLOAT: fs._setFieldUnchecked(meta, fi, input.readFloat()); break; - case PbFieldType._OPTIONAL_DOUBLE: + case PbFieldTypeInternal._OPTIONAL_DOUBLE: fs._setFieldUnchecked(meta, fi, input.readDouble()); break; - case PbFieldType._OPTIONAL_ENUM: + case PbFieldTypeInternal._OPTIONAL_ENUM: final rawValue = input.readEnum(); final value = meta._decodeEnum(tagNumber, registry, rawValue); if (value == null) { @@ -81,7 +82,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, value); } break; - case PbFieldType._OPTIONAL_GROUP: + case PbFieldTypeInternal._OPTIONAL_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); final oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { @@ -90,37 +91,37 @@ void _mergeFromCodedBufferReader( input.readGroup(tagNumber, subMessage, registry); fs._setFieldUnchecked(meta, fi, subMessage); break; - case PbFieldType._OPTIONAL_INT32: + case PbFieldTypeInternal._OPTIONAL_INT32: fs._setFieldUnchecked(meta, fi, input.readInt32()); break; - case PbFieldType._OPTIONAL_INT64: + case PbFieldTypeInternal._OPTIONAL_INT64: fs._setFieldUnchecked(meta, fi, input.readInt64()); break; - case PbFieldType._OPTIONAL_SINT32: + case PbFieldTypeInternal._OPTIONAL_SINT32: fs._setFieldUnchecked(meta, fi, input.readSint32()); break; - case PbFieldType._OPTIONAL_SINT64: + case PbFieldTypeInternal._OPTIONAL_SINT64: fs._setFieldUnchecked(meta, fi, input.readSint64()); break; - case PbFieldType._OPTIONAL_UINT32: + case PbFieldTypeInternal._OPTIONAL_UINT32: fs._setFieldUnchecked(meta, fi, input.readUint32()); break; - case PbFieldType._OPTIONAL_UINT64: + case PbFieldTypeInternal._OPTIONAL_UINT64: fs._setFieldUnchecked(meta, fi, input.readUint64()); break; - case PbFieldType._OPTIONAL_FIXED32: + case PbFieldTypeInternal._OPTIONAL_FIXED32: fs._setFieldUnchecked(meta, fi, input.readFixed32()); break; - case PbFieldType._OPTIONAL_FIXED64: + case PbFieldTypeInternal._OPTIONAL_FIXED64: fs._setFieldUnchecked(meta, fi, input.readFixed64()); break; - case PbFieldType._OPTIONAL_SFIXED32: + case PbFieldTypeInternal._OPTIONAL_SFIXED32: fs._setFieldUnchecked(meta, fi, input.readSfixed32()); break; - case PbFieldType._OPTIONAL_SFIXED64: + case PbFieldTypeInternal._OPTIONAL_SFIXED64: fs._setFieldUnchecked(meta, fi, input.readSfixed64()); break; - case PbFieldType._OPTIONAL_MESSAGE: + case PbFieldTypeInternal._OPTIONAL_MESSAGE: final GeneratedMessage? oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { input.readMessage(oldValue, registry); @@ -130,7 +131,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, subMessage); } break; - case PbFieldType._REPEATED_BOOL: + case PbFieldTypeInternal._REPEATED_BOOL: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -150,17 +151,17 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readBool()); } break; - case PbFieldType._REPEATED_BYTES: + case PbFieldTypeInternal._REPEATED_BYTES: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readBytes()); break; - case PbFieldType._REPEATED_STRING: + case PbFieldTypeInternal._REPEATED_STRING: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readString()); break; - case PbFieldType._REPEATED_FLOAT: + case PbFieldTypeInternal._REPEATED_FLOAT: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -177,7 +178,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFloat()); } break; - case PbFieldType._REPEATED_DOUBLE: + case PbFieldTypeInternal._REPEATED_DOUBLE: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -194,7 +195,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readDouble()); } break; - case PbFieldType._REPEATED_ENUM: + case PbFieldTypeInternal._REPEATED_ENUM: final list = fs._ensureRepeatedField(meta, fi); _readPackableToListEnum( list, @@ -206,13 +207,13 @@ void _mergeFromCodedBufferReader( registry, ); break; - case PbFieldType._REPEATED_GROUP: + case PbFieldTypeInternal._REPEATED_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readGroup(tagNumber, subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldType._REPEATED_INT32: + case PbFieldTypeInternal._REPEATED_INT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -229,7 +230,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt32()); } break; - case PbFieldType._REPEATED_INT64: + case PbFieldTypeInternal._REPEATED_INT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -246,7 +247,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt64()); } break; - case PbFieldType._REPEATED_SINT32: + case PbFieldTypeInternal._REPEATED_SINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -263,7 +264,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint32()); } break; - case PbFieldType._REPEATED_SINT64: + case PbFieldTypeInternal._REPEATED_SINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -280,7 +281,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint64()); } break; - case PbFieldType._REPEATED_UINT32: + case PbFieldTypeInternal._REPEATED_UINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -297,7 +298,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint32()); } break; - case PbFieldType._REPEATED_UINT64: + case PbFieldTypeInternal._REPEATED_UINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -314,7 +315,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint64()); } break; - case PbFieldType._REPEATED_FIXED32: + case PbFieldTypeInternal._REPEATED_FIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -331,7 +332,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed32()); } break; - case PbFieldType._REPEATED_FIXED64: + case PbFieldTypeInternal._REPEATED_FIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -348,7 +349,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed64()); } break; - case PbFieldType._REPEATED_SFIXED32: + case PbFieldTypeInternal._REPEATED_SFIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -365,7 +366,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed32()); } break; - case PbFieldType._REPEATED_SFIXED64: + case PbFieldTypeInternal._REPEATED_SFIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -382,13 +383,13 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed64()); } break; - case PbFieldType._REPEATED_MESSAGE: + case PbFieldTypeInternal._REPEATED_MESSAGE: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readMessage(subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldType._MAP: + case PbFieldTypeInternal._MAP: final mapFieldInfo = fi as MapFieldInfo; final mapEntryMeta = mapFieldInfo.mapEntryBuilderInfo; fs @@ -404,7 +405,7 @@ void _mergeFromCodedBufferReader( void _readPackableToListEnum( List list, BuilderInfo meta, - _FieldSet fs, + FieldSet fs, CodedBufferReader input, int wireType, int tagNumber, @@ -426,7 +427,7 @@ void _readPackableToListEnum( void _readRepeatedEnum( List list, BuilderInfo meta, - _FieldSet fs, + FieldSet fs, CodedBufferReader input, int tagNumber, ExtensionRegistry registry, diff --git a/protobuf/lib/src/protobuf/coded_buffer_reader.dart b/protobuf/lib/src/protobuf/coded_buffer_reader.dart index 2bb9c2ecd..bb1f58551 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_reader.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_reader.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Reader used for converting binary-encoded protobufs into /// [GeneratedMessage]s. diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index a8dffd80a..6bce23985 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -4,7 +4,7 @@ // ignore_for_file: constant_identifier_names -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Writer used for converting [GeneratedMessage]s into binary /// representation. @@ -65,9 +65,9 @@ class CodedBufferWriter { } void writeField(int fieldNumber, int fieldType, Object? fieldValue) { - final valueType = PbFieldType._baseType(fieldType); + final valueType = PbFieldTypeInternal._baseType(fieldType); - if ((fieldType & PbFieldType._PACKED_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal._PACKED_BIT) != 0) { final list = fieldValue as List; if (list.isNotEmpty) { _writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); @@ -80,7 +80,7 @@ class CodedBufferWriter { return; } - if ((fieldType & PbFieldType._MAP_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal._MAP_BIT) != 0) { final map = fieldValue as PbMap; final keyWireFormat = _wireTypes[_valueTypeIndex(map.keyFieldType)]; final valueWireFormat = _wireTypes[_valueTypeIndex(map.valueFieldType)]; @@ -107,7 +107,7 @@ class CodedBufferWriter { final wireFormat = _wireTypes[_valueTypeIndex(valueType)]; - if ((fieldType & PbFieldType._REPEATED_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0) { final list = fieldValue as List; for (var i = 0; i < list.length; i++) { _writeValue(fieldNumber, valueType, list[i], wireFormat); @@ -353,10 +353,10 @@ class CodedBufferWriter { void _writeValueAs(int valueType, dynamic value) { switch (valueType) { - case PbFieldType._BOOL_BIT: + case PbFieldTypeInternal._BOOL_BIT: _writeVarint32(value ? 1 : 0); break; - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: final List bytes = value; if (bytes is Uint8List) { _writeBytesNoTag(bytes); @@ -366,7 +366,7 @@ class CodedBufferWriter { _writeBytesNoTag(Uint8List.fromList(bytes)); } break; - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: final String string = value; if (string.isEmpty) { _writeEmptyBytes(); @@ -374,17 +374,17 @@ class CodedBufferWriter { _writeBytesNoTag(const Utf8Encoder().convert(string)); } break; - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: _writeDouble(value); break; - case PbFieldType._FLOAT_BIT: + case PbFieldTypeInternal._FLOAT_BIT: _writeFloat(value); break; - case PbFieldType._ENUM_BIT: + case PbFieldTypeInternal._ENUM_BIT: final ProtobufEnum enum_ = value; _writeVarint32(enum_.value & 0xffffffff); break; - case PbFieldType._GROUP_BIT: + case PbFieldTypeInternal._GROUP_BIT: // `value` is `UnknownFieldSet` or `GeneratedMessage`. Test for // `UnknownFieldSet` as it doesn't have subtypes, so the type test will // be fast. @@ -399,37 +399,37 @@ class CodedBufferWriter { message.writeToCodedBufferWriter(this); } break; - case PbFieldType._INT32_BIT: + case PbFieldTypeInternal._INT32_BIT: _writeVarint64(Int64(value)); break; - case PbFieldType._INT64_BIT: + case PbFieldTypeInternal._INT64_BIT: _writeVarint64(value); break; - case PbFieldType._SINT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: _writeVarint32(_encodeZigZag32(value)); break; - case PbFieldType._SINT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: _writeVarint64(_encodeZigZag64(value)); break; - case PbFieldType._UINT32_BIT: + case PbFieldTypeInternal._UINT32_BIT: _writeVarint32(value); break; - case PbFieldType._UINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: _writeVarint64(value); break; - case PbFieldType._FIXED32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: _writeInt32(value); break; - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: _writeInt64(value); break; - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: _writeInt32(value); break; - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: _writeInt64(value); break; - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: final mark = _startLengthDelimited(); final GeneratedMessage msg = value; msg.writeToCodedBufferWriter(this); @@ -459,7 +459,7 @@ class CodedBufferWriter { ) { _writeTag(fieldNumber, wireFormat); _writeValueAs(valueType, value); - if (valueType == PbFieldType._GROUP_BIT) { + if (valueType == PbFieldTypeInternal._GROUP_BIT) { _writeTag(fieldNumber, WIRETYPE_END_GROUP); } } diff --git a/protobuf/lib/src/protobuf/consts.dart b/protobuf/lib/src/protobuf/consts.dart index 227188ac7..caa1484ba 100644 --- a/protobuf/lib/src/protobuf/consts.dart +++ b/protobuf/lib/src/protobuf/consts.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Constant string value of `double.infinity.toString()` and the infinity /// value recognized by `double.parse(..)`. diff --git a/protobuf/lib/src/protobuf/exceptions.dart b/protobuf/lib/src/protobuf/exceptions.dart index 3effb4486..f55e9be0a 100644 --- a/protobuf/lib/src/protobuf/exceptions.dart +++ b/protobuf/lib/src/protobuf/exceptions.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; const _truncatedMessageText = ''' While parsing a protocol message, the input ended unexpectedly diff --git a/protobuf/lib/src/protobuf/extension.dart b/protobuf/lib/src/protobuf/extension.dart index 27743b727..dc37b91fb 100644 --- a/protobuf/lib/src/protobuf/extension.dart +++ b/protobuf/lib/src/protobuf/extension.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// An object representing an extension field. class Extension extends FieldInfo { diff --git a/protobuf/lib/src/protobuf/extension_field_set.dart b/protobuf/lib/src/protobuf/extension_field_set.dart index 9e0664359..bbaa707e2 100644 --- a/protobuf/lib/src/protobuf/extension_field_set.dart +++ b/protobuf/lib/src/protobuf/extension_field_set.dart @@ -2,15 +2,15 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; -class _ExtensionFieldSet { - final _FieldSet _parent; +class ExtensionFieldSet { + final FieldSet _parent; final Map _info = {}; final Map _values = {}; bool _isReadOnly = false; - _ExtensionFieldSet(this._parent); + ExtensionFieldSet(this._parent); Extension? _getInfoOrNull(int tagNumber) => _info[tagNumber]; @@ -157,7 +157,7 @@ class _ExtensionFieldSet { bool get _hasValues => _values.isNotEmpty; - bool _equalValues(_ExtensionFieldSet? other) => + bool _equalValues(ExtensionFieldSet? other) => other != null && _areMapsEqual(_values, other._values); void _clearValues() => _values.clear(); @@ -166,7 +166,7 @@ class _ExtensionFieldSet { /// /// Repeated fields are copied. /// Extensions cannot contain map fields. - void _shallowCopyValues(_ExtensionFieldSet original) { + void _shallowCopyValues(ExtensionFieldSet original) { for (final tagNumber in original._tagNumbers) { final extension = original._getInfoOrNull(tagNumber)!; _addInfoUnchecked(extension); @@ -212,3 +212,9 @@ class _ExtensionFieldSet { } } } + +extension ExtensionFieldSetInternalExtension on ExtensionFieldSet { + Map get values => _values; + Iterable get tagNumbers => _tagNumbers; + Extension? getInfoOrNull(int tagNumber) => _getInfoOrNull(tagNumber); +} diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index bc2f8b468..2535b49c1 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// A collection of [Extension] objects, organized by the message type they /// extend. diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index 6c91a21bd..3a2494055 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Returns the error message for an invalid field value, /// or null if it's valid. @@ -10,53 +10,53 @@ part of '../../protobuf.dart'; /// For enums, group, and message fields, this check is only approximate, /// because the exact type isn't included in [fieldType]. String? _getFieldError(int fieldType, var value) { - switch (PbFieldType._baseType(fieldType)) { - case PbFieldType._BOOL_BIT: + switch (PbFieldTypeInternal._baseType(fieldType)) { + case PbFieldTypeInternal._BOOL_BIT: if (value is! bool) return 'not type bool'; return null; - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: if (value is! List) return 'not List'; return null; - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: if (value is! String) return 'not type String'; return null; - case PbFieldType._FLOAT_BIT: + case PbFieldTypeInternal._FLOAT_BIT: if (value is! double) return 'not type double'; if (!_isFloat32(value)) return 'out of range for float'; return null; - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: if (value is! double) return 'not type double'; return null; - case PbFieldType._ENUM_BIT: + case PbFieldTypeInternal._ENUM_BIT: if (value is! ProtobufEnum) return 'not type ProtobufEnum'; return null; - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: if (value is! int) return 'not type int'; if (!_isSigned32(value)) return 'out of range for signed 32-bit int'; return null; - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: if (value is! int) return 'not type int'; if (!_isUnsigned32(value)) return 'out of range for unsigned 32-bit int'; return null; - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._UINT64_BIT: - case PbFieldType._FIXED64_BIT: - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 if (value is! Int64) return 'not Int64'; return null; - case PbFieldType._GROUP_BIT: - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: if (value is! GeneratedMessage) return 'not a GeneratedMessage'; return null; default: @@ -74,33 +74,33 @@ String? _getFieldError(int fieldType, var value) { /// @nodoc CheckFunc getCheckFunction(int fieldType) { switch (fieldType & ~0x7) { - case PbFieldType._BOOL_BIT: - case PbFieldType._BYTES_BIT: - case PbFieldType._STRING_BIT: - case PbFieldType._DOUBLE_BIT: - case PbFieldType._ENUM_BIT: - case PbFieldType._GROUP_BIT: - case PbFieldType._MESSAGE_BIT: - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._SFIXED64_BIT: - case PbFieldType._UINT64_BIT: - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 return _checkNotNull; - case PbFieldType._FLOAT_BIT: + case PbFieldTypeInternal._FLOAT_BIT: return _checkFloat; - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: return _checkSigned32; - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: return _checkUnsigned32; } throw ArgumentError('check function not implemented: $fieldType'); diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index a30925e26..117aacddc 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// An object representing a protobuf message field. class FieldInfo { @@ -60,12 +60,12 @@ class FieldInfo { /// `tagNumber` of `result_per_page` field is 3. final int tagNumber; - /// Index of the field in [_FieldSet._values] list of this field's message. + /// Index of the field in [FieldSet._values] list of this field's message. /// /// The value is `null` for extension fields. final int? index; - /// Type of this field. See [PbFieldType]. + /// Type of this field. See [PbFieldTypeInternal]. final int type; /// Constructs the default value of a field. @@ -81,17 +81,17 @@ class FieldInfo { /// List of all enum values. /// /// Only available in enum fields. - final List? enumValues; + final List? _enumValues; /// Default enum value. /// /// Only available in enum fields. - final ProtobufEnum? defaultEnumValue; + final ProtobufEnum? _defaultEnumValue; /// Mapping from enum integer values to enum values. /// /// Only available in enum fields. - final ValueOfFunc? valueOf; + final ValueOfFunc? _valueOf; /// Function to verify items when adding to a repeated field. /// @@ -105,13 +105,16 @@ class FieldInfo { this.type, { dynamic defaultOrMaker, this.subBuilder, - this.valueOf, - this.enumValues, - this.defaultEnumValue, + ValueOfFunc? valueOf, + List? enumValues, + ProtobufEnum? defaultEnumValue, String? protoName, }) : makeDefault = findMakeDefault(type, defaultOrMaker), check = null, _protoName = protoName, + _valueOf = valueOf, + _enumValues = enumValues, + _defaultEnumValue = defaultEnumValue, assert(type != 0), assert( !_isGroupOrMessage(type) || subBuilder != null || _isMapField(type), @@ -125,10 +128,10 @@ class FieldInfo { tagNumber = 0, type = 0, makeDefault = null, - valueOf = null, + _valueOf = null, check = null, - enumValues = null, - defaultEnumValue = null, + _enumValues = null, + _defaultEnumValue = null, subBuilder = null; FieldInfo.repeated( @@ -138,17 +141,20 @@ class FieldInfo { this.type, CheckFunc this.check, this.subBuilder, { - this.valueOf, - this.enumValues, - this.defaultEnumValue, + ValueOfFunc? valueOf, + List? enumValues, + ProtobufEnum? defaultEnumValue, String? protoName, }) : makeDefault = (() => PbList(check: check)), _protoName = protoName, + _valueOf = valueOf, + _enumValues = enumValues, + _defaultEnumValue = defaultEnumValue, assert(_isRepeated(type)), assert(!_isEnum(type) || valueOf != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { - if (defaultOrMaker == null) return PbFieldType._defaultForType(type); + if (defaultOrMaker == null) return PbFieldTypeInternal.defaultForType(type); if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; return () => defaultOrMaker; } @@ -238,8 +244,8 @@ class FieldInfo { } /// Convenience method to thread this FieldInfo's reified type parameter to - /// `_FieldSet._ensureRepeatedField`. - PbList _ensureRepeatedField(BuilderInfo meta, _FieldSet fs) { + /// `FieldSet._ensureRepeatedField`. + PbList _ensureRepeatedField(BuilderInfo meta, FieldSet fs) { return fs._ensureRepeatedField(meta, this); } @@ -247,6 +253,17 @@ class FieldInfo { String toString() => name; } +extension FieldInfoInternalExtension on FieldInfo { + List ensureRepeatedField(BuilderInfo meta, FieldSet fs) => + _ensureRepeatedField(meta, fs); +} + +extension EnumFieldInfoExtension on FieldInfo { + ValueOfFunc? get valueOf => _valueOf; + List? get enumValues => _enumValues; + ProtobufEnum? get defaultEnumValue => _defaultEnumValue; +} + final RegExp _upperCase = RegExp('[A-Z]'); String _unCamelCase(String name) { @@ -304,7 +321,7 @@ class MapFieldInfo extends FieldInfo?> { FieldInfo get valueFieldInfo => mapEntryBuilderInfo.fieldInfo[PbMap._valueFieldNumber]!; - PbMap _ensureMapField(BuilderInfo meta, _FieldSet fs) { + PbMap _ensureMapField(BuilderInfo meta, FieldSet fs) { return fs._ensureMapField(meta, this); } @@ -313,3 +330,8 @@ class MapFieldInfo extends FieldInfo?> { return PbMap(keyFieldType, valueFieldType); } } + +extension MapFieldInfoInternalExtension on MapFieldInfo { + Map ensureMapField(BuilderInfo meta, FieldSet fs) => + _ensureMapField(meta, fs); +} diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index ec73665b0..64afd3908 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; @pragma('vm:never-inline') @pragma('wasm:never-inline') @@ -25,7 +25,7 @@ void _throwFrozenMessageModificationError( /// These fields and methods are in a separate class to avoid polymorphic /// access due to inheritance. This turns out to be faster when compiled to /// JavaScript. -class _FieldSet { +class FieldSet { final GeneratedMessage? _message; /// The value of each non-extension field in a fixed-length array. @@ -34,7 +34,7 @@ class _FieldSet { final List _values; /// Contains all the extension fields, or null if there aren't any. - _ExtensionFieldSet? _extensions; + ExtensionFieldSet? _extensions; /// Contains all the unknown fields, or null if there aren't any. UnknownFieldSet? _unknownFields; @@ -53,7 +53,7 @@ class _FieldSet { /// code as an `int`. Object _frozenState = false; - /// The [BuilderInfo] for the [GeneratedMessage] this [_FieldSet] belongs to. + /// The [BuilderInfo] for the [GeneratedMessage] this [FieldSet] belongs to. /// /// WARNING: Avoid calling this for any performance critical code, instead /// obtain the [BuilderInfo] on the call site. @@ -82,7 +82,7 @@ class _FieldSet { /// the index is not present, the oneof field is unset. final Map? _oneofCases; - _FieldSet(this._message, BuilderInfo meta) + FieldSet(this._message, BuilderInfo meta) : _values = _makeValueList(meta.byIndex.length), _oneofCases = meta.oneofs.isEmpty ? null : {}; @@ -106,8 +106,8 @@ class _FieldSet { /// The [FieldInfo] for each non-extension field in tag order. Iterable get _infosSortedByTag => _meta.sortedByTag; - _ExtensionFieldSet _ensureExtensions() => - _extensions ??= _ExtensionFieldSet(this); + ExtensionFieldSet _ensureExtensions() => + _extensions ??= ExtensionFieldSet(this); UnknownFieldSet _ensureUnknownFields() { if (_unknownFields == null) { @@ -510,7 +510,7 @@ class _FieldSet { _extensions?._clearValues(); } - bool _equals(_FieldSet o) { + bool _equals(FieldSet o) { if (_meta != o._meta) return false; for (var i = 0; i < _values.length; i++) { if (!_equalFieldValues(_values[i], o._values[i])) return false; @@ -716,7 +716,7 @@ class _FieldSet { /// Singular fields that are set in [other] overwrite the corresponding fields /// in this message. Repeated fields are appended. Singular sub-messages are /// recursively merged. - void _mergeFromMessage(_FieldSet other) { + void _mergeFromMessage(FieldSet other) { // TODO(https://github.com/google/protobuf.dart/issues/60): Recognize // when `this` and [other] are the same protobuf (e.g. from cloning). In // this case, we can merge the non-extension fields without field lookups or @@ -880,7 +880,7 @@ class _FieldSet { /// Makes a shallow copy of all values from [original] to this. /// /// Map fields and repeated fields are copied. - void _shallowCopyValues(_FieldSet original) { + void _shallowCopyValues(FieldSet original) { _values.setRange(0, original._values.length, original._values); final info = _meta; for (var index = 0; index < info.byIndex.length; index++) { @@ -917,3 +917,26 @@ class _FieldSet { _oneofCases?.addAll(original._oneofCases!); } } + +extension FieldSetInternalExtension on FieldSet { + Iterable get infos => _infos; + Iterable get infosSortedByTag => _infosSortedByTag; + List get values => _values; + ExtensionFieldSet? get extensions => _extensions; + UnknownFieldSet? get unknownFields => _unknownFields; + Map? get unknownJsonData => _unknownJsonData; + set unknownJsonData(Map? value) => _unknownJsonData = value; + BuilderInfo get meta => _meta; + GeneratedMessage? get message => _message; + String get messageName => _messageName; + + void ensureWritable() => _ensureWritable(); + PbList ensureRepeatedField(BuilderInfo meta, FieldInfo fi) => + _ensureRepeatedField(meta, fi); + PbMap ensureMapField(BuilderInfo meta, MapFieldInfo fi) => + _ensureMapField(meta, fi); + void validateField(FieldInfo fi, dynamic newValue) => + _validateField(fi, newValue); + void setFieldUnchecked(BuilderInfo meta, FieldInfo fi, dynamic value) => + _setFieldUnchecked(meta, fi, value); +} diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index cb6a1a47f..80ed423bd 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -3,31 +3,36 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: constant_identifier_names,non_constant_identifier_names -part of '../../protobuf.dart'; +part of 'internal.dart'; -bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; +bool _isRepeated(int fieldType) => + (fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0; -bool _isRequired(int fieldType) => (fieldType & PbFieldType._REQUIRED_BIT) != 0; +bool _isRequired(int fieldType) => + (fieldType & PbFieldTypeInternal._REQUIRED_BIT) != 0; bool _isEnum(int fieldType) => - PbFieldType._baseType(fieldType) == PbFieldType._ENUM_BIT; + PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._ENUM_BIT; bool _isBytes(int fieldType) => - PbFieldType._baseType(fieldType) == PbFieldType._BYTES_BIT; + PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._BYTES_BIT; bool _isGroupOrMessage(int fieldType) => - (fieldType & (PbFieldType._GROUP_BIT | PbFieldType._MESSAGE_BIT)) != 0; + (fieldType & + (PbFieldTypeInternal._GROUP_BIT | PbFieldTypeInternal._MESSAGE_BIT)) != + 0; -bool _isMapField(int fieldType) => (fieldType & PbFieldType._MAP_BIT) != 0; +bool _isMapField(int fieldType) => + (fieldType & PbFieldTypeInternal._MAP_BIT) != 0; /// Defines constants and functions for dealing with fieldType bits. -class PbFieldType { +class PbFieldTypeInternal { /// Returns the base field type without any of the required, repeated /// and packed bits. static int _baseType(int fieldType) => fieldType & ~(_REQUIRED_BIT | _REPEATED_BIT | _PACKED_BIT | _MAP_BIT); - static MakeDefaultFunc? _defaultForType(int type) { + static MakeDefaultFunc? defaultForType(int type) { switch (type) { case _OPTIONAL_BOOL: case _REQUIRED_BOOL: diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 7cf6a0a11..28f4992b0 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -4,7 +4,7 @@ // ignore_for_file: non_constant_identifier_names -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Type of an empty message builder. typedef CreateBuilderFunc = GeneratedMessage Function(); @@ -25,13 +25,13 @@ typedef ValueOfFunc = ProtobufEnum? Function(int value); /// `GeneratedMessage_reservedNames` and should be unlikely to be used in a /// proto file. abstract class GeneratedMessage { - _FieldSet? __fieldSet; + FieldSet? __fieldSet; @pragma('dart2js:tryInline') - _FieldSet get _fieldSet => __fieldSet!; + FieldSet get _fieldSet => __fieldSet!; GeneratedMessage() { - __fieldSet = _FieldSet(this, info_); + __fieldSet = FieldSet(this, info_); // The following two returns confuse dart2js into avoiding inlining the // constructor *body*. A `@pragma('dart2js:never-inline')` annotation on @@ -637,3 +637,7 @@ extension GeneratedMessageGenericExtensions on T { ) T deepCopy() => info_.createEmptyInstance!() as T..mergeFromMessage(this); } + +extension GeneratedMessageInternalExtension on GeneratedMessage { + FieldSet get fieldSet => _fieldSet; +} diff --git a/protobuf/lib/src/protobuf/generated_service.dart b/protobuf/lib/src/protobuf/generated_service.dart index f2b8857ed..fc6feae30 100644 --- a/protobuf/lib/src/protobuf/generated_service.dart +++ b/protobuf/lib/src/protobuf/generated_service.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Server side context. class ServerContext { diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart new file mode 100644 index 000000000..d7d23a500 --- /dev/null +++ b/protobuf/lib/src/protobuf/internal.dart @@ -0,0 +1,67 @@ +// Copyright (c) 2011, 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. + +/// Runtime library for Dart implementation of [protobufs][1]. +/// +/// [1]: https://developers.google.com/protocol-buffers +library; + +import 'dart:collection' show ListBase, MapBase; +import 'dart:convert' + show + Utf8Decoder, + Utf8Encoder, + base64Decode, + base64Encode, + jsonDecode, + jsonEncode; +import 'dart:math' as math; +import 'dart:typed_data' show ByteData, Endian, Uint8List; + +import 'package:fixnum/fixnum.dart' show Int64; +import 'package:meta/meta.dart' show UseResult; + +import 'json_parsing_context.dart'; +import 'permissive_compare.dart'; +import 'type_registry.dart'; + +export 'type_registry.dart' show TypeRegistry; + +part 'annotations.dart'; +part 'builder_info.dart'; +part 'coded_buffer.dart'; +part 'coded_buffer_reader.dart'; +part 'coded_buffer_writer.dart'; +part 'consts.dart'; +part 'exceptions.dart'; +part 'extension.dart'; +part 'extension_field_set.dart'; +part 'extension_registry.dart'; +part 'field_error.dart'; +part 'field_info.dart'; +part 'field_set.dart'; +part 'field_type.dart'; +part 'generated_message.dart'; +part 'generated_service.dart'; +part 'json.dart'; +part 'message_set.dart'; +part 'pb_list.dart'; +part 'pb_map.dart'; +part 'proto3_json.dart'; +part 'protobuf_enum.dart'; +part 'rpc_client.dart'; +part 'unknown_field_set.dart'; +part 'unpack.dart'; +part 'utils.dart'; +part 'wire_format.dart'; + +// TODO(sra): Use `Int64.parse()` when available: +// https://github.com/dart-lang/fixnum/issues/18. +/// @nodoc +Int64 parseLongInt(String text) { + if (text.startsWith('0x')) return Int64.parseHex(text.substring(2)); + if (text.startsWith('+0x')) return Int64.parseHex(text.substring(3)); + if (text.startsWith('-0x')) return -Int64.parseHex(text.substring(3)); + return Int64.parseInt(text); +} diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index 75d4fa86c..5cb340491 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -2,11 +2,11 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; -Map _writeToJsonMap(_FieldSet fs) { +Map _writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { - final baseType = PbFieldType._baseType(fieldType); + final baseType = PbFieldTypeInternal._baseType(fieldType); if (_isRepeated(fieldType)) { final PbList list = fieldValue; @@ -14,16 +14,16 @@ Map _writeToJsonMap(_FieldSet fs) { } switch (baseType) { - case PbFieldType._BOOL_BIT: - case PbFieldType._STRING_BIT: - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: return fieldValue; - case PbFieldType._FLOAT_BIT: - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { return _nan; @@ -35,22 +35,22 @@ Map _writeToJsonMap(_FieldSet fs) { return fieldValue.toInt(); } return value; - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: // Encode 'bytes' as a base64-encoded string. return base64Encode(fieldValue as List); - case PbFieldType._ENUM_BIT: + case PbFieldTypeInternal._ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value; // assume |value| < 2^52 - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: return fieldValue.toString(); - case PbFieldType._UINT64_BIT: - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned(); - case PbFieldType._GROUP_BIT: - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: @@ -105,7 +105,7 @@ Map _writeToJsonMap(_FieldSet fs) { // Merge fields from a previously decoded JSON object. // (Called recursively on nested messages.) void _mergeFromJsonMap( - _FieldSet fs, + FieldSet fs, Map json, ExtensionRegistry? registry, ) { @@ -139,7 +139,7 @@ void _mergeFromJsonMap( void _appendJsonList( BuilderInfo meta, - _FieldSet fs, + FieldSet fs, List jsonList, FieldInfo fi, ExtensionRegistry? registry, @@ -169,7 +169,7 @@ void _appendJsonList( void _appendJsonMap( BuilderInfo meta, - _FieldSet fs, + FieldSet fs, List jsonList, MapFieldInfo fi, ExtensionRegistry? registry, @@ -178,7 +178,7 @@ void _appendJsonMap( final map = fi._ensureMapField(meta, fs); for (final jsonEntryDynamic in jsonList) { final jsonEntry = jsonEntryDynamic as Map; - final entryFieldSet = _FieldSet(null, entryMeta); + final entryFieldSet = FieldSet(null, entryMeta); final convertedKey = _convertJsonValue( entryMeta, entryFieldSet, @@ -205,7 +205,7 @@ void _appendJsonMap( void _setJsonField( BuilderInfo meta, - _FieldSet fs, + FieldSet fs, json, FieldInfo fi, ExtensionRegistry? registry, @@ -239,15 +239,15 @@ void _setJsonField( /// Throws [ArgumentError] if it cannot convert the value. dynamic _convertJsonValue( BuilderInfo meta, - _FieldSet fs, + FieldSet fs, value, int tagNumber, int fieldType, ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldType._baseType(fieldType)) { - case PbFieldType._BOOL_BIT: + switch (PbFieldTypeInternal._baseType(fieldType)) { + case PbFieldTypeInternal._BOOL_BIT: if (value is bool) { return value; } else if (value is String) { @@ -265,20 +265,20 @@ dynamic _convertJsonValue( } expectedType = 'bool (true, false, "true", "false", 1, 0)'; break; - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: if (value is String) { return base64Decode(value); } expectedType = 'Base64 String'; break; - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: if (value is String) { return value; } expectedType = 'String'; break; - case PbFieldType._FLOAT_BIT: - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value is double) { return value; @@ -289,7 +289,7 @@ dynamic _convertJsonValue( } expectedType = 'num or stringified num'; break; - case PbFieldType._ENUM_BIT: + case PbFieldTypeInternal._ENUM_BIT: // Allow quoted values, although we don't emit them. if (value is String) { value = int.parse(value); @@ -302,15 +302,15 @@ dynamic _convertJsonValue( } expectedType = 'int or stringified int'; break; - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: if (value is int) return value; if (value is String) return int.parse(value); expectedType = 'int or stringified int'; break; - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: int? validatedValue; if (value is int) validatedValue = value; if (value is String) validatedValue = int.parse(value); @@ -320,17 +320,17 @@ dynamic _convertJsonValue( if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; break; - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._UINT64_BIT: - case PbFieldType._FIXED64_BIT: - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) return Int64.parseInt(value); expectedType = 'int or stringified int'; break; - case PbFieldType._GROUP_BIT: - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; final subMessage = meta._makeEmptyMessage(tagNumber, registry); diff --git a/protobuf/lib/src/protobuf/message_set.dart b/protobuf/lib/src/protobuf/message_set.dart index 9a0213172..dfae87708 100644 --- a/protobuf/lib/src/protobuf/message_set.dart +++ b/protobuf/lib/src/protobuf/message_set.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; const _messageSetItemsTag = 1; const _messageSetItemTypeIdTag = 2; diff --git a/protobuf/lib/src/protobuf/pb_list.dart b/protobuf/lib/src/protobuf/pb_list.dart index 9d880f557..be9dc9663 100644 --- a/protobuf/lib/src/protobuf/pb_list.dart +++ b/protobuf/lib/src/protobuf/pb_list.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Type of a function that checks items added to a `PbList`. /// diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 44337fb26..130e80a72 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// A [MapBase] implementation used for protobuf `map` fields. class PbMap extends MapBase { @@ -108,7 +108,7 @@ class PbMap extends MapBase { final length = input.readInt32(); final oldLimit = input._currentLimit; input._currentLimit = input._bufferPos + length; - final entryFieldSet = _FieldSet(null, mapEntryMeta); + final entryFieldSet = FieldSet(null, mapEntryMeta); _mergeFromCodedBufferReader(mapEntryMeta, entryFieldSet, input, registry); input.checkLastTagWas(0); input._currentLimit = oldLimit; diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index c2bbf29c7..134b5aaba 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -2,30 +2,30 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; -Object? _writeToProto3Json(_FieldSet fs, TypeRegistry typeRegistry) { +Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { - final baseType = PbFieldType._baseType(keyType); + final baseType = PbFieldTypeInternal._baseType(keyType); assert(!_isRepeated(keyType)); switch (baseType) { - case PbFieldType._BOOL_BIT: + case PbFieldTypeInternal._BOOL_BIT: return key ? 'true' : 'false'; - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: return key; - case PbFieldType._UINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: return (key as Int64).toStringUnsigned(); - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: - case PbFieldType._SFIXED32_BIT: - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._SFIXED64_BIT: - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: return key.toString(); default: throw StateError('Not a valid key type $keyType'); @@ -43,25 +43,25 @@ Object? _writeToProto3Json(_FieldSet fs, TypeRegistry typeRegistry) { } else if (_isEnum(fieldType)) { return (fieldValue as ProtobufEnum).name; } else { - final baseType = PbFieldType._baseType(fieldType); + final baseType = PbFieldTypeInternal._baseType(fieldType); switch (baseType) { - case PbFieldType._BOOL_BIT: + case PbFieldTypeInternal._BOOL_BIT: return fieldValue as bool; - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: return fieldValue; - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: return fieldValue; - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._SFIXED64_BIT: - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: return fieldValue.toString(); - case PbFieldType._FLOAT_BIT: - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return _nan; @@ -73,9 +73,9 @@ Object? _writeToProto3Json(_FieldSet fs, TypeRegistry typeRegistry) { return value.toInt(); } return value; - case PbFieldType._UINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: return (fieldValue as Int64).toStringUnsigned(); - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: return base64Encode(fieldValue); default: throw StateError( @@ -160,7 +160,7 @@ extension _FindFirst on Iterable { /// to [fieldSet]. void _mergeFromProto3Json( Object? json, - _FieldSet fieldSet, + FieldSet fieldSet, TypeRegistry typeRegistry, bool ignoreUnknownFields, bool supportNamesWithUnderscores, @@ -173,16 +173,16 @@ void _mergeFromProto3Json( permissiveEnums, ); - void recursionHelper(Object? json, _FieldSet fieldSet) { + void recursionHelper(Object? json, FieldSet fieldSet) { Object? convertProto3JsonValue(Object value, FieldInfo fieldInfo) { final fieldType = fieldInfo.type; - switch (PbFieldType._baseType(fieldType)) { - case PbFieldType._BOOL_BIT: + switch (PbFieldTypeInternal._baseType(fieldType)) { + case PbFieldTypeInternal._BOOL_BIT: if (value is bool) { return value; } throw context.parseException('Expected bool value', json); - case PbFieldType._BYTES_BIT: + case PbFieldTypeInternal._BYTES_BIT: if (value is String) { Uint8List result; try { @@ -199,13 +199,13 @@ void _mergeFromProto3Json( 'Expected bytes encoded as base64 String', value, ); - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: if (value is String) { return value; } throw context.parseException('Expected String value', value); - case PbFieldType._FLOAT_BIT: - case PbFieldType._DOUBLE_BIT: + case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: if (value is double) { return value; } else if (value is num) { @@ -221,7 +221,7 @@ void _mergeFromProto3Json( 'Expected a double represented as a String or number', value, ); - case PbFieldType._ENUM_BIT: + case PbFieldTypeInternal._ENUM_BIT: if (value is String) { // TODO(sigurdm): Do we want to avoid linear search here? Measure... final result = @@ -245,8 +245,8 @@ void _mergeFromProto3Json( 'Expected enum as a string or integer', value, ); - case PbFieldType._UINT32_BIT: - case PbFieldType._FIXED32_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: int result; if (value is int) { result = value; @@ -259,9 +259,9 @@ void _mergeFromProto3Json( ); } return _check32BitUnsignedProto3(result, context); - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: int result; if (value is int) { result = value; @@ -275,7 +275,7 @@ void _mergeFromProto3Json( } _check32BitSignedProto3(result, context); return result; - case PbFieldType._UINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: Int64 result; if (value is int) { result = Int64(value); @@ -288,10 +288,10 @@ void _mergeFromProto3Json( ); } return result; - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._FIXED64_BIT: - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) { Int64 result; @@ -309,8 +309,8 @@ void _mergeFromProto3Json( 'Expected int or stringified int', value, ); - case PbFieldType._GROUP_BIT: - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: final subMessage = fieldInfo.subBuilder!(); recursionHelper(value, subMessage._fieldSet); return subMessage; @@ -320,8 +320,8 @@ void _mergeFromProto3Json( } Object decodeMapKey(String key, int fieldType) { - switch (PbFieldType._baseType(fieldType)) { - case PbFieldType._BOOL_BIT: + switch (PbFieldTypeInternal._baseType(fieldType)) { + case PbFieldTypeInternal._BOOL_BIT: switch (key) { case 'true': return true; @@ -333,26 +333,26 @@ void _mergeFromProto3Json( key, ); } - case PbFieldType._STRING_BIT: + case PbFieldTypeInternal._STRING_BIT: return key; - case PbFieldType._UINT64_BIT: + case PbFieldTypeInternal._UINT64_BIT: // TODO(sigurdm): We do not throw on negative values here. // That would probably require going via bignum. return _tryParse64BitProto3(json, key, context); - case PbFieldType._INT64_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._SFIXED64_BIT: - case PbFieldType._FIXED64_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal._FIXED64_BIT: return _tryParse64BitProto3(json, key, context); - case PbFieldType._INT32_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._FIXED32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: return _check32BitSignedProto3( _tryParse32BitProto3(key, context), context, ); - case PbFieldType._UINT32_BIT: + case PbFieldTypeInternal._UINT32_BIT: return _check32BitUnsignedProto3( _tryParse32BitProto3(key, context), context, diff --git a/protobuf/lib/src/protobuf/protobuf_enum.dart b/protobuf/lib/src/protobuf/protobuf_enum.dart index 73779fb25..5ec61a0a8 100644 --- a/protobuf/lib/src/protobuf/protobuf_enum.dart +++ b/protobuf/lib/src/protobuf/protobuf_enum.dart @@ -4,7 +4,7 @@ // ignore_for_file: non_constant_identifier_names -part of '../../protobuf.dart'; +part of 'internal.dart'; /// A base class for all proto enum types. /// diff --git a/protobuf/lib/src/protobuf/rpc_client.dart b/protobuf/lib/src/protobuf/rpc_client.dart index 6239674e3..7f091f08a 100644 --- a/protobuf/lib/src/protobuf/rpc_client.dart +++ b/protobuf/lib/src/protobuf/rpc_client.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Client side context for [RpcClient]s. class ClientContext { diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index b0579a913..fe1487398 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// A set of unknown fields in a [GeneratedMessage]. class UnknownFieldSet { @@ -283,11 +283,11 @@ class UnknownFieldSetField { output.writeField(fieldNumber, type, value); } - write(PbFieldType._REPEATED_UINT64, varints); - write(PbFieldType._REPEATED_FIXED32, fixed32s); - write(PbFieldType._REPEATED_FIXED64, fixed64s); - write(PbFieldType._REPEATED_BYTES, lengthDelimited); - write(PbFieldType._REPEATED_GROUP, groups); + write(PbFieldTypeInternal._REPEATED_UINT64, varints); + write(PbFieldTypeInternal._REPEATED_FIXED32, fixed32s); + write(PbFieldTypeInternal._REPEATED_FIXED64, fixed64s); + write(PbFieldTypeInternal._REPEATED_BYTES, lengthDelimited); + write(PbFieldTypeInternal._REPEATED_GROUP, groups); } void addGroup(UnknownFieldSet value) { diff --git a/protobuf/lib/src/protobuf/unpack.dart b/protobuf/lib/src/protobuf/unpack.dart index aed3260bf..08d547606 100644 --- a/protobuf/lib/src/protobuf/unpack.dart +++ b/protobuf/lib/src/protobuf/unpack.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; /// Unpacks the message in [value] into [instance]. /// diff --git a/protobuf/lib/src/protobuf/utils.dart b/protobuf/lib/src/protobuf/utils.dart index 4a6b0885a..37e4280ec 100644 --- a/protobuf/lib/src/protobuf/utils.dart +++ b/protobuf/lib/src/protobuf/utils.dart @@ -2,7 +2,7 @@ // 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. -part of '../../protobuf.dart'; +part of 'internal.dart'; // TODO(antonm): reconsider later if PbList should take care of equality. bool _deepEquals(Object lhs, Object rhs) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index a255c8176..6a2536270 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -4,7 +4,7 @@ // ignore_for_file: constant_identifier_names -part of '../../protobuf.dart'; +part of 'internal.dart'; const int _TAG_TYPE_BITS = 3; const int _TAG_TYPE_MASK = (1 << _TAG_TYPE_BITS) - 1; @@ -38,32 +38,32 @@ int makeTag(int fieldNumber, int tag) => (fieldNumber << _TAG_TYPE_BITS) | tag; /// Returns true if the wireType can be merged into the given fieldType. bool _wireTypeMatches(int fieldType, int wireType) { - switch (PbFieldType._baseType(fieldType)) { - case PbFieldType._BOOL_BIT: - case PbFieldType._ENUM_BIT: - case PbFieldType._INT32_BIT: - case PbFieldType._INT64_BIT: - case PbFieldType._SINT32_BIT: - case PbFieldType._SINT64_BIT: - case PbFieldType._UINT32_BIT: - case PbFieldType._UINT64_BIT: + switch (PbFieldTypeInternal._baseType(fieldType)) { + case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal._UINT64_BIT: return wireType == WIRETYPE_VARINT || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldType._FLOAT_BIT: - case PbFieldType._FIXED32_BIT: - case PbFieldType._SFIXED32_BIT: + case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal._SFIXED32_BIT: return wireType == WIRETYPE_FIXED32 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldType._DOUBLE_BIT: - case PbFieldType._FIXED64_BIT: - case PbFieldType._SFIXED64_BIT: + case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal._SFIXED64_BIT: return wireType == WIRETYPE_FIXED64 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldType._BYTES_BIT: - case PbFieldType._STRING_BIT: - case PbFieldType._MESSAGE_BIT: + case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal._MESSAGE_BIT: return wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldType._GROUP_BIT: + case PbFieldTypeInternal._GROUP_BIT: return wireType == WIRETYPE_START_GROUP; default: return false; diff --git a/protobuf/test/codec_test.dart b/protobuf/test/codec_test.dart index 215e90d7f..650259c1e 100644 --- a/protobuf/test/codec_test.dart +++ b/protobuf/test/codec_test.dart @@ -29,7 +29,7 @@ void main() { }; } - final int32ToBytes = convertToBytes(PbFieldType.O3); + final int32ToBytes = convertToBytes(PbFieldTypeInternal.O3); test('testInt32RoundTrips', () { final roundtrip = roundtripTester( @@ -60,7 +60,7 @@ void main() { test('testSint32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint32(), - toBytes: convertToBytes(PbFieldType.OS3), + toBytes: convertToBytes(PbFieldTypeInternal.OS3), ); roundtrip(0, [0x00]); @@ -72,7 +72,7 @@ void main() { test('testSint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint64(), - toBytes: convertToBytes(PbFieldType.OS6), + toBytes: convertToBytes(PbFieldTypeInternal.OS6), ); roundtrip(make64(0), [0x00]); @@ -84,7 +84,7 @@ void main() { test('testFixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed32(), - toBytes: convertToBytes(PbFieldType.OF3), + toBytes: convertToBytes(PbFieldTypeInternal.OF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -96,7 +96,7 @@ void main() { test('testFixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed64(), - toBytes: convertToBytes(PbFieldType.OF6), + toBytes: convertToBytes(PbFieldTypeInternal.OF6), ); roundtrip(make64(0, 0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -126,7 +126,7 @@ void main() { test('testSfixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed32(), - toBytes: convertToBytes(PbFieldType.OSF3), + toBytes: convertToBytes(PbFieldTypeInternal.OSF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -138,7 +138,7 @@ void main() { test('testSfixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed64(), - toBytes: convertToBytes(PbFieldType.OSF6), + toBytes: convertToBytes(PbFieldTypeInternal.OSF6), ); roundtrip(make64(0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -183,7 +183,7 @@ void main() { : equals(expected); List dataToBytes(ByteData byteData) => Uint8List.view(byteData.buffer); - final floatToBytes = convertToBytes(PbFieldType.OF); + final floatToBytes = convertToBytes(PbFieldTypeInternal.OF); int floatToBits(double value) => makeData(floatToBytes(value)).getUint32(0, Endian.little); @@ -197,7 +197,7 @@ void main() { expect(readFloat(bits), doubleEquals(value)); } - final doubleToBytes = convertToBytes(PbFieldType.OD); + final doubleToBytes = convertToBytes(PbFieldTypeInternal.OD); void test64(List hilo, double value) { // Encode a double to its wire format. @@ -732,7 +732,7 @@ void main() { test('testVarint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readUint64(), - toBytes: convertToBytes(PbFieldType.OU6), + toBytes: convertToBytes(PbFieldTypeInternal.OU6), ); roundtrip(make64(0), [0x00]); @@ -794,7 +794,8 @@ void main() { }); test('testWriteTo', () { - final writer = CodedBufferWriter()..writeField(0, PbFieldType.O3, 1337); + final writer = + CodedBufferWriter()..writeField(0, PbFieldTypeInternal.O3, 1337); expect(writer.lengthInBytes, 3); final buffer = Uint8List(5); buffer[0] = 0x55; diff --git a/protobuf/test/list_test.dart b/protobuf/test/list_test.dart index 23e995100..319b730d9 100644 --- a/protobuf/test/list_test.dart +++ b/protobuf/test/list_test.dart @@ -98,7 +98,9 @@ void main() { }); test('PbList for signed int32 validates items', () { - final List list = PbList(check: getCheckFunction(PbFieldType.P3)); + final List list = PbList( + check: getCheckFunction(PbFieldTypeInternal.P3), + ); expect(() { list.add(-2147483649); @@ -126,7 +128,9 @@ void main() { }); test('PBList for unsigned int32 validates items', () { - final List list = PbList(check: getCheckFunction(PbFieldType.PU3)); + final List list = PbList( + check: getCheckFunction(PbFieldTypeInternal.PU3), + ); expect(() { list.add(-1); @@ -154,7 +158,9 @@ void main() { }); test('PbList for float validates items', () { - final List list = PbList(check: getCheckFunction(PbFieldType.PF)); + final List list = PbList( + check: getCheckFunction(PbFieldTypeInternal.PF), + ); expect(() { list.add(3.4028234663852886E39); diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index fdd385ea3..8b5edd66d 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -9,22 +9,28 @@ import 'package:protobuf/protobuf.dart' BuilderInfo, CreateBuilderFunc, GeneratedMessage, - PbFieldType, + PbFieldTypeInternal, ProtobufEnum; final mockEnumValues = [ProtobufEnum(1, 'a'), ProtobufEnum(2, 'b')]; BuilderInfo mockInfo(String className, CreateBuilderFunc create) { return BuilderInfo(className, createEmptyInstance: create) - ..a(1, 'val', PbFieldType.O3, defaultOrMaker: 42) - ..a(2, 'str', PbFieldType.OS) - ..a(3, 'child', PbFieldType.OM, defaultOrMaker: create, subBuilder: create) - ..p(4, 'int32s', PbFieldType.P3) - ..a(5, 'int64', PbFieldType.O6) + ..a(1, 'val', PbFieldTypeInternal.O3, defaultOrMaker: 42) + ..a(2, 'str', PbFieldTypeInternal.OS) + ..a( + 3, + 'child', + PbFieldTypeInternal.OM, + defaultOrMaker: create, + subBuilder: create, + ) + ..p(4, 'int32s', PbFieldTypeInternal.P3) + ..a(5, 'int64', PbFieldTypeInternal.O6) // 6 is reserved for extensions in other tests. ..e( 7, 'enm', - PbFieldType.OE, + PbFieldTypeInternal.OE, defaultOrMaker: mockEnumValues.first, valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), enumValues: mockEnumValues, diff --git a/protobuf/test/readonly_message_test.dart b/protobuf/test/readonly_message_test.dart index cf5b37d59..dba11f208 100644 --- a/protobuf/test/readonly_message_test.dart +++ b/protobuf/test/readonly_message_test.dart @@ -3,7 +3,11 @@ // BSD-style license that can be found in the LICENSE file. import 'package:protobuf/protobuf.dart' - show BuilderInfo, GeneratedMessage, PbFieldType, UnknownFieldSetField; + show + BuilderInfo, + GeneratedMessage, + PbFieldTypeInternal, + UnknownFieldSetField; import 'package:test/test.dart'; Matcher throwsUnsupportedError(Matcher expectedMessage) => throwsA( @@ -23,9 +27,9 @@ class Rec extends GeneratedMessage { @override BuilderInfo info_ = BuilderInfo('rec') - ..a(1, 'value', PbFieldType.O3) - ..pc(2, 'sub', PbFieldType.PM, subBuilder: Rec.create) - ..p(10, 'ints', PbFieldType.P3); + ..a(1, 'value', PbFieldTypeInternal.O3) + ..pc(2, 'sub', PbFieldTypeInternal.PM, subBuilder: Rec.create) + ..p(10, 'ints', PbFieldTypeInternal.P3); int get value => $_get(0, 0); set value(int v) { diff --git a/protoc_plugin/lib/src/base_type.dart b/protoc_plugin/lib/src/base_type.dart index 0f5d08c60..6a96832c6 100644 --- a/protoc_plugin/lib/src/base_type.dart +++ b/protoc_plugin/lib/src/base_type.dart @@ -12,7 +12,7 @@ class BaseType { /// The name of the Dart type when in the same package. final String unprefixed; - /// The suffix of the constant for this type in PbFieldType. + /// The suffix of the constant for this type in PbFieldTypeInternal. /// (For example, 'B' for boolean or '3' for int32.) final String typeConstantSuffix; diff --git a/protoc_plugin/lib/src/gen/dart_options.pb.dart b/protoc_plugin/lib/src/gen/dart_options.pb.dart index 5534342aa..8b53eb43f 100644 --- a/protoc_plugin/lib/src/gen/dart_options.pb.dart +++ b/protoc_plugin/lib/src/gen/dart_options.pb.dart @@ -125,7 +125,8 @@ class Imports extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Imports', package: const $pb.PackageName(_omitMessageNames ? '' : 'dart_options'), createEmptyInstance: create) - ..pc(1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, + ..pc( + 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldTypeInternal.PM, subBuilder: DartMixin.create) ..hasRequiredFields = false; @@ -165,44 +166,44 @@ class Dart_options { _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'imports', 28125061, - $pb.PbFieldType.OM, + $pb.PbFieldTypeInternal.OM, defaultOrMaker: Imports.getDefault, subBuilder: Imports.create); static final defaultMixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'defaultMixin', 96128839, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static final mixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.MessageOptions', _omitFieldNames ? '' : 'mixin', 96128839, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static final overrideGetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideGetter', 28205290, - $pb.PbFieldType.OB); + $pb.PbFieldTypeInternal.OB); static final overrideSetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideSetter', 28937366, - $pb.PbFieldType.OB); + $pb.PbFieldTypeInternal.OB); static final overrideHasMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideHasMethod', 28937461, - $pb.PbFieldType.OB); + $pb.PbFieldTypeInternal.OB); static final overrideClearMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideClearMethod', 28907907, - $pb.PbFieldType.OB); + $pb.PbFieldTypeInternal.OB); static final dartName = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'dartName', 28700919, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(imports); registry.add(defaultMixin); diff --git a/protoc_plugin/lib/src/gen/google/api/client.pb.dart b/protoc_plugin/lib/src/gen/google/api/client.pb.dart index 4660db8c8..16590b7f6 100644 --- a/protoc_plugin/lib/src/gen/google/api/client.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/client.pb.dart @@ -53,7 +53,7 @@ class CommonLanguageSettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'referenceDocsUri') ..pc( - 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldType.KE, + 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldTypeInternal.KE, valueOf: ClientLibraryDestination.valueOf, enumValues: ClientLibraryDestination.values, defaultEnumValue: @@ -164,7 +164,7 @@ class ClientLibrarySettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'version') ..e<$1.LaunchStage>( - 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldType.OE, + 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldTypeInternal.OE, defaultOrMaker: $1.LaunchStage.LAUNCH_STAGE_UNSPECIFIED, valueOf: $1.LaunchStage.valueOf, enumValues: $1.LaunchStage.values) @@ -389,7 +389,7 @@ class Publishing extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldTypeInternal.PM, subBuilder: MethodSettings.create) ..aOS(101, _omitFieldNames ? '' : 'newIssueUri') ..aOS(102, _omitFieldNames ? '' : 'documentationUri') @@ -398,13 +398,13 @@ class Publishing extends $pb.GeneratedMessage { ..pPS(105, _omitFieldNames ? '' : 'codeownerGithubTeams') ..aOS(106, _omitFieldNames ? '' : 'docTagPrefix') ..e( - 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldType.OE, + 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldTypeInternal.OE, defaultOrMaker: ClientLibraryOrganization.CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED, valueOf: ClientLibraryOrganization.valueOf, enumValues: ClientLibraryOrganization.values) - ..pc( - 109, _omitFieldNames ? '' : 'librarySettings', $pb.PbFieldType.PM, + ..pc(109, _omitFieldNames ? '' : 'librarySettings', + $pb.PbFieldTypeInternal.PM, subBuilder: ClientLibrarySettings.create) ..aOS(110, _omitFieldNames ? '' : 'protoReferenceDocumentationUri') ..aOS(111, _omitFieldNames ? '' : 'restReferenceDocumentationUri') @@ -568,8 +568,8 @@ class JavaSettings extends $pb.GeneratedMessage { ..m<$core.String, $core.String>( 2, _omitFieldNames ? '' : 'serviceClassNames', entryClassName: 'JavaSettings.ServiceClassNamesEntry', - keyFieldType: $pb.PbFieldType.OS, - valueFieldType: $pb.PbFieldType.OS, + keyFieldType: $pb.PbFieldTypeInternal.OS, + valueFieldType: $pb.PbFieldTypeInternal.OS, packageName: const $pb.PackageName('google.api')) ..aOM(3, _omitFieldNames ? '' : 'common', subBuilder: CommonLanguageSettings.create) @@ -1055,14 +1055,14 @@ class DotnetSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'DotnetSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldType.OS, - valueFieldType: $pb.PbFieldType.OS, + keyFieldType: $pb.PbFieldTypeInternal.OS, + valueFieldType: $pb.PbFieldTypeInternal.OS, packageName: const $pb.PackageName('google.api')) ..m<$core.String, $core.String>( 3, _omitFieldNames ? '' : 'renamedResources', entryClassName: 'DotnetSettings.RenamedResourcesEntry', - keyFieldType: $pb.PbFieldType.OS, - valueFieldType: $pb.PbFieldType.OS, + keyFieldType: $pb.PbFieldTypeInternal.OS, + valueFieldType: $pb.PbFieldTypeInternal.OS, packageName: const $pb.PackageName('google.api')) ..pPS(4, _omitFieldNames ? '' : 'ignoredResources') ..pPS(5, _omitFieldNames ? '' : 'forcedNamespaceAliases') @@ -1229,8 +1229,8 @@ class GoSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'GoSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldType.OS, - valueFieldType: $pb.PbFieldType.OS, + keyFieldType: $pb.PbFieldTypeInternal.OS, + valueFieldType: $pb.PbFieldTypeInternal.OS, packageName: const $pb.PackageName('google.api')) ..hasRequiredFields = false; @@ -1313,8 +1313,8 @@ class MethodSettings_LongRunning extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM<$0.Duration>(1, _omitFieldNames ? '' : 'initialPollDelay', subBuilder: $0.Duration.create) - ..a<$core.double>( - 2, _omitFieldNames ? '' : 'pollDelayMultiplier', $pb.PbFieldType.OF) + ..a<$core.double>(2, _omitFieldNames ? '' : 'pollDelayMultiplier', + $pb.PbFieldTypeInternal.OF) ..aOM<$0.Duration>(3, _omitFieldNames ? '' : 'maxPollDelay', subBuilder: $0.Duration.create) ..aOM<$0.Duration>(4, _omitFieldNames ? '' : 'totalPollTimeout', @@ -1590,23 +1590,23 @@ class Client { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'methodSignature', 1051, - $pb.PbFieldType.PS, - check: $pb.getCheckFunction($pb.PbFieldType.PS)); + $pb.PbFieldTypeInternal.PS, + check: $pb.getCheckFunction($pb.PbFieldTypeInternal.PS)); static final defaultHost = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'defaultHost', 1049, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static final oauthScopes = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'oauthScopes', 1050, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static final apiVersion = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'apiVersion', 525000001, - $pb.PbFieldType.OS); + $pb.PbFieldTypeInternal.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(methodSignature); registry.add(defaultHost); diff --git a/protoc_plugin/lib/src/gen/google/api/http.pb.dart b/protoc_plugin/lib/src/gen/google/api/http.pb.dart index 2fa07e333..3aba71831 100644 --- a/protoc_plugin/lib/src/gen/google/api/http.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/http.pb.dart @@ -44,7 +44,8 @@ class Http extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Http', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc(1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, + ..pc( + 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldTypeInternal.PM, subBuilder: HttpRule.create) ..aOB(2, _omitFieldNames ? '' : 'fullyDecodeReservedExpansion') ..hasRequiredFields = false; @@ -416,8 +417,8 @@ class HttpRule extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'body') ..aOM(8, _omitFieldNames ? '' : 'custom', subBuilder: CustomHttpPattern.create) - ..pc( - 11, _omitFieldNames ? '' : 'additionalBindings', $pb.PbFieldType.PM, + ..pc(11, _omitFieldNames ? '' : 'additionalBindings', + $pb.PbFieldTypeInternal.PM, subBuilder: HttpRule.create) ..aOS(12, _omitFieldNames ? '' : 'responseBody') ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart index c8c7627e3..04374313b 100644 --- a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart @@ -398,8 +398,8 @@ class RoutingRule extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'RoutingRule', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc( - 2, _omitFieldNames ? '' : 'routingParameters', $pb.PbFieldType.PM, + ..pc(2, _omitFieldNames ? '' : 'routingParameters', + $pb.PbFieldTypeInternal.PM, subBuilder: RoutingParameter.create) ..hasRequiredFields = false; @@ -562,7 +562,7 @@ class Routing { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'routing', 72295729, - $pb.PbFieldType.OM, + $pb.PbFieldTypeInternal.OM, defaultOrMaker: RoutingRule.getDefault, subBuilder: RoutingRule.create); static void registerAllExtensions($pb.ExtensionRegistry registry) { diff --git a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart index 023287aa7..0c40bcc51 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart @@ -51,9 +51,12 @@ class Version extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) - ..a<$core.int>(1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) - ..a<$core.int>(3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) + ..a<$core.int>( + 1, _omitFieldNames ? '' : 'major', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>( + 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>( + 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldTypeInternal.O3) ..aOS(4, _omitFieldNames ? '' : 'suffix') ..hasRequiredFields = false; @@ -153,10 +156,12 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { ..aOM(3, _omitFieldNames ? '' : 'compilerVersion', subBuilder: Version.create) ..pc<$0.FileDescriptorProto>( - 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldType.PM, + 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldTypeInternal.PM, subBuilder: $0.FileDescriptorProto.create) ..pc<$0.FileDescriptorProto>( - 17, _omitFieldNames ? '' : 'sourceFileDescriptors', $pb.PbFieldType.PM, + 17, + _omitFieldNames ? '' : 'sourceFileDescriptors', + $pb.PbFieldTypeInternal.PM, subBuilder: $0.FileDescriptorProto.create); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -423,15 +428,15 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'error') - ..a<$fixnum.Int64>( - 2, _omitFieldNames ? '' : 'supportedFeatures', $pb.PbFieldType.OU6, + ..a<$fixnum.Int64>(2, _omitFieldNames ? '' : 'supportedFeatures', + $pb.PbFieldTypeInternal.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..a<$core.int>( - 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.O3) + 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.O3) ..a<$core.int>( - 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.O3) + 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.O3) ..pc( - 15, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, + 15, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, subBuilder: CodeGeneratorResponse_File.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart index fe6bf4716..1f945e551 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart @@ -47,7 +47,7 @@ class FileDescriptorSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, + 1, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, subBuilder: FileDescriptorProto.create) ..hasExtensions = true; @@ -132,27 +132,28 @@ class FileDescriptorProto extends $pb.GeneratedMessage { ..aOS(2, _omitFieldNames ? '' : 'package') ..pPS(3, _omitFieldNames ? '' : 'dependency') ..pc( - 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldType.PM, + 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldTypeInternal.PM, subBuilder: DescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, + 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 6, _omitFieldNames ? '' : 'service', $pb.PbFieldType.PM, + 6, _omitFieldNames ? '' : 'service', $pb.PbFieldTypeInternal.PM, subBuilder: ServiceDescriptorProto.create) ..pc( - 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, + 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, subBuilder: FieldDescriptorProto.create) ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FileOptions.create) ..aOM(9, _omitFieldNames ? '' : 'sourceCodeInfo', subBuilder: SourceCodeInfo.create) + ..p<$core.int>(10, _omitFieldNames ? '' : 'publicDependency', + $pb.PbFieldTypeInternal.P3) ..p<$core.int>( - 10, _omitFieldNames ? '' : 'publicDependency', $pb.PbFieldType.P3) - ..p<$core.int>( - 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldType.P3) + 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldTypeInternal.P3) ..aOS(12, _omitFieldNames ? '' : 'syntax') - ..e(14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e( + 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -311,8 +312,9 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) + ..a<$core.int>( + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ExtensionRangeOptions.create); @@ -399,8 +401,9 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) + ..a<$core.int>( + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -493,31 +496,31 @@ class DescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'field', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'field', $pb.PbFieldTypeInternal.PM, subBuilder: FieldDescriptorProto.create) ..pc( - 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldType.PM, + 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldTypeInternal.PM, subBuilder: DescriptorProto.create) ..pc( - 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, + 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldType.PM, + 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldTypeInternal.PM, subBuilder: DescriptorProto_ExtensionRange.create) ..pc( - 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, + 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, subBuilder: FieldDescriptorProto.create) ..aOM(7, _omitFieldNames ? '' : 'options', subBuilder: MessageOptions.create) ..pc( - 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldType.PM, + 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldTypeInternal.PM, subBuilder: OneofDescriptorProto.create) ..pc( - 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, + 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, subBuilder: DescriptorProto_ReservedRange.create) ..pPS(10, _omitFieldNames ? '' : 'reservedName') ..e( - 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, + 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -632,7 +635,8 @@ class ExtensionRangeOptions_Declaration extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>(1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>( + 1, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) ..aOS(2, _omitFieldNames ? '' : 'fullName') ..aOS(3, _omitFieldNames ? '' : 'type') ..aOB(5, _omitFieldNames ? '' : 'reserved') @@ -753,17 +757,17 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldTypeInternal.PM, subBuilder: ExtensionRangeOptions_Declaration.create) ..e( - 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldType.OE, + 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldTypeInternal.OE, defaultOrMaker: ExtensionRangeOptions_VerificationState.UNVERIFIED, valueOf: ExtensionRangeOptions_VerificationState.valueOf, enumValues: ExtensionRangeOptions_VerificationState.values) ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -872,14 +876,15 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..aOS(2, _omitFieldNames ? '' : 'extendee') - ..a<$core.int>(3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>( + 3, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) ..e( - 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, + 4, _omitFieldNames ? '' : 'label', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, valueOf: FieldDescriptorProto_Label.valueOf, enumValues: FieldDescriptorProto_Label.values) ..e( - 5, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, + 5, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FieldDescriptorProto_Type.TYPE_DOUBLE, valueOf: FieldDescriptorProto_Type.valueOf, enumValues: FieldDescriptorProto_Type.values) @@ -887,7 +892,8 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'defaultValue') ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FieldOptions.create) - ..a<$core.int>(9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) + ..a<$core.int>( + 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldTypeInternal.O3) ..aOS(10, _omitFieldNames ? '' : 'jsonName') ..aOB(17, _omitFieldNames ? '' : 'proto3Optional'); @@ -1160,8 +1166,9 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) + ..a<$core.int>( + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -1245,16 +1252,16 @@ class EnumDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'value', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'value', $pb.PbFieldTypeInternal.PM, subBuilder: EnumValueDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumOptions.create) ..pc( - 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, + 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, subBuilder: EnumDescriptorProto_EnumReservedRange.create) ..pPS(5, _omitFieldNames ? '' : 'reservedName') ..e( - 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, + 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -1355,7 +1362,8 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') - ..a<$core.int>(2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>( + 2, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumValueOptions.create); @@ -1442,7 +1450,7 @@ class ServiceDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'method', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'method', $pb.PbFieldTypeInternal.PM, subBuilder: MethodDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ServiceOptions.create); @@ -1693,7 +1701,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(1, _omitFieldNames ? '' : 'javaPackage') ..aOS(8, _omitFieldNames ? '' : 'javaOuterClassname') ..e( - 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldType.OE, + 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FileOptions_OptimizeMode.SPEED, valueOf: FileOptions_OptimizeMode.valueOf, enumValues: FileOptions_OptimizeMode.values) @@ -1706,7 +1714,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOB(23, _omitFieldNames ? '' : 'deprecated') ..aOB(27, _omitFieldNames ? '' : 'javaStringCheckUtf8') ..a<$core.bool>( - 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldType.OB, + 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldTypeInternal.OB, defaultOrMaker: true) ..aOS(36, _omitFieldNames ? '' : 'objcClassPrefix') ..aOS(37, _omitFieldNames ? '' : 'csharpNamespace') @@ -1717,8 +1725,8 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(45, _omitFieldNames ? '' : 'rubyPackage') ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2051,8 +2059,8 @@ class MessageOptions extends $pb.GeneratedMessage { ..aOB(11, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(12, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2229,7 +2237,8 @@ class FieldOptions_EditionDefault extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(2, _omitFieldNames ? '' : 'value') - ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e( + 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2310,18 +2319,19 @@ class FieldOptions_FeatureSupport extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e( - 1, _omitFieldNames ? '' : 'editionIntroduced', $pb.PbFieldType.OE, + ..e(1, _omitFieldNames ? '' : 'editionIntroduced', + $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e( - 2, _omitFieldNames ? '' : 'editionDeprecated', $pb.PbFieldType.OE, + ..e(2, _omitFieldNames ? '' : 'editionDeprecated', + $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..aOS(3, _omitFieldNames ? '' : 'deprecationWarning') - ..e(4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, + ..e( + 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2450,7 +2460,7 @@ class FieldOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldType.OE, + 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FieldOptions_CType.STRING, valueOf: FieldOptions_CType.valueOf, enumValues: FieldOptions_CType.values) @@ -2458,7 +2468,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(3, _omitFieldNames ? '' : 'deprecated') ..aOB(5, _omitFieldNames ? '' : 'lazy') ..e( - 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldType.OE, + 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FieldOptions_JSType.JS_NORMAL, valueOf: FieldOptions_JSType.valueOf, enumValues: FieldOptions_JSType.values) @@ -2466,25 +2476,25 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(15, _omitFieldNames ? '' : 'unverifiedLazy') ..aOB(16, _omitFieldNames ? '' : 'debugRedact') ..e( - 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldType.OE, + 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FieldOptions_OptionRetention.RETENTION_UNKNOWN, valueOf: FieldOptions_OptionRetention.valueOf, enumValues: FieldOptions_OptionRetention.values) ..pc( - 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldType.PE, + 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldTypeInternal.PE, valueOf: FieldOptions_OptionTargetType.valueOf, enumValues: FieldOptions_OptionTargetType.values, defaultEnumValue: FieldOptions_OptionTargetType.TARGET_TYPE_UNKNOWN) - ..pc( - 20, _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, + ..pc(20, + _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldTypeInternal.PM, subBuilder: FieldOptions_EditionDefault.create) ..aOM(21, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..aOM( 22, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2713,8 +2723,8 @@ class OneofOptions extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM(1, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2799,8 +2809,8 @@ class EnumOptions extends $pb.GeneratedMessage { ..aOB(6, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(7, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2927,8 +2937,8 @@ class EnumValueOptions extends $pb.GeneratedMessage { ..aOM( 4, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3041,8 +3051,8 @@ class ServiceOptions extends $pb.GeneratedMessage { ..aOB(33, _omitFieldNames ? '' : 'deprecated') ..aOM(34, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3131,15 +3141,15 @@ class MethodOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOB(33, _omitFieldNames ? '' : 'deprecated') - ..e( - 34, _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, + ..e(34, + _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldTypeInternal.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, valueOf: MethodOptions_IdempotencyLevel.valueOf, enumValues: MethodOptions_IdempotencyLevel.values) ..aOM(35, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc( - 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, + ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', + $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3239,7 +3249,7 @@ class UninterpretedOption_NamePart extends $pb.GeneratedMessage { createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'namePart') ..a<$core.bool>( - 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldType.QB); + 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldTypeInternal.QB); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') UninterpretedOption_NamePart clone() => @@ -3327,17 +3337,17 @@ class UninterpretedOption extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'name', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.PM, subBuilder: UninterpretedOption_NamePart.create) ..aOS(3, _omitFieldNames ? '' : 'identifierValue') - ..a<$fixnum.Int64>( - 4, _omitFieldNames ? '' : 'positiveIntValue', $pb.PbFieldType.OU6, + ..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'positiveIntValue', + $pb.PbFieldTypeInternal.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aInt64(5, _omitFieldNames ? '' : 'negativeIntValue') ..a<$core.double>( - 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldType.OD) + 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldTypeInternal.OD) ..a<$core.List<$core.int>>( - 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldType.OY) + 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldTypeInternal.OY) ..aOS(8, _omitFieldNames ? '' : 'aggregateValue'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -3514,44 +3524,48 @@ class FeatureSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldType.OE, + 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_FieldPresence.FIELD_PRESENCE_UNKNOWN, valueOf: FeatureSet_FieldPresence.valueOf, enumValues: FeatureSet_FieldPresence.values) ..e( - 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.OE, + 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_EnumType.ENUM_TYPE_UNKNOWN, valueOf: FeatureSet_EnumType.valueOf, enumValues: FeatureSet_EnumType.values) ..e( - 3, _omitFieldNames ? '' : 'repeatedFieldEncoding', $pb.PbFieldType.OE, + 3, + _omitFieldNames ? '' : 'repeatedFieldEncoding', + $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_RepeatedFieldEncoding.REPEATED_FIELD_ENCODING_UNKNOWN, valueOf: FeatureSet_RepeatedFieldEncoding.valueOf, enumValues: FeatureSet_RepeatedFieldEncoding.values) ..e( - 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldType.OE, + 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN, valueOf: FeatureSet_Utf8Validation.valueOf, enumValues: FeatureSet_Utf8Validation.values) ..e( - 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldType.OE, + 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN, valueOf: FeatureSet_MessageEncoding.valueOf, enumValues: FeatureSet_MessageEncoding.values) ..e( - 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldType.OE, + 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN, valueOf: FeatureSet_JsonFormat.valueOf, enumValues: FeatureSet_JsonFormat.values) - ..e( - 7, _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, + ..e(7, + _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN, valueOf: FeatureSet_EnforceNamingStyle.valueOf, enumValues: FeatureSet_EnforceNamingStyle.values) ..e( - 8, _omitFieldNames ? '' : 'defaultSymbolVisibility', $pb.PbFieldType.OE, + 8, + _omitFieldNames ? '' : 'defaultSymbolVisibility', + $pb.PbFieldTypeInternal.OE, defaultOrMaker: FeatureSet_VisibilityFeature_DefaultSymbolVisibility .DEFAULT_SYMBOL_VISIBILITY_UNKNOWN, valueOf: FeatureSet_VisibilityFeature_DefaultSymbolVisibility.valueOf, @@ -3689,7 +3703,8 @@ class FeatureSetDefaults_FeatureSetEditionDefault extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e( + 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -3791,13 +3806,15 @@ class FeatureSetDefaults extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldType.PM, + 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldTypeInternal.PM, subBuilder: FeatureSetDefaults_FeatureSetEditionDefault.create) - ..e(4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, + ..e( + 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e(5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, + ..e( + 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values); @@ -3882,8 +3899,8 @@ class SourceCodeInfo_Location extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) - ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldType.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldTypeInternal.K3) ..aOS(3, _omitFieldNames ? '' : 'leadingComments') ..aOS(4, _omitFieldNames ? '' : 'trailingComments') ..pPS(6, _omitFieldNames ? '' : 'leadingDetachedComments') @@ -4041,7 +4058,7 @@ class SourceCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'location', $pb.PbFieldType.PM, + 1, _omitFieldNames ? '' : 'location', $pb.PbFieldTypeInternal.PM, subBuilder: SourceCodeInfo_Location.create) ..hasExtensions = true; @@ -4144,12 +4161,13 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) ..aOS(2, _omitFieldNames ? '' : 'sourceFile') - ..a<$core.int>(3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) - ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) + ..a<$core.int>( + 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) ..e( - 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldType.OE, + 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldTypeInternal.OE, defaultOrMaker: GeneratedCodeInfo_Annotation_Semantic.NONE, valueOf: GeneratedCodeInfo_Annotation_Semantic.valueOf, enumValues: GeneratedCodeInfo_Annotation_Semantic.values) @@ -4256,7 +4274,7 @@ class GeneratedCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldType.PM, + 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldTypeInternal.PM, subBuilder: GeneratedCodeInfo_Annotation.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart index 5cba2308c..dc5428b0b 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart @@ -105,7 +105,8 @@ class Duration extends $pb.GeneratedMessage with $mixin.DurationMixin { toProto3Json: $mixin.DurationMixin.toProto3JsonHelper, fromProto3Json: $mixin.DurationMixin.fromProto3JsonHelper) ..aInt64(1, _omitFieldNames ? '' : 'seconds') - ..a<$core.int>(2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) + ..a<$core.int>( + 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldTypeInternal.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index af3ec5921..67ea4cef5 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -181,7 +181,7 @@ class ProtobufField { /// Returns the tag number of the underlying proto field. int get number => descriptor.number; - /// Returns the constant in PbFieldType corresponding to this type. + /// Returns the constant in PbFieldTypeInternal corresponding to this type. String get typeConstant { var prefix = 'O'; if (isRequired) { @@ -191,7 +191,7 @@ class ProtobufField { } else if (isRepeated) { prefix = 'P'; } - return '$protobufImportPrefix.PbFieldType.$prefix${baseType.typeConstantSuffix}'; + return '$protobufImportPrefix.PbFieldTypeInternal.$prefix${baseType.typeConstantSuffix}'; } static String _formatArguments( @@ -260,7 +260,7 @@ class ProtobufField { 'const $protobufImportPrefix.PackageName(\'$package\')'; } } else if (isRepeated) { - if (typeConstant == '$protobufImportPrefix.PbFieldType.PS') { + if (typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.PS') { invocation = 'pPS'; } else { args.add(typeConstant); @@ -291,9 +291,11 @@ class ProtobufField { } else if (makeDefault == null) { switch (type) { case '$coreImportPrefix.String': - if (typeConstant == '$protobufImportPrefix.PbFieldType.OS') { + if (typeConstant == + '$protobufImportPrefix.PbFieldTypeInternal.OS') { invocation = 'aOS'; - } else if (typeConstant == '$protobufImportPrefix.PbFieldType.QS') { + } else if (typeConstant == + '$protobufImportPrefix.PbFieldTypeInternal.QS') { invocation = 'aQS'; } else { invocation = 'a<$type>'; @@ -301,7 +303,8 @@ class ProtobufField { } break; case '$coreImportPrefix.bool': - if (typeConstant == '$protobufImportPrefix.PbFieldType.OB') { + if (typeConstant == + '$protobufImportPrefix.PbFieldTypeInternal.OB') { invocation = 'aOB'; } else { invocation = 'a<$type>'; @@ -316,7 +319,7 @@ class ProtobufField { } else { if (makeDefault == '$fixnumImportPrefix.Int64.ZERO' && type == '$fixnumImportPrefix.Int64' && - typeConstant == '$protobufImportPrefix.PbFieldType.O6') { + typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.O6') { invocation = 'aInt64'; } else { if (baseType.isMessage || baseType.isGroup) { diff --git a/protoc_plugin/test/goldens/extension.pb.dart b/protoc_plugin/test/goldens/extension.pb.dart index 32a5dcb75..1da48e7fc 100644 --- a/protoc_plugin/test/goldens/extension.pb.dart +++ b/protoc_plugin/test/goldens/extension.pb.dart @@ -1,4 +1,4 @@ -static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldType.OS); +static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldTypeInternal.OS); const $core.bool _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const $core.bool _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart b/protoc_plugin/test/goldens/messageGenerator.pb.dart index 15d05a340..7c285d54f 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart @@ -8,8 +8,8 @@ class PhoneNumber extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) - ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$') + ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, defaultOrMaker: '\$') ..aOS(4, _omitFieldNames ? '' : 'deprecatedField') ; diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta index faefae9b1..a5992239b 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1854 - end: 1860 + begin: 1870 + end: 1876 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1902 - end: 1908 + begin: 1918 + end: 1924 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1988 - end: 1997 + begin: 2004 + end: 2013 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2040 - end: 2051 + begin: 2056 + end: 2067 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2123 - end: 2127 + begin: 2139 + end: 2143 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2168 - end: 2172 + begin: 2184 + end: 2188 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2260 - end: 2267 + begin: 2276 + end: 2283 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2310 - end: 2319 + begin: 2326 + end: 2335 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2382 - end: 2386 + begin: 2398 + end: 2402 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2433 - end: 2437 + begin: 2449 + end: 2453 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2517 - end: 2524 + begin: 2533 + end: 2540 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2567 - end: 2576 + begin: 2583 + end: 2592 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2688 - end: 2703 + begin: 2704 + end: 2719 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2794 - end: 2809 + begin: 2810 + end: 2825 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2938 - end: 2956 + begin: 2954 + end: 2972 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3048 - end: 3068 + begin: 3064 + end: 3084 } diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart b/protoc_plugin/test/goldens/oneMessage.pb.dart index e38712f82..d408d4521 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart @@ -32,8 +32,9 @@ class PhoneNumber extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.O3) - ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, + ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.O3) + ..a<$core.String>( + 3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, defaultOrMaker: '\$'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta index 44ec15bfc..6fdc950eb 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2218 - end: 2224 + begin: 2234 + end: 2240 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2266 - end: 2272 + begin: 2282 + end: 2288 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2352 - end: 2361 + begin: 2368 + end: 2377 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2404 - end: 2415 + begin: 2420 + end: 2431 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2475 - end: 2479 + begin: 2491 + end: 2495 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2521 - end: 2525 + begin: 2537 + end: 2541 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2607 - end: 2614 + begin: 2623 + end: 2630 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2657 - end: 2666 + begin: 2673 + end: 2682 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2729 - end: 2733 + begin: 2745 + end: 2749 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2780 - end: 2784 + begin: 2796 + end: 2800 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2864 - end: 2871 + begin: 2880 + end: 2887 } annotation: { path: 4 @@ -117,6 +117,6 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2914 - end: 2923 + begin: 2930 + end: 2939 } diff --git a/protoc_plugin/test/reserved_names_test.dart b/protoc_plugin/test/reserved_names_test.dart index 2158b9ab2..56376c3f7 100644 --- a/protoc_plugin/test/reserved_names_test.dart +++ b/protoc_plugin/test/reserved_names_test.dart @@ -20,7 +20,7 @@ void main() { test('GeneratedMessage reserved names are up to date', () { final actual = Set.from(GeneratedMessage_reservedNames); final expected = findMemberNames( - 'package:protobuf/protobuf.dart', + 'package:protobuf/src/protobuf/internal.dart', #GeneratedMessage, ); @@ -30,7 +30,7 @@ void main() { test('ProtobufEnum reserved names are up to date', () { final actual = Set.from(ProtobufEnum_reservedNames); final expected = findMemberNames( - 'package:protobuf/protobuf.dart', + 'package:protobuf/src/protobuf/internal.dart', #ProtobufEnum, ); @@ -39,7 +39,7 @@ void main() { test("ReadonlyMessageMixin doesn't add any reserved names", () { final mixinNames = findMemberNames( - 'package:protobuf/protobuf.dart', + 'package:protobuf/src/protobuf/internal.dart', #ReadonlyMessageMixin, ); final reservedNames = Set.from(GeneratedMessage_reservedNames); From 35bb15a34b25725c78bdf52c1aedac7553ab147d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 10:10:29 +0100 Subject: [PATCH 02/22] Also make consts a lib --- protobuf/lib/src/protobuf/consts.dart | 8 +++----- protobuf/lib/src/protobuf/internal.dart | 2 +- protobuf/lib/src/protobuf/json.dart | 4 ++-- protobuf/lib/src/protobuf/proto3_json.dart | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/protobuf/lib/src/protobuf/consts.dart b/protobuf/lib/src/protobuf/consts.dart index caa1484ba..22062b7d6 100644 --- a/protobuf/lib/src/protobuf/consts.dart +++ b/protobuf/lib/src/protobuf/consts.dart @@ -2,16 +2,14 @@ // 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. -part of 'internal.dart'; - /// Constant string value of `double.infinity.toString()` and the infinity /// value recognized by `double.parse(..)`. -const _infinity = 'Infinity'; +const infinity = 'Infinity'; /// Constant string value of `double.negativeInfinity.toString()` and the /// negative infinity value recognized by `double.parse(..)`. -const _negativeInfinity = '-Infinity'; +const negativeInfinity = '-Infinity'; /// Constant string value of `double.nan.toString()` and the NaN (not a number) /// value recognized by `double.parse(..)`. -const _nan = 'NaN'; +const nan = 'NaN'; diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart index d7d23a500..9ca3edbfe 100644 --- a/protobuf/lib/src/protobuf/internal.dart +++ b/protobuf/lib/src/protobuf/internal.dart @@ -22,6 +22,7 @@ import 'dart:typed_data' show ByteData, Endian, Uint8List; import 'package:fixnum/fixnum.dart' show Int64; import 'package:meta/meta.dart' show UseResult; +import 'consts.dart'; import 'json_parsing_context.dart'; import 'permissive_compare.dart'; import 'type_registry.dart'; @@ -33,7 +34,6 @@ part 'builder_info.dart'; part 'coded_buffer.dart'; part 'coded_buffer_reader.dart'; part 'coded_buffer_writer.dart'; -part 'consts.dart'; part 'exceptions.dart'; part 'extension.dart'; part 'extension_field_set.dart'; diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index 5cb340491..aebe72829 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -26,10 +26,10 @@ Map _writeToJsonMap(FieldSet fs) { case PbFieldTypeInternal._DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { - return _nan; + return nan; } if (value.isInfinite) { - return value.isNegative ? _negativeInfinity : _infinity; + return value.isNegative ? negativeInfinity : infinity; } if (fieldValue.toInt() == fieldValue) { return fieldValue.toInt(); diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index 134b5aaba..b6b1f0383 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -64,10 +64,10 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { case PbFieldTypeInternal._DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { - return _nan; + return nan; } if (value.isInfinite) { - return value.isNegative ? _negativeInfinity : _infinity; + return value.isNegative ? negativeInfinity : infinity; } if (value.toInt() == fieldValue) { return value.toInt(); From 9a2207f471b1421b434527659aaeac7ce1f64186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 10:15:06 +0100 Subject: [PATCH 03/22] Make utils a lib --- protobuf/lib/src/protobuf/coded_buffer.dart | 2 +- .../lib/src/protobuf/extension_field_set.dart | 2 +- protobuf/lib/src/protobuf/field_set.dart | 20 ++++++------- protobuf/lib/src/protobuf/internal.dart | 2 +- protobuf/lib/src/protobuf/json.dart | 2 +- protobuf/lib/src/protobuf/pb_list.dart | 4 +-- protobuf/lib/src/protobuf/pb_map.dart | 2 +- .../lib/src/protobuf/unknown_field_set.dart | 14 ++++----- protobuf/lib/src/protobuf/utils.dart | 30 +++++++++---------- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index 2036142d8..137d735b7 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -17,7 +17,7 @@ void _writeToCodedBufferWriter(FieldSet fs, CodedBufferWriter out) { final extensions = fs._extensions; if (extensions != null) { - for (final tagNumber in _sorted(extensions._tagNumbers)) { + for (final tagNumber in sorted(extensions._tagNumbers)) { final fi = extensions._getInfoOrNull(tagNumber)!; out.writeField(tagNumber, fi.type, extensions._getFieldOrNull(fi)); } diff --git a/protobuf/lib/src/protobuf/extension_field_set.dart b/protobuf/lib/src/protobuf/extension_field_set.dart index bbaa707e2..649720033 100644 --- a/protobuf/lib/src/protobuf/extension_field_set.dart +++ b/protobuf/lib/src/protobuf/extension_field_set.dart @@ -158,7 +158,7 @@ class ExtensionFieldSet { bool get _hasValues => _values.isNotEmpty; bool _equalValues(ExtensionFieldSet? other) => - other != null && _areMapsEqual(_values, other._values); + other != null && areMapsEqual(_values, other._values); void _clearValues() => _values.clear(); diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index 64afd3908..aee73b7b8 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -545,7 +545,7 @@ class FieldSet { } bool _equalFieldValues(Object? left, Object? right) { - if (left != null && right != null) return _deepEquals(left, right); + if (left != null && right != null) return deepEquals(left, right); final val = left ?? right; @@ -584,7 +584,7 @@ class FieldSet { } // Hash with descriptor. - var hash = _HashUtils._combine(0, _meta.hashCode); + var hash = HashUtils.combine(0, _meta.hashCode); // Hash with non-extension fields. final values = _values; @@ -597,7 +597,7 @@ class FieldSet { // Hash with extension fields. final extensions = _extensions; if (extensions != null) { - final sortedByTagNumbers = _sorted(extensions._tagNumbers); + final sortedByTagNumbers = sorted(extensions._tagNumbers); for (final tagNumber in sortedByTagNumbers) { final fi = extensions._getInfoOrNull(tagNumber)!; hash = _hashField(hash, fi, extensions._getFieldOrNull(fi)); @@ -605,7 +605,7 @@ class FieldSet { } // Hash with unknown fields. - hash = _HashUtils._combine(hash, _unknownFields?.hashCode ?? 0); + hash = HashUtils.combine(hash, _unknownFields?.hashCode ?? 0); // Ignore _unknownJsonData to preserve existing hashing behavior. @@ -625,18 +625,18 @@ class FieldSet { return hash; } - hash = _HashUtils._combine(hash, fi.tagNumber); + hash = HashUtils.combine(hash, fi.tagNumber); if (_isBytes(fi.type)) { // Bytes are represented as a List (Usually with byte-data). // We special case that to match our equality semantics. - hash = _HashUtils._combine(hash, _HashUtils._hashObjects(value)); + hash = HashUtils.combine(hash, HashUtils.hashObjects(value)); } else if (!_isEnum(fi.type)) { - hash = _HashUtils._combine(hash, value.hashCode); + hash = HashUtils.combine(hash, value.hashCode); } else if (fi.isRepeated) { final PbList list = value; - hash = _HashUtils._combine( + hash = HashUtils.combine( hash, - _HashUtils._hashObjects( + HashUtils.hashObjects( list.map((enm) { final ProtobufEnum enm_ = enm; return enm_.value; @@ -645,7 +645,7 @@ class FieldSet { ); } else { final ProtobufEnum enm = value; - hash = _HashUtils._combine(hash, enm.value); + hash = HashUtils.combine(hash, enm.value); } return hash; diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart index 9ca3edbfe..176084d77 100644 --- a/protobuf/lib/src/protobuf/internal.dart +++ b/protobuf/lib/src/protobuf/internal.dart @@ -26,6 +26,7 @@ import 'consts.dart'; import 'json_parsing_context.dart'; import 'permissive_compare.dart'; import 'type_registry.dart'; +import 'utils.dart'; export 'type_registry.dart' show TypeRegistry; @@ -53,7 +54,6 @@ part 'protobuf_enum.dart'; part 'rpc_client.dart'; part 'unknown_field_set.dart'; part 'unpack.dart'; -part 'utils.dart'; part 'wire_format.dart'; // TODO(sra): Use `Int64.parse()` when available: diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index aebe72829..361f1d0e9 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -84,7 +84,7 @@ Map _writeToJsonMap(FieldSet fs) { } final extensions = fs._extensions; if (extensions != null) { - for (final tagNumber in _sorted(extensions._tagNumbers)) { + for (final tagNumber in sorted(extensions._tagNumbers)) { final value = extensions._values[tagNumber]; if (value is List && value.isEmpty) { continue; // It's repeated or an empty byte array. diff --git a/protobuf/lib/src/protobuf/pb_list.dart b/protobuf/lib/src/protobuf/pb_list.dart index be9dc9663..d48a8214b 100644 --- a/protobuf/lib/src/protobuf/pb_list.dart +++ b/protobuf/lib/src/protobuf/pb_list.dart @@ -204,10 +204,10 @@ class PbList extends ListBase { @override bool operator ==(Object other) => - other is PbList && _areListsEqual(other, this); + other is PbList && areListsEqual(other, this); @override - int get hashCode => _HashUtils._hashObjects(_wrappedList); + int get hashCode => HashUtils.hashObjects(_wrappedList); void freeze() { if (_isReadOnly) { diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 130e80a72..f9c5379d9 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -77,7 +77,7 @@ class PbMap extends MapBase { int get hashCode { return _wrappedMap.entries.fold( 0, - (h, entry) => h ^ _HashUtils._hash2(entry.key, entry.value), + (h, entry) => h ^ HashUtils.hash2(entry.key, entry.value), ); } diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index fe1487398..906ca5a71 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -140,7 +140,7 @@ class UnknownFieldSet { if (other is! UnknownFieldSet) return false; final o = other; - return _areMapsEqual(o._fields, _fields); + return areMapsEqual(o._fields, _fields); } @override @@ -159,7 +159,7 @@ class UnknownFieldSet { String _toString(String indent) { final stringBuffer = StringBuffer(); - for (final tag in _sorted(_fields.keys)) { + for (final tag in sorted(_fields.keys)) { final field = _fields[tag]!; for (final value in field.values) { if (value is UnknownFieldSet) { @@ -230,14 +230,14 @@ class UnknownFieldSetField { final o = other; if (lengthDelimited.length != o.lengthDelimited.length) return false; for (var i = 0; i < lengthDelimited.length; i++) { - if (!_areListsEqual(o.lengthDelimited[i], lengthDelimited[i])) { + if (!areListsEqual(o.lengthDelimited[i], lengthDelimited[i])) { return false; } } - if (!_areListsEqual(o.varints, varints)) return false; - if (!_areListsEqual(o.fixed32s, fixed32s)) return false; - if (!_areListsEqual(o.fixed64s, fixed64s)) return false; - if (!_areListsEqual(o.groups, groups)) return false; + if (!areListsEqual(o.varints, varints)) return false; + if (!areListsEqual(o.fixed32s, fixed32s)) return false; + if (!areListsEqual(o.fixed64s, fixed64s)) return false; + if (!areListsEqual(o.groups, groups)) return false; return true; } diff --git a/protobuf/lib/src/protobuf/utils.dart b/protobuf/lib/src/protobuf/utils.dart index 37e4280ec..b4bb8bced 100644 --- a/protobuf/lib/src/protobuf/utils.dart +++ b/protobuf/lib/src/protobuf/utils.dart @@ -2,38 +2,38 @@ // 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. -part of 'internal.dart'; +import 'internal.dart'; // TODO(antonm): reconsider later if PbList should take care of equality. -bool _deepEquals(Object lhs, Object rhs) { +bool deepEquals(Object lhs, Object rhs) { // Some GeneratedMessages implement Map, so test this first. if (lhs is GeneratedMessage) return lhs == rhs; if (rhs is GeneratedMessage) return false; - if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs); - if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs); + if ((lhs is List) && (rhs is List)) return areListsEqual(lhs, rhs); + if ((lhs is Map) && (rhs is Map)) return areMapsEqual(lhs, rhs); return lhs == rhs; } -bool _areListsEqual(List lhs, List rhs) { +bool areListsEqual(List lhs, List rhs) { if (lhs.length != rhs.length) return false; for (var i = 0; i < lhs.length; i++) { - if (!_deepEquals(lhs[i], rhs[i])) return false; + if (!deepEquals(lhs[i], rhs[i])) return false; } return true; } -bool _areMapsEqual(Map lhs, Map rhs) { +bool areMapsEqual(Map lhs, Map rhs) { if (lhs.length != rhs.length) return false; - return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key])); + return lhs.keys.every((key) => deepEquals(lhs[key], rhs[key])); } -List _sorted(Iterable list) => List.from(list)..sort(); +List sorted(Iterable list) => List.from(list)..sort(); -class _HashUtils { +class HashUtils { // Jenkins hash functions copied from // https://github.com/google/quiver-dart/blob/master/lib/src/core/hash.dart. - static int _combine(int hash, int value) { + static int combine(int hash, int value) { hash = 0x1fffffff & (hash + value); hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); return hash ^ (hash >> 6); @@ -46,10 +46,10 @@ class _HashUtils { } /// Generates a hash code for multiple [objects]. - static int _hashObjects(Iterable objects) => - _finish(objects.fold(0, (h, i) => _combine(h, i.hashCode))); + static int hashObjects(Iterable objects) => + _finish(objects.fold(0, (h, i) => combine(h, i.hashCode))); /// Generates a hash code for two objects. - static int _hash2(dynamic a, dynamic b) => - _finish(_combine(_combine(0, a.hashCode), b.hashCode)); + static int hash2(dynamic a, dynamic b) => + _finish(combine(combine(0, a.hashCode), b.hashCode)); } From 8b59a1d624e4b90b23a2960a20a01ab634db3bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 10:41:20 +0100 Subject: [PATCH 04/22] Make PbFieldType stuff public --- protobuf/lib/protobuf.dart | 4 +- protobuf/lib/src/protobuf/builder_info.dart | 10 +- protobuf/lib/src/protobuf/coded_buffer.dart | 76 +-- .../lib/src/protobuf/coded_buffer_writer.dart | 46 +- .../lib/src/protobuf/extension_registry.dart | 2 +- protobuf/lib/src/protobuf/field_error.dart | 74 +-- protobuf/lib/src/protobuf/field_info.dart | 30 +- protobuf/lib/src/protobuf/field_set.dart | 8 +- protobuf/lib/src/protobuf/field_type.dart | 438 +++++++++--------- .../lib/src/protobuf/generated_message.dart | 2 +- protobuf/lib/src/protobuf/json.dart | 80 ++-- protobuf/lib/src/protobuf/pb_map.dart | 5 +- protobuf/lib/src/protobuf/proto3_json.dart | 134 +++--- .../lib/src/protobuf/unknown_field_set.dart | 10 +- protobuf/lib/src/protobuf/wire_format.dart | 38 +- 15 files changed, 485 insertions(+), 472 deletions(-) diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index 5936d56df..ccc85ed7f 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -17,4 +17,6 @@ export 'src/protobuf/internal.dart' FieldSet, FieldSetInternalExtension, GeneratedMessageInternalExtension, - MapFieldInfoInternalExtension; + MapFieldInfoInternalExtension, + mapKeyFieldNumber, + mapValueFieldNumber; diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index 56cce4608..c236e58fa 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -274,7 +274,10 @@ class BuilderInfo { // Repeated, not a message, group, or enum. void p(int tagNumber, String name, int fieldType, {String? protoName}) { - assert(!_isGroupOrMessage(fieldType) && !_isEnum(fieldType)); + assert( + !PbFieldTypeInternal.isGroupOrMessage(fieldType) && + !PbFieldTypeInternal.isEnum(fieldType), + ); addRepeated( tagNumber, name, @@ -298,7 +301,10 @@ class BuilderInfo { ProtobufEnum? defaultEnumValue, String? protoName, }) { - assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType)); + assert( + PbFieldTypeInternal.isGroupOrMessage(fieldType) || + PbFieldTypeInternal.isEnum(fieldType), + ); addRepeated( tagNumber, name, diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index 137d735b7..c1cc0dbb6 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -55,24 +55,24 @@ void _mergeFromCodedBufferReader( // Ignore required/optional packed/unpacked. var fieldType = fi.type; fieldType &= - ~(PbFieldTypeInternal._PACKED_BIT | PbFieldTypeInternal._REQUIRED_BIT); + ~(PbFieldTypeInternal.PACKED_BIT | PbFieldTypeInternal.REQUIRED_BIT); switch (fieldType) { - case PbFieldTypeInternal._OPTIONAL_BOOL: + case PbFieldTypeInternal.OPTIONAL_BOOL: fs._setFieldUnchecked(meta, fi, input.readBool()); break; - case PbFieldTypeInternal._OPTIONAL_BYTES: + case PbFieldTypeInternal.OPTIONAL_BYTES: fs._setFieldUnchecked(meta, fi, input.readBytes()); break; - case PbFieldTypeInternal._OPTIONAL_STRING: + case PbFieldTypeInternal.OPTIONAL_STRING: fs._setFieldUnchecked(meta, fi, input.readString()); break; - case PbFieldTypeInternal._OPTIONAL_FLOAT: + case PbFieldTypeInternal.OPTIONAL_FLOAT: fs._setFieldUnchecked(meta, fi, input.readFloat()); break; - case PbFieldTypeInternal._OPTIONAL_DOUBLE: + case PbFieldTypeInternal.OPTIONAL_DOUBLE: fs._setFieldUnchecked(meta, fi, input.readDouble()); break; - case PbFieldTypeInternal._OPTIONAL_ENUM: + case PbFieldTypeInternal.OPTIONAL_ENUM: final rawValue = input.readEnum(); final value = meta._decodeEnum(tagNumber, registry, rawValue); if (value == null) { @@ -82,7 +82,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, value); } break; - case PbFieldTypeInternal._OPTIONAL_GROUP: + case PbFieldTypeInternal.OPTIONAL_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); final oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { @@ -91,37 +91,37 @@ void _mergeFromCodedBufferReader( input.readGroup(tagNumber, subMessage, registry); fs._setFieldUnchecked(meta, fi, subMessage); break; - case PbFieldTypeInternal._OPTIONAL_INT32: + case PbFieldTypeInternal.OPTIONAL_INT32: fs._setFieldUnchecked(meta, fi, input.readInt32()); break; - case PbFieldTypeInternal._OPTIONAL_INT64: + case PbFieldTypeInternal.OPTIONAL_INT64: fs._setFieldUnchecked(meta, fi, input.readInt64()); break; - case PbFieldTypeInternal._OPTIONAL_SINT32: + case PbFieldTypeInternal.OPTIONAL_SINT32: fs._setFieldUnchecked(meta, fi, input.readSint32()); break; - case PbFieldTypeInternal._OPTIONAL_SINT64: + case PbFieldTypeInternal.OPTIONAL_SINT64: fs._setFieldUnchecked(meta, fi, input.readSint64()); break; - case PbFieldTypeInternal._OPTIONAL_UINT32: + case PbFieldTypeInternal.OPTIONAL_UINT32: fs._setFieldUnchecked(meta, fi, input.readUint32()); break; - case PbFieldTypeInternal._OPTIONAL_UINT64: + case PbFieldTypeInternal.OPTIONAL_UINT64: fs._setFieldUnchecked(meta, fi, input.readUint64()); break; - case PbFieldTypeInternal._OPTIONAL_FIXED32: + case PbFieldTypeInternal.OPTIONAL_FIXED32: fs._setFieldUnchecked(meta, fi, input.readFixed32()); break; - case PbFieldTypeInternal._OPTIONAL_FIXED64: + case PbFieldTypeInternal.OPTIONAL_FIXED64: fs._setFieldUnchecked(meta, fi, input.readFixed64()); break; - case PbFieldTypeInternal._OPTIONAL_SFIXED32: + case PbFieldTypeInternal.OPTIONAL_SFIXED32: fs._setFieldUnchecked(meta, fi, input.readSfixed32()); break; - case PbFieldTypeInternal._OPTIONAL_SFIXED64: + case PbFieldTypeInternal.OPTIONAL_SFIXED64: fs._setFieldUnchecked(meta, fi, input.readSfixed64()); break; - case PbFieldTypeInternal._OPTIONAL_MESSAGE: + case PbFieldTypeInternal.OPTIONAL_MESSAGE: final GeneratedMessage? oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { input.readMessage(oldValue, registry); @@ -131,7 +131,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, subMessage); } break; - case PbFieldTypeInternal._REPEATED_BOOL: + case PbFieldTypeInternal.REPEATED_BOOL: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -151,17 +151,17 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readBool()); } break; - case PbFieldTypeInternal._REPEATED_BYTES: + case PbFieldTypeInternal.REPEATED_BYTES: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readBytes()); break; - case PbFieldTypeInternal._REPEATED_STRING: + case PbFieldTypeInternal.REPEATED_STRING: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readString()); break; - case PbFieldTypeInternal._REPEATED_FLOAT: + case PbFieldTypeInternal.REPEATED_FLOAT: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -178,7 +178,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFloat()); } break; - case PbFieldTypeInternal._REPEATED_DOUBLE: + case PbFieldTypeInternal.REPEATED_DOUBLE: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -195,7 +195,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readDouble()); } break; - case PbFieldTypeInternal._REPEATED_ENUM: + case PbFieldTypeInternal.REPEATED_ENUM: final list = fs._ensureRepeatedField(meta, fi); _readPackableToListEnum( list, @@ -207,13 +207,13 @@ void _mergeFromCodedBufferReader( registry, ); break; - case PbFieldTypeInternal._REPEATED_GROUP: + case PbFieldTypeInternal.REPEATED_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readGroup(tagNumber, subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal._REPEATED_INT32: + case PbFieldTypeInternal.REPEATED_INT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -230,7 +230,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt32()); } break; - case PbFieldTypeInternal._REPEATED_INT64: + case PbFieldTypeInternal.REPEATED_INT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -247,7 +247,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt64()); } break; - case PbFieldTypeInternal._REPEATED_SINT32: + case PbFieldTypeInternal.REPEATED_SINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -264,7 +264,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint32()); } break; - case PbFieldTypeInternal._REPEATED_SINT64: + case PbFieldTypeInternal.REPEATED_SINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -281,7 +281,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint64()); } break; - case PbFieldTypeInternal._REPEATED_UINT32: + case PbFieldTypeInternal.REPEATED_UINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -298,7 +298,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint32()); } break; - case PbFieldTypeInternal._REPEATED_UINT64: + case PbFieldTypeInternal.REPEATED_UINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -315,7 +315,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint64()); } break; - case PbFieldTypeInternal._REPEATED_FIXED32: + case PbFieldTypeInternal.REPEATED_FIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -332,7 +332,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed32()); } break; - case PbFieldTypeInternal._REPEATED_FIXED64: + case PbFieldTypeInternal.REPEATED_FIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -349,7 +349,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed64()); } break; - case PbFieldTypeInternal._REPEATED_SFIXED32: + case PbFieldTypeInternal.REPEATED_SFIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -366,7 +366,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed32()); } break; - case PbFieldTypeInternal._REPEATED_SFIXED64: + case PbFieldTypeInternal.REPEATED_SFIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -383,13 +383,13 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed64()); } break; - case PbFieldTypeInternal._REPEATED_MESSAGE: + case PbFieldTypeInternal.REPEATED_MESSAGE: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readMessage(subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal._MAP: + case PbFieldTypeInternal.MAP: final mapFieldInfo = fi as MapFieldInfo; final mapEntryMeta = mapFieldInfo.mapEntryBuilderInfo; fs diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index 6bce23985..f3f483af1 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -65,9 +65,9 @@ class CodedBufferWriter { } void writeField(int fieldNumber, int fieldType, Object? fieldValue) { - final valueType = PbFieldTypeInternal._baseType(fieldType); + final valueType = PbFieldTypeInternal.baseType(fieldType); - if ((fieldType & PbFieldTypeInternal._PACKED_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal.PACKED_BIT) != 0) { final list = fieldValue as List; if (list.isNotEmpty) { _writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); @@ -80,7 +80,7 @@ class CodedBufferWriter { return; } - if ((fieldType & PbFieldTypeInternal._MAP_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal.MAP_BIT) != 0) { final map = fieldValue as PbMap; final keyWireFormat = _wireTypes[_valueTypeIndex(map.keyFieldType)]; final valueWireFormat = _wireTypes[_valueTypeIndex(map.valueFieldType)]; @@ -107,7 +107,7 @@ class CodedBufferWriter { final wireFormat = _wireTypes[_valueTypeIndex(valueType)]; - if ((fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0) { + if ((fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0) { final list = fieldValue as List; for (var i = 0; i < list.length; i++) { _writeValue(fieldNumber, valueType, list[i], wireFormat); @@ -353,10 +353,10 @@ class CodedBufferWriter { void _writeValueAs(int valueType, dynamic value) { switch (valueType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal.BOOL_BIT: _writeVarint32(value ? 1 : 0); break; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: final List bytes = value; if (bytes is Uint8List) { _writeBytesNoTag(bytes); @@ -366,7 +366,7 @@ class CodedBufferWriter { _writeBytesNoTag(Uint8List.fromList(bytes)); } break; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: final String string = value; if (string.isEmpty) { _writeEmptyBytes(); @@ -374,17 +374,17 @@ class CodedBufferWriter { _writeBytesNoTag(const Utf8Encoder().convert(string)); } break; - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: _writeDouble(value); break; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal.FLOAT_BIT: _writeFloat(value); break; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal.ENUM_BIT: final ProtobufEnum enum_ = value; _writeVarint32(enum_.value & 0xffffffff); break; - case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal.GROUP_BIT: // `value` is `UnknownFieldSet` or `GeneratedMessage`. Test for // `UnknownFieldSet` as it doesn't have subtypes, so the type test will // be fast. @@ -399,37 +399,37 @@ class CodedBufferWriter { message.writeToCodedBufferWriter(this); } break; - case PbFieldTypeInternal._INT32_BIT: + case PbFieldTypeInternal.INT32_BIT: _writeVarint64(Int64(value)); break; - case PbFieldTypeInternal._INT64_BIT: + case PbFieldTypeInternal.INT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal._SINT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: _writeVarint32(_encodeZigZag32(value)); break; - case PbFieldTypeInternal._SINT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: _writeVarint64(_encodeZigZag64(value)); break; - case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: _writeVarint32(value); break; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: final mark = _startLengthDelimited(); final GeneratedMessage msg = value; msg.writeToCodedBufferWriter(this); @@ -459,7 +459,7 @@ class CodedBufferWriter { ) { _writeTag(fieldNumber, wireFormat); _writeValueAs(valueType, value); - if (valueType == PbFieldTypeInternal._GROUP_BIT) { + if (valueType == PbFieldTypeInternal.GROUP_BIT) { _writeTag(fieldNumber, WIRETYPE_END_GROUP); } } diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index 2535b49c1..16cb448a1 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart @@ -181,7 +181,7 @@ T _reparseMessage( final messageMapDynamic = message._fieldSet._values[field.index!]; if (messageMapDynamic == null) continue; final PbMap messageMap = messageMapDynamic; - if (_isGroupOrMessage(field.valueFieldType)) { + if (PbFieldTypeInternal.isGroupOrMessage(field.valueFieldType)) { for (final key in messageMap.keys) { final GeneratedMessage value = messageMap[key]; final reparsedValue = _reparseMessage(value, extensionRegistry); diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index 3a2494055..d8a04ad9c 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -10,53 +10,53 @@ part of 'internal.dart'; /// For enums, group, and message fields, this check is only approximate, /// because the exact type isn't included in [fieldType]. String? _getFieldError(int fieldType, var value) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: if (value is! bool) return 'not type bool'; return null; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: if (value is! List) return 'not List'; return null; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: if (value is! String) return 'not type String'; return null; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal.FLOAT_BIT: if (value is! double) return 'not type double'; if (!_isFloat32(value)) return 'out of range for float'; return null; - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: if (value is! double) return 'not type double'; return null; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal.ENUM_BIT: if (value is! ProtobufEnum) return 'not type ProtobufEnum'; return null; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: if (value is! int) return 'not type int'; if (!_isSigned32(value)) return 'out of range for signed 32-bit int'; return null; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: if (value is! int) return 'not type int'; if (!_isUnsigned32(value)) return 'out of range for unsigned 32-bit int'; return null; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 if (value is! Int64) return 'not Int64'; return null; - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: if (value is! GeneratedMessage) return 'not a GeneratedMessage'; return null; default: @@ -74,33 +74,33 @@ String? _getFieldError(int fieldType, var value) { /// @nodoc CheckFunc getCheckFunction(int fieldType) { switch (fieldType & ~0x7) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._BYTES_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: - case PbFieldTypeInternal._ENUM_BIT: - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.BOOL_BIT: + case PbFieldTypeInternal.BYTES_BIT: + case PbFieldTypeInternal.STRING_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldTypeInternal.ENUM_BIT: + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 return _checkNotNull; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldTypeInternal.FLOAT_BIT: return _checkFloat; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: return _checkSigned32; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: return _checkUnsigned32; } throw ArgumentError('check function not implemented: $fieldType'); diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 117aacddc..6f11de5cf 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -117,9 +117,11 @@ class FieldInfo { _defaultEnumValue = defaultEnumValue, assert(type != 0), assert( - !_isGroupOrMessage(type) || subBuilder != null || _isMapField(type), + !PbFieldTypeInternal.isGroupOrMessage(type) || + subBuilder != null || + PbFieldTypeInternal.isMapField(type), ), - assert(!_isEnum(type) || valueOf != null); + assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); // Represents a field that has been removed by a program transformation. FieldInfo.dummy(this.index) @@ -150,8 +152,8 @@ class FieldInfo { _valueOf = valueOf, _enumValues = enumValues, _defaultEnumValue = defaultEnumValue, - assert(_isRepeated(type)), - assert(!_isEnum(type) || valueOf != null); + assert(PbFieldTypeInternal.isRepeated(type)), + assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { if (defaultOrMaker == null) return PbFieldTypeInternal.defaultForType(type); @@ -163,11 +165,11 @@ class FieldInfo { /// been removed by a program transformation. bool get _isDummy => tagNumber == 0; - bool get isRequired => _isRequired(type); - bool get isRepeated => _isRepeated(type); - bool get isGroupOrMessage => _isGroupOrMessage(type); - bool get isEnum => _isEnum(type); - bool get isMapField => _isMapField(type); + bool get isRequired => PbFieldTypeInternal.isRequired(type); + bool get isRepeated => PbFieldTypeInternal.isRepeated(type); + bool get isGroupOrMessage => PbFieldTypeInternal.isGroupOrMessage(type); + bool get isEnum => PbFieldTypeInternal.isEnum(type); + bool get isMapField => PbFieldTypeInternal.isMapField(type); /// Returns a read-only default value for a field. Unlike /// [GeneratedMessage.getField], doesn't create a repeated field. @@ -182,7 +184,9 @@ class FieldInfo { /// That is, it doesn't contain any required fields that aren't initialized. bool _hasRequiredValues(dynamic value) { if (value == null) return !isRequired; // missing is okay if optional - if (!_isGroupOrMessage(type)) return true; // primitive and present + if (!PbFieldTypeInternal.isGroupOrMessage(type)) { + return true; // primitive and present + } if (!isRepeated) { // A required message: recurse. @@ -205,7 +209,7 @@ class FieldInfo { void _appendInvalidFields(List problems, value, String prefix) { if (value == null) { if (isRequired) problems.add('$prefix$name'); - } else if (!_isGroupOrMessage(type)) { + } else if (!PbFieldTypeInternal.isGroupOrMessage(type)) { // primitive and present } else if (!isRepeated) { // Required message/group: recurse. @@ -305,7 +309,7 @@ class MapFieldInfo extends FieldInfo?> { this.valueCreator, { ProtobufEnum? defaultEnumValue, String? protoName, - }) : assert(_isMapField(type)), + }) : assert(PbFieldTypeInternal.isMapField(type)), super( name, tagNumber, @@ -315,7 +319,7 @@ class MapFieldInfo extends FieldInfo?> { defaultEnumValue: defaultEnumValue, protoName: protoName, ) { - assert(!_isEnum(type) || valueOf != null); + assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); } FieldInfo get valueFieldInfo => diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index aee73b7b8..f7c260883 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -626,11 +626,11 @@ class FieldSet { } hash = HashUtils.combine(hash, fi.tagNumber); - if (_isBytes(fi.type)) { + if (PbFieldTypeInternal.isBytes(fi.type)) { // Bytes are represented as a List (Usually with byte-data). // We special case that to match our equality semantics. hash = HashUtils.combine(hash, HashUtils.hashObjects(value)); - } else if (!_isEnum(fi.type)) { + } else if (!PbFieldTypeInternal.isEnum(fi.type)) { hash = HashUtils.combine(hash, value.hashCode); } else if (fi.isRepeated) { final PbList list = value; @@ -772,7 +772,7 @@ class FieldSet { final MapFieldInfo f = fi as dynamic; final PbMap map = f._ensureMapField(meta, this) as dynamic; - if (_isGroupOrMessage(f.valueFieldType)) { + if (PbFieldTypeInternal.isGroupOrMessage(f.valueFieldType)) { final PbMap fieldValueMap = fieldValue; for (final entry in fieldValueMap.entries) { map[entry.key] = entry.value.deepCopy(); @@ -784,7 +784,7 @@ class FieldSet { } if (fi.isRepeated) { - if (_isGroupOrMessage(otherFi.type)) { + if (PbFieldTypeInternal.isGroupOrMessage(otherFi.type)) { // fieldValue must be a PbList of GeneratedMessage. final PbList pbList = fieldValue; final repeatedFields = fi._ensureRepeatedField(meta, this); diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index 80ed423bd..a3e6cb4ae 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -5,258 +5,256 @@ // ignore_for_file: constant_identifier_names,non_constant_identifier_names part of 'internal.dart'; -bool _isRepeated(int fieldType) => - (fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0; +/// Defines constants and functions for dealing with fieldType bits. +class PbFieldTypeInternal { + static bool isRepeated(int fieldType) => + (fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0; -bool _isRequired(int fieldType) => - (fieldType & PbFieldTypeInternal._REQUIRED_BIT) != 0; + static bool isRequired(int fieldType) => + (fieldType & PbFieldTypeInternal.REQUIRED_BIT) != 0; -bool _isEnum(int fieldType) => - PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._ENUM_BIT; + static bool isEnum(int fieldType) => + PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.ENUM_BIT; -bool _isBytes(int fieldType) => - PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._BYTES_BIT; + static bool isBytes(int fieldType) => + PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.BYTES_BIT; -bool _isGroupOrMessage(int fieldType) => - (fieldType & - (PbFieldTypeInternal._GROUP_BIT | PbFieldTypeInternal._MESSAGE_BIT)) != - 0; + static bool isGroupOrMessage(int fieldType) => + (fieldType & + (PbFieldTypeInternal.GROUP_BIT | PbFieldTypeInternal.MESSAGE_BIT)) != + 0; -bool _isMapField(int fieldType) => - (fieldType & PbFieldTypeInternal._MAP_BIT) != 0; + static bool isMapField(int fieldType) => + (fieldType & PbFieldTypeInternal.MAP_BIT) != 0; -/// Defines constants and functions for dealing with fieldType bits. -class PbFieldTypeInternal { /// Returns the base field type without any of the required, repeated /// and packed bits. - static int _baseType(int fieldType) => - fieldType & ~(_REQUIRED_BIT | _REPEATED_BIT | _PACKED_BIT | _MAP_BIT); + static int baseType(int fieldType) => + fieldType & ~(REQUIRED_BIT | REPEATED_BIT | PACKED_BIT | MAP_BIT); static MakeDefaultFunc? defaultForType(int type) { switch (type) { - case _OPTIONAL_BOOL: - case _REQUIRED_BOOL: - return _BOOL_FALSE; - case _OPTIONAL_BYTES: - case _REQUIRED_BYTES: - return _BYTES_EMPTY; - case _OPTIONAL_STRING: - case _REQUIRED_STRING: - return _STRING_EMPTY; - case _OPTIONAL_FLOAT: - case _REQUIRED_FLOAT: - case _OPTIONAL_DOUBLE: - case _REQUIRED_DOUBLE: - return _DOUBLE_ZERO; - case _OPTIONAL_INT32: - case _REQUIRED_INT32: - case _OPTIONAL_INT64: - case _REQUIRED_INT64: - case _OPTIONAL_SINT32: - case _REQUIRED_SINT32: - case _OPTIONAL_SINT64: - case _REQUIRED_SINT64: - case _OPTIONAL_UINT32: - case _REQUIRED_UINT32: - case _OPTIONAL_UINT64: - case _REQUIRED_UINT64: - case _OPTIONAL_FIXED32: - case _REQUIRED_FIXED32: - case _OPTIONAL_FIXED64: - case _REQUIRED_FIXED64: - case _OPTIONAL_SFIXED32: - case _REQUIRED_SFIXED32: - case _OPTIONAL_SFIXED64: - case _REQUIRED_SFIXED64: - return _INT_ZERO; + case OPTIONAL_BOOL: + case REQUIRED_BOOL: + return BOOL_FALSE; + case OPTIONAL_BYTES: + case REQUIRED_BYTES: + return BYTES_EMPTY; + case OPTIONAL_STRING: + case REQUIRED_STRING: + return STRING_EMPTY; + case OPTIONAL_FLOAT: + case REQUIRED_FLOAT: + case OPTIONAL_DOUBLE: + case REQUIRED_DOUBLE: + return DOUBLE_ZERO; + case OPTIONAL_INT32: + case REQUIRED_INT32: + case OPTIONAL_INT64: + case REQUIRED_INT64: + case OPTIONAL_SINT32: + case REQUIRED_SINT32: + case OPTIONAL_SINT64: + case REQUIRED_SINT64: + case OPTIONAL_UINT32: + case REQUIRED_UINT32: + case OPTIONAL_UINT64: + case REQUIRED_UINT64: + case OPTIONAL_FIXED32: + case REQUIRED_FIXED32: + case OPTIONAL_FIXED64: + case REQUIRED_FIXED64: + case OPTIONAL_SFIXED32: + case REQUIRED_SFIXED32: + case OPTIONAL_SFIXED64: + case REQUIRED_SFIXED64: + return INT_ZERO; default: return null; } } // Closures commonly used by initializers. - static String _STRING_EMPTY() => ''; - static List _BYTES_EMPTY() => []; - static bool _BOOL_FALSE() => false; - static int _INT_ZERO() => 0; - static double _DOUBLE_ZERO() => 0.0; + static String STRING_EMPTY() => ''; + static List BYTES_EMPTY() => []; + static bool BOOL_FALSE() => false; + static int INT_ZERO() => 0; + static double DOUBLE_ZERO() => 0.0; - static const int _REQUIRED_BIT = 0x1; - static const int _REPEATED_BIT = 0x2; - static const int _PACKED_BIT = 0x4; + static const int REQUIRED_BIT = 0x1; + static const int REPEATED_BIT = 0x2; + static const int PACKED_BIT = 0x4; - static const int _BOOL_BIT = 0x10; - static const int _BYTES_BIT = 0x20; - static const int _STRING_BIT = 0x40; - static const int _DOUBLE_BIT = 0x80; - static const int _FLOAT_BIT = 0x100; - static const int _ENUM_BIT = 0x200; - static const int _GROUP_BIT = 0x400; - static const int _INT32_BIT = 0x800; - static const int _INT64_BIT = 0x1000; - static const int _SINT32_BIT = 0x2000; - static const int _SINT64_BIT = 0x4000; - static const int _UINT32_BIT = 0x8000; - static const int _UINT64_BIT = 0x10000; - static const int _FIXED32_BIT = 0x20000; - static const int _FIXED64_BIT = 0x40000; - static const int _SFIXED32_BIT = 0x80000; - static const int _SFIXED64_BIT = 0x100000; - static const int _MESSAGE_BIT = 0x200000; - static const int _MAP_BIT = 0x400000; + static const int BOOL_BIT = 0x10; + static const int BYTES_BIT = 0x20; + static const int STRING_BIT = 0x40; + static const int DOUBLE_BIT = 0x80; + static const int FLOAT_BIT = 0x100; + static const int ENUM_BIT = 0x200; + static const int GROUP_BIT = 0x400; + static const int INT32_BIT = 0x800; + static const int INT64_BIT = 0x1000; + static const int SINT32_BIT = 0x2000; + static const int SINT64_BIT = 0x4000; + static const int UINT32_BIT = 0x8000; + static const int UINT64_BIT = 0x10000; + static const int FIXED32_BIT = 0x20000; + static const int FIXED64_BIT = 0x40000; + static const int SFIXED32_BIT = 0x80000; + static const int SFIXED64_BIT = 0x100000; + static const int MESSAGE_BIT = 0x200000; + static const int MAP_BIT = 0x400000; - static const int _OPTIONAL_BOOL = _BOOL_BIT; - static const int _OPTIONAL_BYTES = _BYTES_BIT; - static const int _OPTIONAL_STRING = _STRING_BIT; - static const int _OPTIONAL_FLOAT = _FLOAT_BIT; - static const int _OPTIONAL_DOUBLE = _DOUBLE_BIT; - static const int _OPTIONAL_ENUM = _ENUM_BIT; - static const int _OPTIONAL_GROUP = _GROUP_BIT; - static const int _OPTIONAL_INT32 = _INT32_BIT; - static const int _OPTIONAL_INT64 = _INT64_BIT; - static const int _OPTIONAL_SINT32 = _SINT32_BIT; - static const int _OPTIONAL_SINT64 = _SINT64_BIT; - static const int _OPTIONAL_UINT32 = _UINT32_BIT; - static const int _OPTIONAL_UINT64 = _UINT64_BIT; - static const int _OPTIONAL_FIXED32 = _FIXED32_BIT; - static const int _OPTIONAL_FIXED64 = _FIXED64_BIT; - static const int _OPTIONAL_SFIXED32 = _SFIXED32_BIT; - static const int _OPTIONAL_SFIXED64 = _SFIXED64_BIT; - static const int _OPTIONAL_MESSAGE = _MESSAGE_BIT; + static const int OPTIONAL_BOOL = BOOL_BIT; + static const int OPTIONAL_BYTES = BYTES_BIT; + static const int OPTIONAL_STRING = STRING_BIT; + static const int OPTIONAL_FLOAT = FLOAT_BIT; + static const int OPTIONAL_DOUBLE = DOUBLE_BIT; + static const int OPTIONAL_ENUM = ENUM_BIT; + static const int OPTIONAL_GROUP = GROUP_BIT; + static const int OPTIONAL_INT32 = INT32_BIT; + static const int OPTIONAL_INT64 = INT64_BIT; + static const int OPTIONAL_SINT32 = SINT32_BIT; + static const int OPTIONAL_SINT64 = SINT64_BIT; + static const int OPTIONAL_UINT32 = UINT32_BIT; + static const int OPTIONAL_UINT64 = UINT64_BIT; + static const int OPTIONAL_FIXED32 = FIXED32_BIT; + static const int OPTIONAL_FIXED64 = FIXED64_BIT; + static const int OPTIONAL_SFIXED32 = SFIXED32_BIT; + static const int OPTIONAL_SFIXED64 = SFIXED64_BIT; + static const int OPTIONAL_MESSAGE = MESSAGE_BIT; - static const int _REQUIRED_BOOL = _REQUIRED_BIT | _BOOL_BIT; - static const int _REQUIRED_BYTES = _REQUIRED_BIT | _BYTES_BIT; - static const int _REQUIRED_STRING = _REQUIRED_BIT | _STRING_BIT; - static const int _REQUIRED_FLOAT = _REQUIRED_BIT | _FLOAT_BIT; - static const int _REQUIRED_DOUBLE = _REQUIRED_BIT | _DOUBLE_BIT; - static const int _REQUIRED_ENUM = _REQUIRED_BIT | _ENUM_BIT; - static const int _REQUIRED_GROUP = _REQUIRED_BIT | _GROUP_BIT; - static const int _REQUIRED_INT32 = _REQUIRED_BIT | _INT32_BIT; - static const int _REQUIRED_INT64 = _REQUIRED_BIT | _INT64_BIT; - static const int _REQUIRED_SINT32 = _REQUIRED_BIT | _SINT32_BIT; - static const int _REQUIRED_SINT64 = _REQUIRED_BIT | _SINT64_BIT; - static const int _REQUIRED_UINT32 = _REQUIRED_BIT | _UINT32_BIT; - static const int _REQUIRED_UINT64 = _REQUIRED_BIT | _UINT64_BIT; - static const int _REQUIRED_FIXED32 = _REQUIRED_BIT | _FIXED32_BIT; - static const int _REQUIRED_FIXED64 = _REQUIRED_BIT | _FIXED64_BIT; - static const int _REQUIRED_SFIXED32 = _REQUIRED_BIT | _SFIXED32_BIT; - static const int _REQUIRED_SFIXED64 = _REQUIRED_BIT | _SFIXED64_BIT; - static const int _REQUIRED_MESSAGE = _REQUIRED_BIT | _MESSAGE_BIT; + static const int REQUIRED_BOOL = REQUIRED_BIT | BOOL_BIT; + static const int REQUIRED_BYTES = REQUIRED_BIT | BYTES_BIT; + static const int REQUIRED_STRING = REQUIRED_BIT | STRING_BIT; + static const int REQUIRED_FLOAT = REQUIRED_BIT | FLOAT_BIT; + static const int REQUIRED_DOUBLE = REQUIRED_BIT | DOUBLE_BIT; + static const int REQUIRED_ENUM = REQUIRED_BIT | ENUM_BIT; + static const int REQUIRED_GROUP = REQUIRED_BIT | GROUP_BIT; + static const int REQUIRED_INT32 = REQUIRED_BIT | INT32_BIT; + static const int REQUIRED_INT64 = REQUIRED_BIT | INT64_BIT; + static const int REQUIRED_SINT32 = REQUIRED_BIT | SINT32_BIT; + static const int REQUIRED_SINT64 = REQUIRED_BIT | SINT64_BIT; + static const int REQUIRED_UINT32 = REQUIRED_BIT | UINT32_BIT; + static const int REQUIRED_UINT64 = REQUIRED_BIT | UINT64_BIT; + static const int REQUIRED_FIXED32 = REQUIRED_BIT | FIXED32_BIT; + static const int REQUIRED_FIXED64 = REQUIRED_BIT | FIXED64_BIT; + static const int REQUIRED_SFIXED32 = REQUIRED_BIT | SFIXED32_BIT; + static const int REQUIRED_SFIXED64 = REQUIRED_BIT | SFIXED64_BIT; + static const int REQUIRED_MESSAGE = REQUIRED_BIT | MESSAGE_BIT; - static const int _REPEATED_BOOL = _REPEATED_BIT | _BOOL_BIT; - static const int _REPEATED_BYTES = _REPEATED_BIT | _BYTES_BIT; - static const int _REPEATED_STRING = _REPEATED_BIT | _STRING_BIT; - static const int _REPEATED_FLOAT = _REPEATED_BIT | _FLOAT_BIT; - static const int _REPEATED_DOUBLE = _REPEATED_BIT | _DOUBLE_BIT; - static const int _REPEATED_ENUM = _REPEATED_BIT | _ENUM_BIT; - static const int _REPEATED_GROUP = _REPEATED_BIT | _GROUP_BIT; - static const int _REPEATED_INT32 = _REPEATED_BIT | _INT32_BIT; - static const int _REPEATED_INT64 = _REPEATED_BIT | _INT64_BIT; - static const int _REPEATED_SINT32 = _REPEATED_BIT | _SINT32_BIT; - static const int _REPEATED_SINT64 = _REPEATED_BIT | _SINT64_BIT; - static const int _REPEATED_UINT32 = _REPEATED_BIT | _UINT32_BIT; - static const int _REPEATED_UINT64 = _REPEATED_BIT | _UINT64_BIT; - static const int _REPEATED_FIXED32 = _REPEATED_BIT | _FIXED32_BIT; - static const int _REPEATED_FIXED64 = _REPEATED_BIT | _FIXED64_BIT; - static const int _REPEATED_SFIXED32 = _REPEATED_BIT | _SFIXED32_BIT; - static const int _REPEATED_SFIXED64 = _REPEATED_BIT | _SFIXED64_BIT; - static const int _REPEATED_MESSAGE = _REPEATED_BIT | _MESSAGE_BIT; + static const int REPEATED_BOOL = REPEATED_BIT | BOOL_BIT; + static const int REPEATED_BYTES = REPEATED_BIT | BYTES_BIT; + static const int REPEATED_STRING = REPEATED_BIT | STRING_BIT; + static const int REPEATED_FLOAT = REPEATED_BIT | FLOAT_BIT; + static const int REPEATED_DOUBLE = REPEATED_BIT | DOUBLE_BIT; + static const int REPEATED_ENUM = REPEATED_BIT | ENUM_BIT; + static const int REPEATED_GROUP = REPEATED_BIT | GROUP_BIT; + static const int REPEATED_INT32 = REPEATED_BIT | INT32_BIT; + static const int REPEATED_INT64 = REPEATED_BIT | INT64_BIT; + static const int REPEATED_SINT32 = REPEATED_BIT | SINT32_BIT; + static const int REPEATED_SINT64 = REPEATED_BIT | SINT64_BIT; + static const int REPEATED_UINT32 = REPEATED_BIT | UINT32_BIT; + static const int REPEATED_UINT64 = REPEATED_BIT | UINT64_BIT; + static const int REPEATED_FIXED32 = REPEATED_BIT | FIXED32_BIT; + static const int REPEATED_FIXED64 = REPEATED_BIT | FIXED64_BIT; + static const int REPEATED_SFIXED32 = REPEATED_BIT | SFIXED32_BIT; + static const int REPEATED_SFIXED64 = REPEATED_BIT | SFIXED64_BIT; + static const int REPEATED_MESSAGE = REPEATED_BIT | MESSAGE_BIT; - static const int _PACKED_BOOL = _REPEATED_BIT | _PACKED_BIT | _BOOL_BIT; - static const int _PACKED_FLOAT = _REPEATED_BIT | _PACKED_BIT | _FLOAT_BIT; - static const int _PACKED_DOUBLE = _REPEATED_BIT | _PACKED_BIT | _DOUBLE_BIT; - static const int _PACKED_ENUM = _REPEATED_BIT | _PACKED_BIT | _ENUM_BIT; - static const int _PACKED_INT32 = _REPEATED_BIT | _PACKED_BIT | _INT32_BIT; - static const int _PACKED_INT64 = _REPEATED_BIT | _PACKED_BIT | _INT64_BIT; - static const int _PACKED_SINT32 = _REPEATED_BIT | _PACKED_BIT | _SINT32_BIT; - static const int _PACKED_SINT64 = _REPEATED_BIT | _PACKED_BIT | _SINT64_BIT; - static const int _PACKED_UINT32 = _REPEATED_BIT | _PACKED_BIT | _UINT32_BIT; - static const int _PACKED_UINT64 = _REPEATED_BIT | _PACKED_BIT | _UINT64_BIT; - static const int _PACKED_FIXED32 = _REPEATED_BIT | _PACKED_BIT | _FIXED32_BIT; - static const int _PACKED_FIXED64 = _REPEATED_BIT | _PACKED_BIT | _FIXED64_BIT; - static const int _PACKED_SFIXED32 = - _REPEATED_BIT | _PACKED_BIT | _SFIXED32_BIT; - static const int _PACKED_SFIXED64 = - _REPEATED_BIT | _PACKED_BIT | _SFIXED64_BIT; + static const int PACKED_BOOL = REPEATED_BIT | PACKED_BIT | BOOL_BIT; + static const int PACKED_FLOAT = REPEATED_BIT | PACKED_BIT | FLOAT_BIT; + static const int PACKED_DOUBLE = REPEATED_BIT | PACKED_BIT | DOUBLE_BIT; + static const int PACKED_ENUM = REPEATED_BIT | PACKED_BIT | ENUM_BIT; + static const int PACKED_INT32 = REPEATED_BIT | PACKED_BIT | INT32_BIT; + static const int PACKED_INT64 = REPEATED_BIT | PACKED_BIT | INT64_BIT; + static const int PACKED_SINT32 = REPEATED_BIT | PACKED_BIT | SINT32_BIT; + static const int PACKED_SINT64 = REPEATED_BIT | PACKED_BIT | SINT64_BIT; + static const int PACKED_UINT32 = REPEATED_BIT | PACKED_BIT | UINT32_BIT; + static const int PACKED_UINT64 = REPEATED_BIT | PACKED_BIT | UINT64_BIT; + static const int PACKED_FIXED32 = REPEATED_BIT | PACKED_BIT | FIXED32_BIT; + static const int PACKED_FIXED64 = REPEATED_BIT | PACKED_BIT | FIXED64_BIT; + static const int PACKED_SFIXED32 = REPEATED_BIT | PACKED_BIT | SFIXED32_BIT; + static const int PACKED_SFIXED64 = REPEATED_BIT | PACKED_BIT | SFIXED64_BIT; - static const int _MAP = _MAP_BIT | _MESSAGE_BIT; + static const int MAP = MAP_BIT | MESSAGE_BIT; // Short names for use in generated code. // _O_ptional. - static const int OB = _OPTIONAL_BOOL; - static const int OY = _OPTIONAL_BYTES; - static const int OS = _OPTIONAL_STRING; - static const int OF = _OPTIONAL_FLOAT; - static const int OD = _OPTIONAL_DOUBLE; - static const int OE = _OPTIONAL_ENUM; - static const int OG = _OPTIONAL_GROUP; - static const int O3 = _OPTIONAL_INT32; - static const int O6 = _OPTIONAL_INT64; - static const int OS3 = _OPTIONAL_SINT32; - static const int OS6 = _OPTIONAL_SINT64; - static const int OU3 = _OPTIONAL_UINT32; - static const int OU6 = _OPTIONAL_UINT64; - static const int OF3 = _OPTIONAL_FIXED32; - static const int OF6 = _OPTIONAL_FIXED64; - static const int OSF3 = _OPTIONAL_SFIXED32; - static const int OSF6 = _OPTIONAL_SFIXED64; - static const int OM = _OPTIONAL_MESSAGE; + static const int OB = OPTIONAL_BOOL; + static const int OY = OPTIONAL_BYTES; + static const int OS = OPTIONAL_STRING; + static const int OF = OPTIONAL_FLOAT; + static const int OD = OPTIONAL_DOUBLE; + static const int OE = OPTIONAL_ENUM; + static const int OG = OPTIONAL_GROUP; + static const int O3 = OPTIONAL_INT32; + static const int O6 = OPTIONAL_INT64; + static const int OS3 = OPTIONAL_SINT32; + static const int OS6 = OPTIONAL_SINT64; + static const int OU3 = OPTIONAL_UINT32; + static const int OU6 = OPTIONAL_UINT64; + static const int OF3 = OPTIONAL_FIXED32; + static const int OF6 = OPTIONAL_FIXED64; + static const int OSF3 = OPTIONAL_SFIXED32; + static const int OSF6 = OPTIONAL_SFIXED64; + static const int OM = OPTIONAL_MESSAGE; // re_Q_uired. - static const int QB = _REQUIRED_BOOL; - static const int QY = _REQUIRED_BYTES; - static const int QS = _REQUIRED_STRING; - static const int QF = _REQUIRED_FLOAT; - static const int QD = _REQUIRED_DOUBLE; - static const int QE = _REQUIRED_ENUM; - static const int QG = _REQUIRED_GROUP; - static const int Q3 = _REQUIRED_INT32; - static const int Q6 = _REQUIRED_INT64; - static const int QS3 = _REQUIRED_SINT32; - static const int QS6 = _REQUIRED_SINT64; - static const int QU3 = _REQUIRED_UINT32; - static const int QU6 = _REQUIRED_UINT64; - static const int QF3 = _REQUIRED_FIXED32; - static const int QF6 = _REQUIRED_FIXED64; - static const int QSF3 = _REQUIRED_SFIXED32; - static const int QSF6 = _REQUIRED_SFIXED64; - static const int QM = _REQUIRED_MESSAGE; + static const int QB = REQUIRED_BOOL; + static const int QY = REQUIRED_BYTES; + static const int QS = REQUIRED_STRING; + static const int QF = REQUIRED_FLOAT; + static const int QD = REQUIRED_DOUBLE; + static const int QE = REQUIRED_ENUM; + static const int QG = REQUIRED_GROUP; + static const int Q3 = REQUIRED_INT32; + static const int Q6 = REQUIRED_INT64; + static const int QS3 = REQUIRED_SINT32; + static const int QS6 = REQUIRED_SINT64; + static const int QU3 = REQUIRED_UINT32; + static const int QU6 = REQUIRED_UINT64; + static const int QF3 = REQUIRED_FIXED32; + static const int QF6 = REQUIRED_FIXED64; + static const int QSF3 = REQUIRED_SFIXED32; + static const int QSF6 = REQUIRED_SFIXED64; + static const int QM = REQUIRED_MESSAGE; // re_P_eated. - static const int PB = _REPEATED_BOOL; - static const int PY = _REPEATED_BYTES; - static const int PS = _REPEATED_STRING; - static const int PF = _REPEATED_FLOAT; - static const int PD = _REPEATED_DOUBLE; - static const int PE = _REPEATED_ENUM; - static const int PG = _REPEATED_GROUP; - static const int P3 = _REPEATED_INT32; - static const int P6 = _REPEATED_INT64; - static const int PS3 = _REPEATED_SINT32; - static const int PS6 = _REPEATED_SINT64; - static const int PU3 = _REPEATED_UINT32; - static const int PU6 = _REPEATED_UINT64; - static const int PF3 = _REPEATED_FIXED32; - static const int PF6 = _REPEATED_FIXED64; - static const int PSF3 = _REPEATED_SFIXED32; - static const int PSF6 = _REPEATED_SFIXED64; - static const int PM = _REPEATED_MESSAGE; + static const int PB = REPEATED_BOOL; + static const int PY = REPEATED_BYTES; + static const int PS = REPEATED_STRING; + static const int PF = REPEATED_FLOAT; + static const int PD = REPEATED_DOUBLE; + static const int PE = REPEATED_ENUM; + static const int PG = REPEATED_GROUP; + static const int P3 = REPEATED_INT32; + static const int P6 = REPEATED_INT64; + static const int PS3 = REPEATED_SINT32; + static const int PS6 = REPEATED_SINT64; + static const int PU3 = REPEATED_UINT32; + static const int PU6 = REPEATED_UINT64; + static const int PF3 = REPEATED_FIXED32; + static const int PF6 = REPEATED_FIXED64; + static const int PSF3 = REPEATED_SFIXED32; + static const int PSF6 = REPEATED_SFIXED64; + static const int PM = REPEATED_MESSAGE; // pac_K_ed. - static const int KB = _PACKED_BOOL; - static const int KE = _PACKED_ENUM; - static const int KF = _PACKED_FLOAT; - static const int KD = _PACKED_DOUBLE; - static const int K3 = _PACKED_INT32; - static const int K6 = _PACKED_INT64; - static const int KS3 = _PACKED_SINT32; - static const int KS6 = _PACKED_SINT64; - static const int KU3 = _PACKED_UINT32; - static const int KU6 = _PACKED_UINT64; - static const int KF3 = _PACKED_FIXED32; - static const int KF6 = _PACKED_FIXED64; - static const int KSF3 = _PACKED_SFIXED32; - static const int KSF6 = _PACKED_SFIXED64; + static const int KB = PACKED_BOOL; + static const int KE = PACKED_ENUM; + static const int KF = PACKED_FLOAT; + static const int KD = PACKED_DOUBLE; + static const int K3 = PACKED_INT32; + static const int K6 = PACKED_INT64; + static const int KS3 = PACKED_SINT32; + static const int KS6 = PACKED_SINT64; + static const int KU3 = PACKED_UINT32; + static const int KU6 = PACKED_UINT64; + static const int KF3 = PACKED_FIXED32; + static const int KF6 = PACKED_FIXED64; + static const int KSF3 = PACKED_SFIXED32; + static const int KSF6 = PACKED_SFIXED64; - static const int M = _MAP; + static const int M = MAP; } diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 28f4992b0..0660a072f 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -418,7 +418,7 @@ abstract class GeneratedMessage { /// Sets the value of a non-repeated extension field to [value]. void setExtension(Extension extension, Object value) { - if (_isRepeated(extension.type)) { + if (PbFieldTypeInternal.isRepeated(extension.type)) { throw ArgumentError( _fieldSet._setFieldFailedMessage( extension, diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index 361f1d0e9..df74de5be 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -6,24 +6,24 @@ part of 'internal.dart'; Map _writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { - final baseType = PbFieldTypeInternal._baseType(fieldType); + final baseType = PbFieldTypeInternal.baseType(fieldType); - if (_isRepeated(fieldType)) { + if (PbFieldTypeInternal.isRepeated(fieldType)) { final PbList list = fieldValue; return List.from(list.map((e) => convertToMap(e, baseType))); } switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.BOOL_BIT: + case PbFieldTypeInternal.STRING_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { return nan; @@ -35,22 +35,22 @@ Map _writeToJsonMap(FieldSet fs) { return fieldValue.toInt(); } return value; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: // Encode 'bytes' as a base64-encoded string. return base64Encode(fieldValue as List); - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal.ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value; // assume |value| < 2^52 - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned(); - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: @@ -73,7 +73,7 @@ Map _writeToJsonMap(FieldSet fs) { if (value == null || (value is List && value.isEmpty)) { continue; // It's missing, repeated, or an empty byte array. } - if (_isMapField(fi.type)) { + if (PbFieldTypeInternal.isMapField(fi.type)) { result['${fi.tagNumber}'] = writeMap( value, fi as MapFieldInfo, @@ -246,8 +246,8 @@ dynamic _convertJsonValue( ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: if (value is bool) { return value; } else if (value is String) { @@ -265,20 +265,20 @@ dynamic _convertJsonValue( } expectedType = 'bool (true, false, "true", "false", 1, 0)'; break; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: if (value is String) { return base64Decode(value); } expectedType = 'Base64 String'; break; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: if (value is String) { return value; } expectedType = 'String'; break; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value is double) { return value; @@ -289,7 +289,7 @@ dynamic _convertJsonValue( } expectedType = 'num or stringified num'; break; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal.ENUM_BIT: // Allow quoted values, although we don't emit them. if (value is String) { value = int.parse(value); @@ -302,15 +302,15 @@ dynamic _convertJsonValue( } expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: if (value is int) return value; if (value is String) return int.parse(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: int? validatedValue; if (value is int) validatedValue = value; if (value is String) validatedValue = int.parse(value); @@ -320,17 +320,17 @@ dynamic _convertJsonValue( if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) return Int64.parseInt(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; final subMessage = meta._makeEmptyMessage(tagNumber, registry); diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index f9c5379d9..0d929091a 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -4,6 +4,9 @@ part of 'internal.dart'; +const mapKeyFieldNumber = 1; +const mapValueFieldNumber = 2; + /// A [MapBase] implementation used for protobuf `map` fields. class PbMap extends MapBase { /// Key type of the map. Per proto2 and proto3 specs, this needs to be an @@ -121,7 +124,7 @@ class PbMap extends MapBase { PbMap freeze() { _isReadOnly = true; - if (_isGroupOrMessage(valueFieldType)) { + if (PbFieldTypeInternal.isGroupOrMessage(valueFieldType)) { for (final subMessage in values as Iterable) { subMessage.freeze(); } diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index b6b1f0383..61632bc1a 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -6,26 +6,26 @@ part of 'internal.dart'; Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { - final baseType = PbFieldTypeInternal._baseType(keyType); + final baseType = PbFieldTypeInternal.baseType(keyType); - assert(!_isRepeated(keyType)); + assert(!PbFieldTypeInternal.isRepeated(keyType)); switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal.BOOL_BIT: return key ? 'true' : 'false'; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: return key; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: return (key as Int64).toStringUnsigned(); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: return key.toString(); default: throw StateError('Not a valid key type $keyType'); @@ -35,33 +35,33 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { Object? valueToProto3Json(dynamic fieldValue, int? fieldType) { if (fieldValue == null) return null; - if (_isGroupOrMessage(fieldType!)) { + if (PbFieldTypeInternal.isGroupOrMessage(fieldType!)) { return _writeToProto3Json( (fieldValue as GeneratedMessage)._fieldSet, typeRegistry, ); - } else if (_isEnum(fieldType)) { + } else if (PbFieldTypeInternal.isEnum(fieldType)) { return (fieldValue as ProtobufEnum).name; } else { - final baseType = PbFieldTypeInternal._baseType(fieldType); + final baseType = PbFieldTypeInternal.baseType(fieldType); switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldTypeInternal.BOOL_BIT: return fieldValue as bool; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: return fieldValue; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return nan; @@ -73,9 +73,9 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { return value.toInt(); } return value; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: return (fieldValue as Int64).toStringUnsigned(); - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: return base64Encode(fieldValue); default: throw StateError( @@ -176,13 +176,13 @@ void _mergeFromProto3Json( void recursionHelper(Object? json, FieldSet fieldSet) { Object? convertProto3JsonValue(Object value, FieldInfo fieldInfo) { final fieldType = fieldInfo.type; - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: if (value is bool) { return value; } throw context.parseException('Expected bool value', json); - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldTypeInternal.BYTES_BIT: if (value is String) { Uint8List result; try { @@ -199,13 +199,13 @@ void _mergeFromProto3Json( 'Expected bytes encoded as base64 String', value, ); - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: if (value is String) { return value; } throw context.parseException('Expected String value', value); - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: if (value is double) { return value; } else if (value is num) { @@ -221,7 +221,7 @@ void _mergeFromProto3Json( 'Expected a double represented as a String or number', value, ); - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldTypeInternal.ENUM_BIT: if (value is String) { // TODO(sigurdm): Do we want to avoid linear search here? Measure... final result = @@ -245,8 +245,8 @@ void _mergeFromProto3Json( 'Expected enum as a string or integer', value, ); - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: int result; if (value is int) { result = value; @@ -259,9 +259,9 @@ void _mergeFromProto3Json( ); } return _check32BitUnsignedProto3(result, context); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: int result; if (value is int) { result = value; @@ -275,7 +275,7 @@ void _mergeFromProto3Json( } _check32BitSignedProto3(result, context); return result; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: Int64 result; if (value is int) { result = Int64(value); @@ -288,10 +288,10 @@ void _mergeFromProto3Json( ); } return result; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) { Int64 result; @@ -309,8 +309,8 @@ void _mergeFromProto3Json( 'Expected int or stringified int', value, ); - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: final subMessage = fieldInfo.subBuilder!(); recursionHelper(value, subMessage._fieldSet); return subMessage; @@ -320,8 +320,8 @@ void _mergeFromProto3Json( } Object decodeMapKey(String key, int fieldType) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: switch (key) { case 'true': return true; @@ -333,26 +333,26 @@ void _mergeFromProto3Json( key, ); } - case PbFieldTypeInternal._STRING_BIT: + case PbFieldTypeInternal.STRING_BIT: return key; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: // TODO(sigurdm): We do not throw on negative values here. // That would probably require going via bignum. return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: return _check32BitSignedProto3( _tryParse32BitProto3(key, context), context, ); - case PbFieldTypeInternal._UINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: return _check32BitUnsignedProto3( _tryParse32BitProto3(key, context), context, @@ -400,7 +400,7 @@ void _mergeFromProto3Json( } } - if (_isMapField(fieldInfo.type)) { + if (PbFieldTypeInternal.isMapField(fieldInfo.type)) { if (value is Map) { final mapFieldInfo = fieldInfo as MapFieldInfo; final Map fieldValues = fieldSet._ensureMapField(meta, fieldInfo); @@ -421,7 +421,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a map', value); } - } else if (_isRepeated(fieldInfo.type)) { + } else if (PbFieldTypeInternal.isRepeated(fieldInfo.type)) { if (value is List) { final values = fieldSet._ensureRepeatedField(meta, fieldInfo); for (var i = 0; i < value.length; i++) { @@ -433,7 +433,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a list', value); } - } else if (_isGroupOrMessage(fieldInfo.type)) { + } else if (PbFieldTypeInternal.isGroupOrMessage(fieldInfo.type)) { // TODO(sigurdm) consider a cleaner separation between parsing and // merging. final parsedSubMessage = diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 906ca5a71..9702c5670 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -283,11 +283,11 @@ class UnknownFieldSetField { output.writeField(fieldNumber, type, value); } - write(PbFieldTypeInternal._REPEATED_UINT64, varints); - write(PbFieldTypeInternal._REPEATED_FIXED32, fixed32s); - write(PbFieldTypeInternal._REPEATED_FIXED64, fixed64s); - write(PbFieldTypeInternal._REPEATED_BYTES, lengthDelimited); - write(PbFieldTypeInternal._REPEATED_GROUP, groups); + write(PbFieldTypeInternal.REPEATED_UINT64, varints); + write(PbFieldTypeInternal.REPEATED_FIXED32, fixed32s); + write(PbFieldTypeInternal.REPEATED_FIXED64, fixed64s); + write(PbFieldTypeInternal.REPEATED_BYTES, lengthDelimited); + write(PbFieldTypeInternal.REPEATED_GROUP, groups); } void addGroup(UnknownFieldSet value) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index 6a2536270..16e400b4a 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -38,32 +38,32 @@ int makeTag(int fieldNumber, int tag) => (fieldNumber << _TAG_TYPE_BITS) | tag; /// Returns true if the wireType can be merged into the given fieldType. bool _wireTypeMatches(int fieldType, int wireType) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._ENUM_BIT: - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._UINT64_BIT: + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: + case PbFieldTypeInternal.ENUM_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.UINT64_BIT: return wireType == WIRETYPE_VARINT || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: return wireType == WIRETYPE_FIXED32 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._DOUBLE_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: return wireType == WIRETYPE_FIXED64 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._BYTES_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldTypeInternal.BYTES_BIT: + case PbFieldTypeInternal.STRING_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: return wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._GROUP_BIT: + case PbFieldTypeInternal.GROUP_BIT: return wireType == WIRETYPE_START_GROUP; default: return false; From 0a5d2b226ee9e11c313ad50603c138904cb273a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 10:47:01 +0100 Subject: [PATCH 05/22] Sync web decoders --- .../lib/src/protobuf/generated_message.dart | 6 +- protobuf/lib/src/protobuf/internal.dart | 2 +- .../lib/src/protobuf/{ => json}/json.dart | 62 +-- protobuf/lib/src/protobuf/json/json_vm.dart | 23 + protobuf/lib/src/protobuf/json/json_web.dart | 447 ++++++++++++++++++ 5 files changed, 509 insertions(+), 31 deletions(-) rename protobuf/lib/src/protobuf/{ => json}/json.dart (86%) create mode 100644 protobuf/lib/src/protobuf/json/json_vm.dart create mode 100644 protobuf/lib/src/protobuf/json/json_web.dart diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 0660a072f..e711381f5 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -227,7 +227,7 @@ abstract class GeneratedMessage { /// Unknown field data, data for which there is no metadata for the associated /// field, will only be included if this message was deserialized from the /// same wire format. - Map writeToJsonMap() => _writeToJsonMap(_fieldSet); + Map writeToJsonMap() => json_lib.writeToJsonMap(_fieldSet); /// Returns a JSON string that encodes this message. /// @@ -326,7 +326,7 @@ abstract class GeneratedMessage { data, reviver: _emptyReviver, ); - _mergeFromJsonMap(_fieldSet, jsonMap, extensionRegistry); + json_lib.mergeFromJsonMap(_fieldSet, jsonMap, extensionRegistry); } static Object? _emptyReviver(Object? k, Object? v) => v; @@ -338,7 +338,7 @@ abstract class GeneratedMessage { Map json, [ ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY, ]) { - _mergeFromJsonMap(_fieldSet, json, extensionRegistry); + json_lib.mergeFromJsonMap(_fieldSet, json, extensionRegistry); } /// Adds an extension field value to a repeated field. diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart index 176084d77..a91205d04 100644 --- a/protobuf/lib/src/protobuf/internal.dart +++ b/protobuf/lib/src/protobuf/internal.dart @@ -23,6 +23,7 @@ import 'package:fixnum/fixnum.dart' show Int64; import 'package:meta/meta.dart' show UseResult; import 'consts.dart'; +import 'json/json.dart' as json_lib; import 'json_parsing_context.dart'; import 'permissive_compare.dart'; import 'type_registry.dart'; @@ -45,7 +46,6 @@ part 'field_set.dart'; part 'field_type.dart'; part 'generated_message.dart'; part 'generated_service.dart'; -part 'json.dart'; part 'message_set.dart'; part 'pb_list.dart'; part 'pb_map.dart'; diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json/json.dart similarity index 86% rename from protobuf/lib/src/protobuf/json.dart rename to protobuf/lib/src/protobuf/json/json.dart index df74de5be..d32e336c5 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json/json.dart @@ -2,9 +2,17 @@ // 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. -part of 'internal.dart'; +import 'dart:convert' show base64Decode, base64Encode; -Map _writeToJsonMap(FieldSet fs) { +import 'package:fixnum/fixnum.dart' show Int64; + +import '../consts.dart'; +import '../internal.dart'; +import '../utils.dart'; + +export 'json_vm.dart' if (dart.library.js_interop) 'json_web.dart'; + +Map writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { final baseType = PbFieldTypeInternal.baseType(fieldType); @@ -61,15 +69,15 @@ Map _writeToJsonMap(FieldSet fs) { List writeMap(PbMap fieldValue, MapFieldInfo fi) => List.from( fieldValue.entries.map( (MapEntry e) => { - '${PbMap._keyFieldNumber}': convertToMap(e.key, fi.keyFieldType), - '${PbMap._valueFieldNumber}': convertToMap(e.value, fi.valueFieldType), + '$mapKeyFieldNumber': convertToMap(e.key, fi.keyFieldType), + '$mapValueFieldNumber': convertToMap(e.value, fi.valueFieldType), }, ), ); final result = {}; - for (final fi in fs._infosSortedByTag) { - final value = fs._values[fi.index!]; + for (final fi in fs.infosSortedByTag) { + final value = fs.values[fi.index!]; if (value == null || (value is List && value.isEmpty)) { continue; // It's missing, repeated, or an empty byte array. } @@ -82,18 +90,18 @@ Map _writeToJsonMap(FieldSet fs) { } result['${fi.tagNumber}'] = convertToMap(value, fi.type); } - final extensions = fs._extensions; + final extensions = fs.extensions; if (extensions != null) { - for (final tagNumber in sorted(extensions._tagNumbers)) { - final value = extensions._values[tagNumber]; + for (final tagNumber in sorted(extensions.tagNumbers)) { + final value = extensions.values[tagNumber]; if (value is List && value.isEmpty) { continue; // It's repeated or an empty byte array. } - final fi = extensions._getInfoOrNull(tagNumber)!; + final fi = extensions.getInfoOrNull(tagNumber)!; result['$tagNumber'] = convertToMap(value, fi.type); } } - final unknownJsonData = fs._unknownJsonData; + final unknownJsonData = fs.unknownJsonData; if (unknownJsonData != null) { unknownJsonData.forEach((key, value) { result[key] = value; @@ -104,20 +112,20 @@ Map _writeToJsonMap(FieldSet fs) { // Merge fields from a previously decoded JSON object. // (Called recursively on nested messages.) -void _mergeFromJsonMap( +void mergeFromJsonMap( FieldSet fs, Map json, ExtensionRegistry? registry, ) { - fs._ensureWritable(); + fs.ensureWritable(); final keys = json.keys; - final meta = fs._meta; + final meta = fs.meta; for (final key in keys) { var fi = meta.byTagAsString[key]; if (fi == null) { - fi = registry?.getExtension(fs._messageName, int.parse(key)); + fi = registry?.getExtension(fs.messageName, int.parse(key)); if (fi == null) { - (fs._unknownJsonData ??= {})[key] = json[key]; + (fs.unknownJsonData ??= {})[key] = json[key]; continue; } } @@ -144,7 +152,7 @@ void _appendJsonList( FieldInfo fi, ExtensionRegistry? registry, ) { - final repeated = fi._ensureRepeatedField(meta, fs); + final repeated = fi.ensureRepeatedField(meta, fs); // Micro optimization. Using "for in" generates the following and iterator // alloc: // for (t1 = J.get$iterator$ax(json), t2 = fi.tagNumber, t3 = fi.type, @@ -175,23 +183,23 @@ void _appendJsonMap( ExtensionRegistry? registry, ) { final entryMeta = fi.mapEntryBuilderInfo; - final map = fi._ensureMapField(meta, fs); + final map = fi.ensureMapField(meta, fs); for (final jsonEntryDynamic in jsonList) { final jsonEntry = jsonEntryDynamic as Map; final entryFieldSet = FieldSet(null, entryMeta); final convertedKey = _convertJsonValue( entryMeta, entryFieldSet, - jsonEntry['${PbMap._keyFieldNumber}'], - PbMap._keyFieldNumber, + jsonEntry['$mapKeyFieldNumber'], + mapKeyFieldNumber, fi.keyFieldType, registry, ); var convertedValue = _convertJsonValue( entryMeta, entryFieldSet, - jsonEntry['${PbMap._valueFieldNumber}'], - PbMap._valueFieldNumber, + jsonEntry['$mapValueFieldNumber'], + mapValueFieldNumber, fi.valueFieldType, registry, ); @@ -223,10 +231,10 @@ void _setJsonField( // Therefore we run _validateField for debug builds only to validate // correctness of conversion. assert(() { - fs._validateField(fi, value); + fs.validateField(fi, value); return true; }()); - fs._setFieldUnchecked(meta, fi, value); + fs.setFieldUnchecked(meta, fi, value); } /// Converts [value] from the JSON format to the Dart data type suitable for @@ -298,7 +306,7 @@ dynamic _convertJsonValue( // The following call will return null if the enum value is unknown. // In that case, we want the caller to ignore this value, so we return // null from this method as well. - return meta._decodeEnum(tagNumber, registry, value); + return meta.decodeEnum(tagNumber, registry, value); } expectedType = 'int or stringified int'; break; @@ -333,8 +341,8 @@ dynamic _convertJsonValue( case PbFieldTypeInternal.MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; - final subMessage = meta._makeEmptyMessage(tagNumber, registry); - _mergeFromJsonMap(subMessage._fieldSet, messageValue, registry); + final subMessage = meta.makeEmptyMessage(tagNumber, registry); + mergeFromJsonMap(subMessage.fieldSet, messageValue, registry); return subMessage; } expectedType = 'nested message or group'; diff --git a/protobuf/lib/src/protobuf/json/json_vm.dart b/protobuf/lib/src/protobuf/json/json_vm.dart new file mode 100644 index 000000000..8f09e7f7d --- /dev/null +++ b/protobuf/lib/src/protobuf/json/json_vm.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2015, 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:convert' show jsonDecode, jsonEncode; + +import '../internal.dart'; +import 'json.dart'; + +String writeToJsonString(FieldSet fs) => jsonEncode(writeToJsonMap(fs)); + +/// Merge fields from a [json] string. +void mergeFromJsonString( + FieldSet fs, + String json, + ExtensionRegistry? registry, +) { + final jsonMap = jsonDecode(json); + if (jsonMap is! Map) { + throw ArgumentError.value(json, 'json', 'Does not parse to a JSON object.'); + } + mergeFromJsonMap(fs, jsonMap, registry); +} diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart new file mode 100644 index 000000000..d4e30e728 --- /dev/null +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -0,0 +1,447 @@ +// Copyright (c) 2015, 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:convert' show base64Decode, base64Encode; +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; + +import 'package:fixnum/fixnum.dart' show Int64; + +import '../consts.dart'; +import '../internal.dart'; +import '../utils.dart'; + +@JS('JSON') +extension type JSON._(JSObject _) implements JSObject { + external static JSString stringify(JSObject value); + external static JSAny? parse(JSString text); +} + +@JS('Number') +extension type Number._(JSObject _) implements JSObject { + external static bool isInteger(JSAny value); +} + +@JS('Object.keys') +external JSArray objectKeys(JSObject obj); + +@JS('Object.prototype') +external JSObject get objectPrototype; + +@JS('Object.getPrototypeOf') +external JSObject getPrototypeOf(JSAny obj); + +extension on JSAny { + /// Returns this typed as [T] while omitting the `as` cast. For use after an + /// `isA` check. + @pragma('dart2js:as:trust') + @pragma('dart2js:prefer-inline') + T as() => this as T; +} + +String writeToJsonString(FieldSet fs) { + final rawJs = _writeToRawJs(fs); + return JSON.stringify(rawJs).toDart; +} + +JSObject _writeToRawJs(FieldSet fs) { + JSAny convertToRawJs(dynamic fieldValue, int fieldType) { + final baseType = PbFieldTypeInternal.baseType(fieldType); + + if (PbFieldTypeInternal.isRepeated(fieldType)) { + final PbList list = fieldValue; + final length = list.length; + final jsArray = JSArray.withLength(length); + for (var i = 0; i < length; i++) { + final entry = list[i]; + jsArray[i] = convertToRawJs(entry, baseType); + } + return jsArray; + } + + switch (baseType) { + case PbFieldTypeInternal.BOOL_BIT: + case PbFieldTypeInternal.STRING_BIT: + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: + return fieldValue; + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: + final value = fieldValue as double; + if (value.isNaN) { + return nan.toJS; + } + if (value.isInfinite) { + return value.isNegative ? negativeInfinity.toJS : infinity.toJS; + } + if (fieldValue.toInt() == fieldValue) { + return fieldValue.toInt().toJS; + } + return value.toJS; + case PbFieldTypeInternal.BYTES_BIT: + // Encode 'bytes' as a base64-encoded string. + return base64Encode(fieldValue as List).toJS; + case PbFieldTypeInternal.ENUM_BIT: + final ProtobufEnum enum_ = fieldValue; + return enum_.value.toJS; // assume |value| < 2^52 + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + return fieldValue.toString().toJS; + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + final Int64 int_ = fieldValue; + return int_.toStringUnsigned().toJS; + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: + final GeneratedMessage msg = fieldValue; + return _writeToRawJs(msg.fieldSet); + default: + throw UnsupportedError('Unknown type $fieldType'); + } + } + + JSArray writeMap(PbMap fieldValue, MapFieldInfo fi) { + final length = fieldValue.entries.length; + final jsArray = JSArray.withLength(length); + var index = 0; + for (final entry in fieldValue.entries) { + final entryJsObj = JSObject(); + entryJsObj.setProperty( + mapKeyFieldNumber.toJS, + convertToRawJs(entry.key, fi.keyFieldType), + ); + entryJsObj.setProperty( + mapValueFieldNumber.toJS, + convertToRawJs(entry.value, fi.valueFieldType), + ); + jsArray[index] = entryJsObj; + index++; + } + return jsArray; + } + + final result = JSObject(); + for (final fi in fs.infosSortedByTag) { + final value = fs.values[fi.index!]; + if (value == null || (value is List && value.isEmpty)) { + continue; // It's missing, repeated, or an empty byte array. + } + if (PbFieldTypeInternal.isMapField(fi.type)) { + result.setProperty( + fi.tagNumber.toJS, + writeMap(value, fi as MapFieldInfo), + ); + continue; + } + result.setProperty(fi.tagNumber.toJS, convertToRawJs(value, fi.type)); + } + final extensions = fs.extensions; + if (extensions != null) { + for (final tagNumber in sorted(extensions.tagNumbers)) { + final value = extensions.values[tagNumber]; + if (value is List && value.isEmpty) { + continue; // It's repeated or an empty byte array. + } + final fi = extensions.getInfoOrNull(tagNumber)!; + result.setProperty(tagNumber.toJS, convertToRawJs(value, fi.type)); + } + } + final unknownJsonData = fs.unknownJsonData; + if (unknownJsonData != null) { + unknownJsonData.forEach((key, value) { + result.setProperty(key.toJS, value); + }); + } + return result; +} + +/// Merge fields from a [json] string. +void mergeFromJsonString( + FieldSet fs, + String json, + ExtensionRegistry? registry, +) { + final JSAny? parsed; + try { + parsed = JSON.parse(json.toJS); + } catch (e) { + throw FormatException(e.toString()); + } + if (parsed == null || !parsed.isA()) { + throw ArgumentError.value(json, 'json', 'Does not parse to a JSON object.'); + } + _mergeFromRawJsMap(fs, parsed.as(), registry); +} + +void _mergeFromRawJsMap( + FieldSet fs, + JSObject json, + ExtensionRegistry? registry, +) { + fs.ensureWritable(); + + final meta = fs.meta; + final keys = objectKeys(json); + final length = keys.length; + for (var i = 0; i < length; i++) { + final jsKey = keys[i]; + final key = jsKey.toDart; + var fi = meta.byTagAsString[key]; + if (fi == null) { + fi = registry?.getExtension(fs.messageName, int.parse(key)); + if (fi == null) { + (fs.unknownJsonData ??= {})[key] = json.getProperty(jsKey); + continue; + } + } + if (fi.isMapField) { + _appendRawJsMap( + meta, + fs, + json.getProperty>(jsKey), + fi as MapFieldInfo, + registry, + ); + } else if (fi.isRepeated) { + _appendRawJsList( + meta, + fs, + json.getProperty>(jsKey), + fi, + registry, + ); + } else { + _setRawJsField(meta, fs, json.getProperty(jsKey), fi, registry); + } + } +} + +void _appendRawJsList( + BuilderInfo meta, + FieldSet fs, + JSArray jsonList, + FieldInfo fi, + ExtensionRegistry? registry, +) { + final repeated = fi.ensureRepeatedField(meta, fs); + // Micro optimization. Using "for in" generates the following and iterator + // alloc: + // for (t1 = J.get$iterator$ax(json), t2 = fi.tagNumber, t3 = fi.type, + // t4 = J.getInterceptor$ax(repeated); t1.moveNext$0();) + final length = jsonList.length; + for (var i = 0; i < length; i++) { + final value = jsonList[i]; + var convertedValue = _convertRawJsValue( + meta, + fs, + value, + fi.tagNumber, + fi.type, + registry, + ); + // In the case of an unknown enum value, the converted value may return + // null. The default enum value should be used in these cases, which is + // stored in the FieldInfo. + convertedValue ??= fi.defaultEnumValue; + repeated.add(convertedValue); + } +} + +void _appendRawJsMap( + BuilderInfo meta, + FieldSet fs, + JSArray jsonList, + MapFieldInfo fi, + ExtensionRegistry? registry, +) { + final entryMeta = fi.mapEntryBuilderInfo; + final map = fi.ensureMapField(meta, fs); + final length = jsonList.length; + + for (var i = 0; i < length; i++) { + final value = jsonList[i]; + final entryFieldSet = FieldSet(null, entryMeta); + + final convertedKey = _convertRawJsValue( + entryMeta, + entryFieldSet, + value.getProperty(mapKeyFieldNumber.toJS), + mapKeyFieldNumber, + fi.keyFieldType, + registry, + ); + var convertedValue = _convertRawJsValue( + entryMeta, + entryFieldSet, + value.getProperty(mapValueFieldNumber.toJS), + mapValueFieldNumber, + fi.valueFieldType, + registry, + ); + // In the case of an unknown enum value, the converted value may return + // null. The default enum value should be used in these cases, which is + // stored in the FieldInfo. + convertedValue ??= fi.defaultEnumValue; + map[convertedKey] = convertedValue; + } +} + +void _setRawJsField( + BuilderInfo meta, + FieldSet fs, + JSAny json, + FieldInfo fi, + ExtensionRegistry? registry, +) { + final value = _convertRawJsValue( + meta, + fs, + json, + fi.tagNumber, + fi.type, + registry, + ); + if (value == null) return; + // _convertRawJsValue throws exception when it fails to do conversion. + // Therefore we run _validateField for debug builds only to validate + // correctness of conversion. + assert(() { + fs.validateField(fi, value); + return true; + }()); + fs.setFieldUnchecked(meta, fi, value); +} + +/// Converts [value] from the JSON format to the Dart data type suitable for +/// inserting into the corresponding [GeneratedMessage] field. +/// +/// Returns the converted value. Returns `null` if it is an unknown enum value, +/// in which case the caller should figure out the default enum value to return +/// instead. +/// +/// Throws [ArgumentError] if it cannot convert the value. +Object? _convertRawJsValue( + BuilderInfo meta, + FieldSet fs, + JSAny value, + int tagNumber, + int fieldType, + ExtensionRegistry? registry, +) { + String expectedType; // for exception message + switch (PbFieldTypeInternal.baseType(fieldType)) { + case PbFieldTypeInternal.BOOL_BIT: + if (value.isA()) { + return value.as().toDart; + } else if (value.isA()) { + final dartStr = value.as().toDart; + if (dartStr == 'true') { + return true; + } else if (dartStr == 'false') { + return false; + } + } else if (value.isA()) { + final dartNum = value.as().toDartDouble; + if (dartNum == 1) { + return true; + } else if (dartNum == 0) { + return false; + } + } + expectedType = 'bool (true, false, "true", "false", 1, 0)'; + case PbFieldTypeInternal.BYTES_BIT: + if (value.isA()) { + return base64Decode(value.as().toDart); + } + expectedType = 'Base64 String'; + case PbFieldTypeInternal.STRING_BIT: + if (value.isA()) { + return value.as().toDart; + } + expectedType = 'String'; + case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldTypeInternal.DOUBLE_BIT: + // Allow quoted values, although we don't emit them. + if (value.isA()) { + final jsNum = value.as(); + return Number.isInteger(jsNum) ? jsNum.toDartInt : jsNum.toDartDouble; + } else if (value.isA()) { + return double.parse(value.as().toDart); + } + expectedType = 'num or stringified num'; + case PbFieldTypeInternal.ENUM_BIT: + // Allow quoted values, although we don't emit them. + if (value.isA()) { + value = int.parse(value.as().toDart).toJS; + } + if (Number.isInteger(value)) { + // The following call will return null if the enum value is unknown. + // In that case, we want the caller to ignore this value, so we return + // null from this method as well. + return meta.decodeEnum( + tagNumber, + registry, + value.as().toDartInt, + ); + } + expectedType = 'int or stringified int'; + case PbFieldTypeInternal.INT32_BIT: + case PbFieldTypeInternal.SINT32_BIT: + case PbFieldTypeInternal.SFIXED32_BIT: + if (Number.isInteger(value)) { + return value.as().toDartInt; + } + if (value.isA()) { + return int.parse(value.as().toDart); + } + expectedType = 'int or stringified int'; + case PbFieldTypeInternal.UINT32_BIT: + case PbFieldTypeInternal.FIXED32_BIT: + int? validatedValue; + if (Number.isInteger(value)) { + validatedValue = value.as().toDartInt; + } + if (value.isA()) { + validatedValue = int.parse(value.as().toDart); + } + if (validatedValue != null && validatedValue < 0) { + validatedValue += 2 * (1 << 31); + } + if (validatedValue != null) return validatedValue; + expectedType = 'int or stringified int'; + case PbFieldTypeInternal.INT64_BIT: + case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.UINT64_BIT: + case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + if (Number.isInteger(value)) { + return Int64(value.as().toDartInt); + } + if (value.isA()) { + return Int64.parseInt(value.as().toDart); + } + expectedType = 'int or stringified int'; + case PbFieldTypeInternal.GROUP_BIT: + case PbFieldTypeInternal.MESSAGE_BIT: + if (getPrototypeOf(value).strictEquals(objectPrototype).toDart) { + final subMessage = meta.makeEmptyMessage(tagNumber, registry); + _mergeFromRawJsMap(subMessage.fieldSet, value.as(), registry); + return subMessage; + } + expectedType = 'nested message or group'; + default: + throw ArgumentError( + 'Unknown type $fieldType when decoding a ' + '${meta.qualifiedMessageName} message field with tag $tagNumber.', + ); + } + throw ArgumentError( + 'Expected type $expectedType, got $value when decoding a ' + '${meta.qualifiedMessageName} message field with tag $tagNumber.', + ); +} From 32911d8427cbaa4907b4525dbf85659dbca9820d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 13:05:06 +0100 Subject: [PATCH 06/22] Export ExtensionRegistry --- protobuf/lib/protobuf.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index 5936d56df..d55474d76 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -13,6 +13,7 @@ export 'src/protobuf/internal.dart' EnumFieldInfoExtension, ExtensionFieldSet, ExtensionFieldSetInternalExtension, + ExtensionRegistry, FieldInfoInternalExtension, FieldSet, FieldSetInternalExtension, From e821977776783680c56b44f08947c5d1d7753c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Fri, 18 Jul 2025 13:06:44 +0100 Subject: [PATCH 07/22] Revert "Export ExtensionRegistry" This reverts commit 32911d8427cbaa4907b4525dbf85659dbca9820d. --- protobuf/lib/protobuf.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index d55474d76..5936d56df 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -13,7 +13,6 @@ export 'src/protobuf/internal.dart' EnumFieldInfoExtension, ExtensionFieldSet, ExtensionFieldSetInternalExtension, - ExtensionRegistry, FieldInfoInternalExtension, FieldSet, FieldSetInternalExtension, From 877adf8e8df58db81191df2475dc97db755bbbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 21 Jul 2025 11:27:03 +0100 Subject: [PATCH 08/22] Update GeneratedMessage.{writeToJson,mergeFromJson} --- protobuf/lib/src/protobuf/generated_message.dart | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index e711381f5..6f0f984a8 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -246,7 +246,7 @@ abstract class GeneratedMessage { /// Unknown field data, data for which there is no metadata for the associated /// field, will only be included if this message was deserialized from the /// same wire format. - String writeToJson() => jsonEncode(writeToJsonMap()); + String writeToJson() => json_lib.writeToJsonString(_fieldSet); /// Returns an Object representing Proto3 JSON serialization of `this`. /// @@ -318,15 +318,7 @@ abstract class GeneratedMessage { String data, [ ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY, ]) { - /// Disable lazy creation of Dart objects for a dart2js speedup. - /// This is a slight regression on the Dart VM. - /// TODO(skybrian) we could skip the reviver if we're running - /// on the Dart VM for a slight speedup. - final Map jsonMap = jsonDecode( - data, - reviver: _emptyReviver, - ); - json_lib.mergeFromJsonMap(_fieldSet, jsonMap, extensionRegistry); + json_lib.mergeFromJsonString(_fieldSet, data, extensionRegistry); } static Object? _emptyReviver(Object? k, Object? v) => v; From 11eecbc5ce2b81fb240384ceb6b9c63f6f6165c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 21 Jul 2025 11:52:01 +0100 Subject: [PATCH 09/22] Remove unused member --- protobuf/lib/src/protobuf/generated_message.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 6f0f984a8..7c8073281 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -321,8 +321,6 @@ abstract class GeneratedMessage { json_lib.mergeFromJsonString(_fieldSet, data, extensionRegistry); } - static Object? _emptyReviver(Object? k, Object? v) => v; - /// Merges field values from a JSON object represented as a Dart map. /// /// The encoding is described in [GeneratedMessage.writeToJson]. From 83390eaae2e587cec51fd9ef2038cf7d3928d4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 21 Jul 2025 11:52:17 +0100 Subject: [PATCH 10/22] Fix js_interop usage in serialization --- protobuf/lib/src/protobuf/json/json_web.dart | 27 +++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index d4e30e728..96c14cec1 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -61,17 +61,25 @@ JSObject _writeToRawJs(FieldSet fs) { } switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.STRING_BIT: case PbFieldTypeInternal.INT32_BIT: case PbFieldTypeInternal.SINT32_BIT: case PbFieldTypeInternal.UINT32_BIT: case PbFieldTypeInternal.FIXED32_BIT: case PbFieldTypeInternal.SFIXED32_BIT: - return fieldValue; + final int value = fieldValue; + return value.toJS; + + case PbFieldTypeInternal.BOOL_BIT: + final bool value = fieldValue; + return value.toJS; + + case PbFieldTypeInternal.STRING_BIT: + final String value = fieldValue; + return value.toJS; + case PbFieldTypeInternal.FLOAT_BIT: case PbFieldTypeInternal.DOUBLE_BIT: - final value = fieldValue as double; + final double value = fieldValue; if (value.isNaN) { return nan.toJS; } @@ -82,24 +90,29 @@ JSObject _writeToRawJs(FieldSet fs) { return fieldValue.toInt().toJS; } return value.toJS; + case PbFieldTypeInternal.BYTES_BIT: // Encode 'bytes' as a base64-encoded string. - return base64Encode(fieldValue as List).toJS; + final List value = fieldValue; + return base64Encode(value).toJS; + case PbFieldTypeInternal.ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value.toJS; // assume |value| < 2^52 + case PbFieldTypeInternal.INT64_BIT: case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - return fieldValue.toString().toJS; case PbFieldTypeInternal.UINT64_BIT: case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned().toJS; + case PbFieldTypeInternal.GROUP_BIT: case PbFieldTypeInternal.MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return _writeToRawJs(msg.fieldSet); + default: throw UnsupportedError('Unknown type $fieldType'); } From 96b5dc06574df2decca0d47492c1ff11e2f8f5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 21 Jul 2025 11:55:44 +0100 Subject: [PATCH 11/22] Fix sint serialization --- protobuf/lib/src/protobuf/json/json_web.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index 96c14cec1..bd699ed51 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -102,9 +102,12 @@ JSObject _writeToRawJs(FieldSet fs) { case PbFieldTypeInternal.INT64_BIT: case PbFieldTypeInternal.SINT64_BIT: + case PbFieldTypeInternal.SFIXED64_BIT: + final Int64 int_ = fieldValue; + return int_.toString().toJS; + case PbFieldTypeInternal.UINT64_BIT: case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned().toJS; From afd49a75966fd12c11466e58e9859aa486cc6a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 21 Jul 2025 12:55:45 +0100 Subject: [PATCH 12/22] Remove a dynamic invo --- protobuf/lib/src/protobuf/json/json_web.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index bd699ed51..eeb74ec47 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -86,8 +86,8 @@ JSObject _writeToRawJs(FieldSet fs) { if (value.isInfinite) { return value.isNegative ? negativeInfinity.toJS : infinity.toJS; } - if (fieldValue.toInt() == fieldValue) { - return fieldValue.toInt().toJS; + if (value.toInt() == value) { + return value.toInt().toJS; } return value.toJS; From c5acfd39ca9bda91f763102f6889c1130789db5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 10:49:43 +0100 Subject: [PATCH 13/22] Fix warning --- protobuf/lib/src/protobuf/internal.dart | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart index a91205d04..e3a29d072 100644 --- a/protobuf/lib/src/protobuf/internal.dart +++ b/protobuf/lib/src/protobuf/internal.dart @@ -8,14 +8,7 @@ library; import 'dart:collection' show ListBase, MapBase; -import 'dart:convert' - show - Utf8Decoder, - Utf8Encoder, - base64Decode, - base64Encode, - jsonDecode, - jsonEncode; +import 'dart:convert' show Utf8Decoder, Utf8Encoder, base64Decode, base64Encode; import 'dart:math' as math; import 'dart:typed_data' show ByteData, Endian, Uint8List; From be75e06fa6c522bedf78d465c0599bf8627ec239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:03:02 +0100 Subject: [PATCH 14/22] Revert some of the changes --- protobuf/lib/protobuf.dart | 1 - protobuf/lib/src/protobuf/field_info.dart | 36 ++++++++--------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index 5936d56df..2c6ef8391 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -10,7 +10,6 @@ library; export 'src/protobuf/internal.dart' hide BuilderInfoInternalExtension, - EnumFieldInfoExtension, ExtensionFieldSet, ExtensionFieldSetInternalExtension, FieldInfoInternalExtension, diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 117aacddc..587c499b8 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -81,17 +81,17 @@ class FieldInfo { /// List of all enum values. /// /// Only available in enum fields. - final List? _enumValues; + final List? enumValues; /// Default enum value. /// /// Only available in enum fields. - final ProtobufEnum? _defaultEnumValue; + final ProtobufEnum? defaultEnumValue; /// Mapping from enum integer values to enum values. /// /// Only available in enum fields. - final ValueOfFunc? _valueOf; + final ValueOfFunc? valueOf; /// Function to verify items when adding to a repeated field. /// @@ -105,16 +105,13 @@ class FieldInfo { this.type, { dynamic defaultOrMaker, this.subBuilder, - ValueOfFunc? valueOf, - List? enumValues, - ProtobufEnum? defaultEnumValue, + this.valueOf, + this.enumValues, + this.defaultEnumValue, String? protoName, }) : makeDefault = findMakeDefault(type, defaultOrMaker), check = null, _protoName = protoName, - _valueOf = valueOf, - _enumValues = enumValues, - _defaultEnumValue = defaultEnumValue, assert(type != 0), assert( !_isGroupOrMessage(type) || subBuilder != null || _isMapField(type), @@ -128,10 +125,10 @@ class FieldInfo { tagNumber = 0, type = 0, makeDefault = null, - _valueOf = null, + valueOf = null, check = null, - _enumValues = null, - _defaultEnumValue = null, + enumValues = null, + defaultEnumValue = null, subBuilder = null; FieldInfo.repeated( @@ -141,15 +138,12 @@ class FieldInfo { this.type, CheckFunc this.check, this.subBuilder, { - ValueOfFunc? valueOf, - List? enumValues, - ProtobufEnum? defaultEnumValue, + this.valueOf, + this.enumValues, + this.defaultEnumValue, String? protoName, }) : makeDefault = (() => PbList(check: check)), _protoName = protoName, - _valueOf = valueOf, - _enumValues = enumValues, - _defaultEnumValue = defaultEnumValue, assert(_isRepeated(type)), assert(!_isEnum(type) || valueOf != null); @@ -258,12 +252,6 @@ extension FieldInfoInternalExtension on FieldInfo { _ensureRepeatedField(meta, fs); } -extension EnumFieldInfoExtension on FieldInfo { - ValueOfFunc? get valueOf => _valueOf; - List? get enumValues => _enumValues; - ProtobufEnum? get defaultEnumValue => _defaultEnumValue; -} - final RegExp _upperCase = RegExp('[A-Z]'); String _unCamelCase(String name) { From 34afcf8fdaa4e6e737b40670c30446eb2810581e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:36:15 +0100 Subject: [PATCH 15/22] Revert renaming --- protobuf/lib/src/protobuf/builder_info.dart | 24 +-- protobuf/lib/src/protobuf/coded_buffer.dart | 77 +++++---- .../lib/src/protobuf/coded_buffer_writer.dart | 46 ++--- protobuf/lib/src/protobuf/field_error.dart | 74 ++++---- protobuf/lib/src/protobuf/field_info.dart | 4 +- protobuf/lib/src/protobuf/field_type.dart | 19 +-- protobuf/lib/src/protobuf/json.dart | 76 ++++----- protobuf/lib/src/protobuf/proto3_json.dart | 122 ++++++------- .../lib/src/protobuf/unknown_field_set.dart | 10 +- protobuf/lib/src/protobuf/wire_format.dart | 38 ++--- protobuf/test/codec_test.dart | 23 ++- protobuf/test/list_test.dart | 12 +- protobuf/test/mock_util.dart | 20 +-- protobuf/test/readonly_message_test.dart | 12 +- protoc_plugin/lib/src/base_type.dart | 2 +- .../lib/src/gen/dart_options.pb.dart | 18 +- .../lib/src/gen/google/api/client.pb.dart | 38 ++--- .../lib/src/gen/google/api/http.pb.dart | 4 +- .../lib/src/gen/google/api/routing.pb.dart | 4 +- .../google/protobuf/compiler/plugin.pb.dart | 18 +- .../gen/google/protobuf/descriptor.pb.dart | 160 +++++++++--------- .../src/gen/google/protobuf/duration.pb.dart | 2 +- protoc_plugin/lib/src/protobuf_field.dart | 14 +- protoc_plugin/test/goldens/extension.pb.dart | 2 +- .../test/goldens/messageGenerator.pb.dart | 4 +- .../goldens/messageGenerator.pb.dart.meta | 64 +++---- protoc_plugin/test/goldens/oneMessage.pb.dart | 5 +- .../test/goldens/oneMessage.pb.dart.meta | 48 +++--- 28 files changed, 458 insertions(+), 482 deletions(-) diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index 56cce4608..24af8110c 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -105,7 +105,7 @@ class BuilderInfo { name, tagNumber, index, - PbFieldTypeInternal.M, + PbFieldType.M, keyFieldType, valueFieldType, mapEntryBuilderInfo, @@ -179,13 +179,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.OS String with no default value to reduce generated + /// Adds PbFieldType.OS String with no default value to reduce generated /// code size. void aOS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.OS, + PbFieldType.OS, null, null, null, @@ -194,13 +194,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.PS String with no default value. + /// Adds PbFieldType.PS String with no default value. void pPS(int tagNumber, String name, {String? protoName}) { addRepeated( tagNumber, name, - PbFieldTypeInternal.PS, - getCheckFunction(PbFieldTypeInternal.PS), + PbFieldType.PS, + getCheckFunction(PbFieldType.PS), null, null, null, @@ -208,12 +208,12 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.QS String with no default value. + /// Adds PbFieldType.QS String with no default value. void aQS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.QS, + PbFieldType.QS, null, null, null, @@ -227,7 +227,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.O6, + PbFieldType.O6, Int64.ZERO, null, null, @@ -241,7 +241,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OB, + PbFieldType.OB, null, null, null, @@ -321,7 +321,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OM, + PbFieldType.OM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, @@ -339,7 +339,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.QM, + PbFieldType.QM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index 137d735b7..92102654f 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -54,25 +54,24 @@ void _mergeFromCodedBufferReader( // Ignore required/optional packed/unpacked. var fieldType = fi.type; - fieldType &= - ~(PbFieldTypeInternal._PACKED_BIT | PbFieldTypeInternal._REQUIRED_BIT); + fieldType &= ~(PbFieldType._PACKED_BIT | PbFieldType._REQUIRED_BIT); switch (fieldType) { - case PbFieldTypeInternal._OPTIONAL_BOOL: + case PbFieldType._OPTIONAL_BOOL: fs._setFieldUnchecked(meta, fi, input.readBool()); break; - case PbFieldTypeInternal._OPTIONAL_BYTES: + case PbFieldType._OPTIONAL_BYTES: fs._setFieldUnchecked(meta, fi, input.readBytes()); break; - case PbFieldTypeInternal._OPTIONAL_STRING: + case PbFieldType._OPTIONAL_STRING: fs._setFieldUnchecked(meta, fi, input.readString()); break; - case PbFieldTypeInternal._OPTIONAL_FLOAT: + case PbFieldType._OPTIONAL_FLOAT: fs._setFieldUnchecked(meta, fi, input.readFloat()); break; - case PbFieldTypeInternal._OPTIONAL_DOUBLE: + case PbFieldType._OPTIONAL_DOUBLE: fs._setFieldUnchecked(meta, fi, input.readDouble()); break; - case PbFieldTypeInternal._OPTIONAL_ENUM: + case PbFieldType._OPTIONAL_ENUM: final rawValue = input.readEnum(); final value = meta._decodeEnum(tagNumber, registry, rawValue); if (value == null) { @@ -82,7 +81,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, value); } break; - case PbFieldTypeInternal._OPTIONAL_GROUP: + case PbFieldType._OPTIONAL_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); final oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { @@ -91,37 +90,37 @@ void _mergeFromCodedBufferReader( input.readGroup(tagNumber, subMessage, registry); fs._setFieldUnchecked(meta, fi, subMessage); break; - case PbFieldTypeInternal._OPTIONAL_INT32: + case PbFieldType._OPTIONAL_INT32: fs._setFieldUnchecked(meta, fi, input.readInt32()); break; - case PbFieldTypeInternal._OPTIONAL_INT64: + case PbFieldType._OPTIONAL_INT64: fs._setFieldUnchecked(meta, fi, input.readInt64()); break; - case PbFieldTypeInternal._OPTIONAL_SINT32: + case PbFieldType._OPTIONAL_SINT32: fs._setFieldUnchecked(meta, fi, input.readSint32()); break; - case PbFieldTypeInternal._OPTIONAL_SINT64: + case PbFieldType._OPTIONAL_SINT64: fs._setFieldUnchecked(meta, fi, input.readSint64()); break; - case PbFieldTypeInternal._OPTIONAL_UINT32: + case PbFieldType._OPTIONAL_UINT32: fs._setFieldUnchecked(meta, fi, input.readUint32()); break; - case PbFieldTypeInternal._OPTIONAL_UINT64: + case PbFieldType._OPTIONAL_UINT64: fs._setFieldUnchecked(meta, fi, input.readUint64()); break; - case PbFieldTypeInternal._OPTIONAL_FIXED32: + case PbFieldType._OPTIONAL_FIXED32: fs._setFieldUnchecked(meta, fi, input.readFixed32()); break; - case PbFieldTypeInternal._OPTIONAL_FIXED64: + case PbFieldType._OPTIONAL_FIXED64: fs._setFieldUnchecked(meta, fi, input.readFixed64()); break; - case PbFieldTypeInternal._OPTIONAL_SFIXED32: + case PbFieldType._OPTIONAL_SFIXED32: fs._setFieldUnchecked(meta, fi, input.readSfixed32()); break; - case PbFieldTypeInternal._OPTIONAL_SFIXED64: + case PbFieldType._OPTIONAL_SFIXED64: fs._setFieldUnchecked(meta, fi, input.readSfixed64()); break; - case PbFieldTypeInternal._OPTIONAL_MESSAGE: + case PbFieldType._OPTIONAL_MESSAGE: final GeneratedMessage? oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { input.readMessage(oldValue, registry); @@ -131,7 +130,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, subMessage); } break; - case PbFieldTypeInternal._REPEATED_BOOL: + case PbFieldType._REPEATED_BOOL: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -151,17 +150,17 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readBool()); } break; - case PbFieldTypeInternal._REPEATED_BYTES: + case PbFieldType._REPEATED_BYTES: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readBytes()); break; - case PbFieldTypeInternal._REPEATED_STRING: + case PbFieldType._REPEATED_STRING: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readString()); break; - case PbFieldTypeInternal._REPEATED_FLOAT: + case PbFieldType._REPEATED_FLOAT: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -178,7 +177,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFloat()); } break; - case PbFieldTypeInternal._REPEATED_DOUBLE: + case PbFieldType._REPEATED_DOUBLE: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -195,7 +194,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readDouble()); } break; - case PbFieldTypeInternal._REPEATED_ENUM: + case PbFieldType._REPEATED_ENUM: final list = fs._ensureRepeatedField(meta, fi); _readPackableToListEnum( list, @@ -207,13 +206,13 @@ void _mergeFromCodedBufferReader( registry, ); break; - case PbFieldTypeInternal._REPEATED_GROUP: + case PbFieldType._REPEATED_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readGroup(tagNumber, subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal._REPEATED_INT32: + case PbFieldType._REPEATED_INT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -230,7 +229,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt32()); } break; - case PbFieldTypeInternal._REPEATED_INT64: + case PbFieldType._REPEATED_INT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -247,7 +246,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt64()); } break; - case PbFieldTypeInternal._REPEATED_SINT32: + case PbFieldType._REPEATED_SINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -264,7 +263,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint32()); } break; - case PbFieldTypeInternal._REPEATED_SINT64: + case PbFieldType._REPEATED_SINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -281,7 +280,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint64()); } break; - case PbFieldTypeInternal._REPEATED_UINT32: + case PbFieldType._REPEATED_UINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -298,7 +297,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint32()); } break; - case PbFieldTypeInternal._REPEATED_UINT64: + case PbFieldType._REPEATED_UINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -315,7 +314,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint64()); } break; - case PbFieldTypeInternal._REPEATED_FIXED32: + case PbFieldType._REPEATED_FIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -332,7 +331,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed32()); } break; - case PbFieldTypeInternal._REPEATED_FIXED64: + case PbFieldType._REPEATED_FIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -349,7 +348,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed64()); } break; - case PbFieldTypeInternal._REPEATED_SFIXED32: + case PbFieldType._REPEATED_SFIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -366,7 +365,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed32()); } break; - case PbFieldTypeInternal._REPEATED_SFIXED64: + case PbFieldType._REPEATED_SFIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -383,13 +382,13 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed64()); } break; - case PbFieldTypeInternal._REPEATED_MESSAGE: + case PbFieldType._REPEATED_MESSAGE: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readMessage(subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal._MAP: + case PbFieldType._MAP: final mapFieldInfo = fi as MapFieldInfo; final mapEntryMeta = mapFieldInfo.mapEntryBuilderInfo; fs diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index 6bce23985..312e8fdd2 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -65,9 +65,9 @@ class CodedBufferWriter { } void writeField(int fieldNumber, int fieldType, Object? fieldValue) { - final valueType = PbFieldTypeInternal._baseType(fieldType); + final valueType = PbFieldType._baseType(fieldType); - if ((fieldType & PbFieldTypeInternal._PACKED_BIT) != 0) { + if ((fieldType & PbFieldType._PACKED_BIT) != 0) { final list = fieldValue as List; if (list.isNotEmpty) { _writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); @@ -80,7 +80,7 @@ class CodedBufferWriter { return; } - if ((fieldType & PbFieldTypeInternal._MAP_BIT) != 0) { + if ((fieldType & PbFieldType._MAP_BIT) != 0) { final map = fieldValue as PbMap; final keyWireFormat = _wireTypes[_valueTypeIndex(map.keyFieldType)]; final valueWireFormat = _wireTypes[_valueTypeIndex(map.valueFieldType)]; @@ -107,7 +107,7 @@ class CodedBufferWriter { final wireFormat = _wireTypes[_valueTypeIndex(valueType)]; - if ((fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0) { + if ((fieldType & PbFieldType._REPEATED_BIT) != 0) { final list = fieldValue as List; for (var i = 0; i < list.length; i++) { _writeValue(fieldNumber, valueType, list[i], wireFormat); @@ -353,10 +353,10 @@ class CodedBufferWriter { void _writeValueAs(int valueType, dynamic value) { switch (valueType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldType._BOOL_BIT: _writeVarint32(value ? 1 : 0); break; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: final List bytes = value; if (bytes is Uint8List) { _writeBytesNoTag(bytes); @@ -366,7 +366,7 @@ class CodedBufferWriter { _writeBytesNoTag(Uint8List.fromList(bytes)); } break; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: final String string = value; if (string.isEmpty) { _writeEmptyBytes(); @@ -374,17 +374,17 @@ class CodedBufferWriter { _writeBytesNoTag(const Utf8Encoder().convert(string)); } break; - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._DOUBLE_BIT: _writeDouble(value); break; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldType._FLOAT_BIT: _writeFloat(value); break; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldType._ENUM_BIT: final ProtobufEnum enum_ = value; _writeVarint32(enum_.value & 0xffffffff); break; - case PbFieldTypeInternal._GROUP_BIT: + case PbFieldType._GROUP_BIT: // `value` is `UnknownFieldSet` or `GeneratedMessage`. Test for // `UnknownFieldSet` as it doesn't have subtypes, so the type test will // be fast. @@ -399,37 +399,37 @@ class CodedBufferWriter { message.writeToCodedBufferWriter(this); } break; - case PbFieldTypeInternal._INT32_BIT: + case PbFieldType._INT32_BIT: _writeVarint64(Int64(value)); break; - case PbFieldTypeInternal._INT64_BIT: + case PbFieldType._INT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal._SINT32_BIT: + case PbFieldType._SINT32_BIT: _writeVarint32(_encodeZigZag32(value)); break; - case PbFieldTypeInternal._SINT64_BIT: + case PbFieldType._SINT64_BIT: _writeVarint64(_encodeZigZag64(value)); break; - case PbFieldTypeInternal._UINT32_BIT: + case PbFieldType._UINT32_BIT: _writeVarint32(value); break; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldType._UINT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldType._FIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._FIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._SFIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._SFIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._MESSAGE_BIT: final mark = _startLengthDelimited(); final GeneratedMessage msg = value; msg.writeToCodedBufferWriter(this); @@ -459,7 +459,7 @@ class CodedBufferWriter { ) { _writeTag(fieldNumber, wireFormat); _writeValueAs(valueType, value); - if (valueType == PbFieldTypeInternal._GROUP_BIT) { + if (valueType == PbFieldType._GROUP_BIT) { _writeTag(fieldNumber, WIRETYPE_END_GROUP); } } diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index 3a2494055..c3dda1232 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -10,53 +10,53 @@ part of 'internal.dart'; /// For enums, group, and message fields, this check is only approximate, /// because the exact type isn't included in [fieldType]. String? _getFieldError(int fieldType, var value) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldType._baseType(fieldType)) { + case PbFieldType._BOOL_BIT: if (value is! bool) return 'not type bool'; return null; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: if (value is! List) return 'not List'; return null; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: if (value is! String) return 'not type String'; return null; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldType._FLOAT_BIT: if (value is! double) return 'not type double'; if (!_isFloat32(value)) return 'out of range for float'; return null; - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._DOUBLE_BIT: if (value is! double) return 'not type double'; return null; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldType._ENUM_BIT: if (value is! ProtobufEnum) return 'not type ProtobufEnum'; return null; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._SFIXED32_BIT: if (value is! int) return 'not type int'; if (!_isSigned32(value)) return 'out of range for signed 32-bit int'; return null; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: if (value is! int) return 'not type int'; if (!_isUnsigned32(value)) return 'out of range for unsigned 32-bit int'; return null; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._UINT64_BIT: + case PbFieldType._FIXED64_BIT: + case PbFieldType._SFIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 if (value is! Int64) return 'not Int64'; return null; - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._GROUP_BIT: + case PbFieldType._MESSAGE_BIT: if (value is! GeneratedMessage) return 'not a GeneratedMessage'; return null; default: @@ -74,33 +74,33 @@ String? _getFieldError(int fieldType, var value) { /// @nodoc CheckFunc getCheckFunction(int fieldType) { switch (fieldType & ~0x7) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._BYTES_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: - case PbFieldTypeInternal._ENUM_BIT: - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._BOOL_BIT: + case PbFieldType._BYTES_BIT: + case PbFieldType._STRING_BIT: + case PbFieldType._DOUBLE_BIT: + case PbFieldType._ENUM_BIT: + case PbFieldType._GROUP_BIT: + case PbFieldType._MESSAGE_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._SFIXED64_BIT: + case PbFieldType._UINT64_BIT: + case PbFieldType._FIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 return _checkNotNull; - case PbFieldTypeInternal._FLOAT_BIT: + case PbFieldType._FLOAT_BIT: return _checkFloat; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._SFIXED32_BIT: return _checkSigned32; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: return _checkUnsigned32; } throw ArgumentError('check function not implemented: $fieldType'); diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 587c499b8..87d76c27d 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -65,7 +65,7 @@ class FieldInfo { /// The value is `null` for extension fields. final int? index; - /// Type of this field. See [PbFieldTypeInternal]. + /// Type of this field. See [PbFieldType]. final int type; /// Constructs the default value of a field. @@ -148,7 +148,7 @@ class FieldInfo { assert(!_isEnum(type) || valueOf != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { - if (defaultOrMaker == null) return PbFieldTypeInternal.defaultForType(type); + if (defaultOrMaker == null) return PbFieldType.defaultForType(type); if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; return () => defaultOrMaker; } diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index 80ed423bd..ad3ac2405 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -5,28 +5,23 @@ // ignore_for_file: constant_identifier_names,non_constant_identifier_names part of 'internal.dart'; -bool _isRepeated(int fieldType) => - (fieldType & PbFieldTypeInternal._REPEATED_BIT) != 0; +bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; -bool _isRequired(int fieldType) => - (fieldType & PbFieldTypeInternal._REQUIRED_BIT) != 0; +bool _isRequired(int fieldType) => (fieldType & PbFieldType._REQUIRED_BIT) != 0; bool _isEnum(int fieldType) => - PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._ENUM_BIT; + PbFieldType._baseType(fieldType) == PbFieldType._ENUM_BIT; bool _isBytes(int fieldType) => - PbFieldTypeInternal._baseType(fieldType) == PbFieldTypeInternal._BYTES_BIT; + PbFieldType._baseType(fieldType) == PbFieldType._BYTES_BIT; bool _isGroupOrMessage(int fieldType) => - (fieldType & - (PbFieldTypeInternal._GROUP_BIT | PbFieldTypeInternal._MESSAGE_BIT)) != - 0; + (fieldType & (PbFieldType._GROUP_BIT | PbFieldType._MESSAGE_BIT)) != 0; -bool _isMapField(int fieldType) => - (fieldType & PbFieldTypeInternal._MAP_BIT) != 0; +bool _isMapField(int fieldType) => (fieldType & PbFieldType._MAP_BIT) != 0; /// Defines constants and functions for dealing with fieldType bits. -class PbFieldTypeInternal { +class PbFieldType { /// Returns the base field type without any of the required, repeated /// and packed bits. static int _baseType(int fieldType) => diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index 361f1d0e9..f21756754 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -6,7 +6,7 @@ part of 'internal.dart'; Map _writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { - final baseType = PbFieldTypeInternal._baseType(fieldType); + final baseType = PbFieldType._baseType(fieldType); if (_isRepeated(fieldType)) { final PbList list = fieldValue; @@ -14,16 +14,16 @@ Map _writeToJsonMap(FieldSet fs) { } switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._BOOL_BIT: + case PbFieldType._STRING_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: + case PbFieldType._SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._FLOAT_BIT: + case PbFieldType._DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { return nan; @@ -35,22 +35,22 @@ Map _writeToJsonMap(FieldSet fs) { return fieldValue.toInt(); } return value; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: // Encode 'bytes' as a base64-encoded string. return base64Encode(fieldValue as List); - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldType._ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value; // assume |value| < 2^52 - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._SFIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._UINT64_BIT: + case PbFieldType._FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned(); - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._GROUP_BIT: + case PbFieldType._MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: @@ -246,8 +246,8 @@ dynamic _convertJsonValue( ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldType._baseType(fieldType)) { + case PbFieldType._BOOL_BIT: if (value is bool) { return value; } else if (value is String) { @@ -265,20 +265,20 @@ dynamic _convertJsonValue( } expectedType = 'bool (true, false, "true", "false", 1, 0)'; break; - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: if (value is String) { return base64Decode(value); } expectedType = 'Base64 String'; break; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: if (value is String) { return value; } expectedType = 'String'; break; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._FLOAT_BIT: + case PbFieldType._DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value is double) { return value; @@ -289,7 +289,7 @@ dynamic _convertJsonValue( } expectedType = 'num or stringified num'; break; - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldType._ENUM_BIT: // Allow quoted values, although we don't emit them. if (value is String) { value = int.parse(value); @@ -302,15 +302,15 @@ dynamic _convertJsonValue( } expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._SFIXED32_BIT: if (value is int) return value; if (value is String) return int.parse(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: int? validatedValue; if (value is int) validatedValue = value; if (value is String) validatedValue = int.parse(value); @@ -320,17 +320,17 @@ dynamic _convertJsonValue( if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._UINT64_BIT: + case PbFieldType._FIXED64_BIT: + case PbFieldType._SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) return Int64.parseInt(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._GROUP_BIT: + case PbFieldType._MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; final subMessage = meta._makeEmptyMessage(tagNumber, registry); diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index b6b1f0383..c1dbe11a8 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -6,26 +6,26 @@ part of 'internal.dart'; Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { - final baseType = PbFieldTypeInternal._baseType(keyType); + final baseType = PbFieldType._baseType(keyType); assert(!_isRepeated(keyType)); switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldType._BOOL_BIT: return key ? 'true' : 'false'; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: return key; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldType._UINT64_BIT: return (key as Int64).toStringUnsigned(); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: + case PbFieldType._SFIXED32_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._SFIXED64_BIT: + case PbFieldType._FIXED64_BIT: return key.toString(); default: throw StateError('Not a valid key type $keyType'); @@ -43,25 +43,25 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { } else if (_isEnum(fieldType)) { return (fieldValue as ProtobufEnum).name; } else { - final baseType = PbFieldTypeInternal._baseType(fieldType); + final baseType = PbFieldType._baseType(fieldType); switch (baseType) { - case PbFieldTypeInternal._BOOL_BIT: + case PbFieldType._BOOL_BIT: return fieldValue as bool; - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: return fieldValue; - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: + case PbFieldType._SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._SFIXED64_BIT: + case PbFieldType._FIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._FLOAT_BIT: + case PbFieldType._DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return nan; @@ -73,9 +73,9 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { return value.toInt(); } return value; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldType._UINT64_BIT: return (fieldValue as Int64).toStringUnsigned(); - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: return base64Encode(fieldValue); default: throw StateError( @@ -176,13 +176,13 @@ void _mergeFromProto3Json( void recursionHelper(Object? json, FieldSet fieldSet) { Object? convertProto3JsonValue(Object value, FieldInfo fieldInfo) { final fieldType = fieldInfo.type; - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldType._baseType(fieldType)) { + case PbFieldType._BOOL_BIT: if (value is bool) { return value; } throw context.parseException('Expected bool value', json); - case PbFieldTypeInternal._BYTES_BIT: + case PbFieldType._BYTES_BIT: if (value is String) { Uint8List result; try { @@ -199,13 +199,13 @@ void _mergeFromProto3Json( 'Expected bytes encoded as base64 String', value, ); - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: if (value is String) { return value; } throw context.parseException('Expected String value', value); - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._DOUBLE_BIT: + case PbFieldType._FLOAT_BIT: + case PbFieldType._DOUBLE_BIT: if (value is double) { return value; } else if (value is num) { @@ -221,7 +221,7 @@ void _mergeFromProto3Json( 'Expected a double represented as a String or number', value, ); - case PbFieldTypeInternal._ENUM_BIT: + case PbFieldType._ENUM_BIT: if (value is String) { // TODO(sigurdm): Do we want to avoid linear search here? Measure... final result = @@ -245,8 +245,8 @@ void _mergeFromProto3Json( 'Expected enum as a string or integer', value, ); - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._FIXED32_BIT: int result; if (value is int) { result = value; @@ -259,9 +259,9 @@ void _mergeFromProto3Json( ); } return _check32BitUnsignedProto3(result, context); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._SFIXED32_BIT: int result; if (value is int) { result = value; @@ -275,7 +275,7 @@ void _mergeFromProto3Json( } _check32BitSignedProto3(result, context); return result; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldType._UINT64_BIT: Int64 result; if (value is int) { result = Int64(value); @@ -288,10 +288,10 @@ void _mergeFromProto3Json( ); } return result; - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._FIXED64_BIT: + case PbFieldType._SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) { Int64 result; @@ -309,8 +309,8 @@ void _mergeFromProto3Json( 'Expected int or stringified int', value, ); - case PbFieldTypeInternal._GROUP_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._GROUP_BIT: + case PbFieldType._MESSAGE_BIT: final subMessage = fieldInfo.subBuilder!(); recursionHelper(value, subMessage._fieldSet); return subMessage; @@ -320,8 +320,8 @@ void _mergeFromProto3Json( } Object decodeMapKey(String key, int fieldType) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: + switch (PbFieldType._baseType(fieldType)) { + case PbFieldType._BOOL_BIT: switch (key) { case 'true': return true; @@ -333,26 +333,26 @@ void _mergeFromProto3Json( key, ); } - case PbFieldTypeInternal._STRING_BIT: + case PbFieldType._STRING_BIT: return key; - case PbFieldTypeInternal._UINT64_BIT: + case PbFieldType._UINT64_BIT: // TODO(sigurdm): We do not throw on negative values here. // That would probably require going via bignum. return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: - case PbFieldTypeInternal._FIXED64_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._SFIXED64_BIT: + case PbFieldType._FIXED64_BIT: return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._FIXED32_BIT: + case PbFieldType._SFIXED32_BIT: return _check32BitSignedProto3( _tryParse32BitProto3(key, context), context, ); - case PbFieldTypeInternal._UINT32_BIT: + case PbFieldType._UINT32_BIT: return _check32BitUnsignedProto3( _tryParse32BitProto3(key, context), context, diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 906ca5a71..62cee24b1 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -283,11 +283,11 @@ class UnknownFieldSetField { output.writeField(fieldNumber, type, value); } - write(PbFieldTypeInternal._REPEATED_UINT64, varints); - write(PbFieldTypeInternal._REPEATED_FIXED32, fixed32s); - write(PbFieldTypeInternal._REPEATED_FIXED64, fixed64s); - write(PbFieldTypeInternal._REPEATED_BYTES, lengthDelimited); - write(PbFieldTypeInternal._REPEATED_GROUP, groups); + write(PbFieldType._REPEATED_UINT64, varints); + write(PbFieldType._REPEATED_FIXED32, fixed32s); + write(PbFieldType._REPEATED_FIXED64, fixed64s); + write(PbFieldType._REPEATED_BYTES, lengthDelimited); + write(PbFieldType._REPEATED_GROUP, groups); } void addGroup(UnknownFieldSet value) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index 6a2536270..1dabb6385 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -38,32 +38,32 @@ int makeTag(int fieldNumber, int tag) => (fieldNumber << _TAG_TYPE_BITS) | tag; /// Returns true if the wireType can be merged into the given fieldType. bool _wireTypeMatches(int fieldType, int wireType) { - switch (PbFieldTypeInternal._baseType(fieldType)) { - case PbFieldTypeInternal._BOOL_BIT: - case PbFieldTypeInternal._ENUM_BIT: - case PbFieldTypeInternal._INT32_BIT: - case PbFieldTypeInternal._INT64_BIT: - case PbFieldTypeInternal._SINT32_BIT: - case PbFieldTypeInternal._SINT64_BIT: - case PbFieldTypeInternal._UINT32_BIT: - case PbFieldTypeInternal._UINT64_BIT: + switch (PbFieldType._baseType(fieldType)) { + case PbFieldType._BOOL_BIT: + case PbFieldType._ENUM_BIT: + case PbFieldType._INT32_BIT: + case PbFieldType._INT64_BIT: + case PbFieldType._SINT32_BIT: + case PbFieldType._SINT64_BIT: + case PbFieldType._UINT32_BIT: + case PbFieldType._UINT64_BIT: return wireType == WIRETYPE_VARINT || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._FLOAT_BIT: - case PbFieldTypeInternal._FIXED32_BIT: - case PbFieldTypeInternal._SFIXED32_BIT: + case PbFieldType._FLOAT_BIT: + case PbFieldType._FIXED32_BIT: + case PbFieldType._SFIXED32_BIT: return wireType == WIRETYPE_FIXED32 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._DOUBLE_BIT: - case PbFieldTypeInternal._FIXED64_BIT: - case PbFieldTypeInternal._SFIXED64_BIT: + case PbFieldType._DOUBLE_BIT: + case PbFieldType._FIXED64_BIT: + case PbFieldType._SFIXED64_BIT: return wireType == WIRETYPE_FIXED64 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._BYTES_BIT: - case PbFieldTypeInternal._STRING_BIT: - case PbFieldTypeInternal._MESSAGE_BIT: + case PbFieldType._BYTES_BIT: + case PbFieldType._STRING_BIT: + case PbFieldType._MESSAGE_BIT: return wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal._GROUP_BIT: + case PbFieldType._GROUP_BIT: return wireType == WIRETYPE_START_GROUP; default: return false; diff --git a/protobuf/test/codec_test.dart b/protobuf/test/codec_test.dart index 650259c1e..215e90d7f 100644 --- a/protobuf/test/codec_test.dart +++ b/protobuf/test/codec_test.dart @@ -29,7 +29,7 @@ void main() { }; } - final int32ToBytes = convertToBytes(PbFieldTypeInternal.O3); + final int32ToBytes = convertToBytes(PbFieldType.O3); test('testInt32RoundTrips', () { final roundtrip = roundtripTester( @@ -60,7 +60,7 @@ void main() { test('testSint32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint32(), - toBytes: convertToBytes(PbFieldTypeInternal.OS3), + toBytes: convertToBytes(PbFieldType.OS3), ); roundtrip(0, [0x00]); @@ -72,7 +72,7 @@ void main() { test('testSint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OS6), + toBytes: convertToBytes(PbFieldType.OS6), ); roundtrip(make64(0), [0x00]); @@ -84,7 +84,7 @@ void main() { test('testFixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OF3), + toBytes: convertToBytes(PbFieldType.OF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -96,7 +96,7 @@ void main() { test('testFixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OF6), + toBytes: convertToBytes(PbFieldType.OF6), ); roundtrip(make64(0, 0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -126,7 +126,7 @@ void main() { test('testSfixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF3), + toBytes: convertToBytes(PbFieldType.OSF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -138,7 +138,7 @@ void main() { test('testSfixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF6), + toBytes: convertToBytes(PbFieldType.OSF6), ); roundtrip(make64(0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -183,7 +183,7 @@ void main() { : equals(expected); List dataToBytes(ByteData byteData) => Uint8List.view(byteData.buffer); - final floatToBytes = convertToBytes(PbFieldTypeInternal.OF); + final floatToBytes = convertToBytes(PbFieldType.OF); int floatToBits(double value) => makeData(floatToBytes(value)).getUint32(0, Endian.little); @@ -197,7 +197,7 @@ void main() { expect(readFloat(bits), doubleEquals(value)); } - final doubleToBytes = convertToBytes(PbFieldTypeInternal.OD); + final doubleToBytes = convertToBytes(PbFieldType.OD); void test64(List hilo, double value) { // Encode a double to its wire format. @@ -732,7 +732,7 @@ void main() { test('testVarint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readUint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OU6), + toBytes: convertToBytes(PbFieldType.OU6), ); roundtrip(make64(0), [0x00]); @@ -794,8 +794,7 @@ void main() { }); test('testWriteTo', () { - final writer = - CodedBufferWriter()..writeField(0, PbFieldTypeInternal.O3, 1337); + final writer = CodedBufferWriter()..writeField(0, PbFieldType.O3, 1337); expect(writer.lengthInBytes, 3); final buffer = Uint8List(5); buffer[0] = 0x55; diff --git a/protobuf/test/list_test.dart b/protobuf/test/list_test.dart index 319b730d9..23e995100 100644 --- a/protobuf/test/list_test.dart +++ b/protobuf/test/list_test.dart @@ -98,9 +98,7 @@ void main() { }); test('PbList for signed int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.P3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.P3)); expect(() { list.add(-2147483649); @@ -128,9 +126,7 @@ void main() { }); test('PBList for unsigned int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PU3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PU3)); expect(() { list.add(-1); @@ -158,9 +154,7 @@ void main() { }); test('PbList for float validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PF), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PF)); expect(() { list.add(3.4028234663852886E39); diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index 8b5edd66d..fdd385ea3 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -9,28 +9,22 @@ import 'package:protobuf/protobuf.dart' BuilderInfo, CreateBuilderFunc, GeneratedMessage, - PbFieldTypeInternal, + PbFieldType, ProtobufEnum; final mockEnumValues = [ProtobufEnum(1, 'a'), ProtobufEnum(2, 'b')]; BuilderInfo mockInfo(String className, CreateBuilderFunc create) { return BuilderInfo(className, createEmptyInstance: create) - ..a(1, 'val', PbFieldTypeInternal.O3, defaultOrMaker: 42) - ..a(2, 'str', PbFieldTypeInternal.OS) - ..a( - 3, - 'child', - PbFieldTypeInternal.OM, - defaultOrMaker: create, - subBuilder: create, - ) - ..p(4, 'int32s', PbFieldTypeInternal.P3) - ..a(5, 'int64', PbFieldTypeInternal.O6) + ..a(1, 'val', PbFieldType.O3, defaultOrMaker: 42) + ..a(2, 'str', PbFieldType.OS) + ..a(3, 'child', PbFieldType.OM, defaultOrMaker: create, subBuilder: create) + ..p(4, 'int32s', PbFieldType.P3) + ..a(5, 'int64', PbFieldType.O6) // 6 is reserved for extensions in other tests. ..e( 7, 'enm', - PbFieldTypeInternal.OE, + PbFieldType.OE, defaultOrMaker: mockEnumValues.first, valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), enumValues: mockEnumValues, diff --git a/protobuf/test/readonly_message_test.dart b/protobuf/test/readonly_message_test.dart index dba11f208..cf5b37d59 100644 --- a/protobuf/test/readonly_message_test.dart +++ b/protobuf/test/readonly_message_test.dart @@ -3,11 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:protobuf/protobuf.dart' - show - BuilderInfo, - GeneratedMessage, - PbFieldTypeInternal, - UnknownFieldSetField; + show BuilderInfo, GeneratedMessage, PbFieldType, UnknownFieldSetField; import 'package:test/test.dart'; Matcher throwsUnsupportedError(Matcher expectedMessage) => throwsA( @@ -27,9 +23,9 @@ class Rec extends GeneratedMessage { @override BuilderInfo info_ = BuilderInfo('rec') - ..a(1, 'value', PbFieldTypeInternal.O3) - ..pc(2, 'sub', PbFieldTypeInternal.PM, subBuilder: Rec.create) - ..p(10, 'ints', PbFieldTypeInternal.P3); + ..a(1, 'value', PbFieldType.O3) + ..pc(2, 'sub', PbFieldType.PM, subBuilder: Rec.create) + ..p(10, 'ints', PbFieldType.P3); int get value => $_get(0, 0); set value(int v) { diff --git a/protoc_plugin/lib/src/base_type.dart b/protoc_plugin/lib/src/base_type.dart index 6a96832c6..0f5d08c60 100644 --- a/protoc_plugin/lib/src/base_type.dart +++ b/protoc_plugin/lib/src/base_type.dart @@ -12,7 +12,7 @@ class BaseType { /// The name of the Dart type when in the same package. final String unprefixed; - /// The suffix of the constant for this type in PbFieldTypeInternal. + /// The suffix of the constant for this type in PbFieldType. /// (For example, 'B' for boolean or '3' for int32.) final String typeConstantSuffix; diff --git a/protoc_plugin/lib/src/gen/dart_options.pb.dart b/protoc_plugin/lib/src/gen/dart_options.pb.dart index 8b53eb43f..b582465bf 100644 --- a/protoc_plugin/lib/src/gen/dart_options.pb.dart +++ b/protoc_plugin/lib/src/gen/dart_options.pb.dart @@ -126,7 +126,7 @@ class Imports extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'dart_options'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, subBuilder: DartMixin.create) ..hasRequiredFields = false; @@ -166,44 +166,44 @@ class Dart_options { _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'imports', 28125061, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: Imports.getDefault, subBuilder: Imports.create); static final defaultMixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'defaultMixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final mixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.MessageOptions', _omitFieldNames ? '' : 'mixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final overrideGetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideGetter', 28205290, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideSetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideSetter', 28937366, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideHasMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideHasMethod', 28937461, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideClearMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideClearMethod', 28907907, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final dartName = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'dartName', 28700919, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(imports); registry.add(defaultMixin); diff --git a/protoc_plugin/lib/src/gen/google/api/client.pb.dart b/protoc_plugin/lib/src/gen/google/api/client.pb.dart index 16590b7f6..79b1a177a 100644 --- a/protoc_plugin/lib/src/gen/google/api/client.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/client.pb.dart @@ -53,7 +53,7 @@ class CommonLanguageSettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'referenceDocsUri') ..pc( - 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldTypeInternal.KE, + 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldType.KE, valueOf: ClientLibraryDestination.valueOf, enumValues: ClientLibraryDestination.values, defaultEnumValue: @@ -164,7 +164,7 @@ class ClientLibrarySettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'version') ..e<$1.LaunchStage>( - 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldType.OE, defaultOrMaker: $1.LaunchStage.LAUNCH_STAGE_UNSPECIFIED, valueOf: $1.LaunchStage.valueOf, enumValues: $1.LaunchStage.values) @@ -389,7 +389,7 @@ class Publishing extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldType.PM, subBuilder: MethodSettings.create) ..aOS(101, _omitFieldNames ? '' : 'newIssueUri') ..aOS(102, _omitFieldNames ? '' : 'documentationUri') @@ -398,13 +398,13 @@ class Publishing extends $pb.GeneratedMessage { ..pPS(105, _omitFieldNames ? '' : 'codeownerGithubTeams') ..aOS(106, _omitFieldNames ? '' : 'docTagPrefix') ..e( - 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldTypeInternal.OE, + 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldType.OE, defaultOrMaker: ClientLibraryOrganization.CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED, valueOf: ClientLibraryOrganization.valueOf, enumValues: ClientLibraryOrganization.values) ..pc(109, _omitFieldNames ? '' : 'librarySettings', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: ClientLibrarySettings.create) ..aOS(110, _omitFieldNames ? '' : 'protoReferenceDocumentationUri') ..aOS(111, _omitFieldNames ? '' : 'restReferenceDocumentationUri') @@ -568,8 +568,8 @@ class JavaSettings extends $pb.GeneratedMessage { ..m<$core.String, $core.String>( 2, _omitFieldNames ? '' : 'serviceClassNames', entryClassName: 'JavaSettings.ServiceClassNamesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..aOM(3, _omitFieldNames ? '' : 'common', subBuilder: CommonLanguageSettings.create) @@ -1055,14 +1055,14 @@ class DotnetSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'DotnetSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..m<$core.String, $core.String>( 3, _omitFieldNames ? '' : 'renamedResources', entryClassName: 'DotnetSettings.RenamedResourcesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..pPS(4, _omitFieldNames ? '' : 'ignoredResources') ..pPS(5, _omitFieldNames ? '' : 'forcedNamespaceAliases') @@ -1229,8 +1229,8 @@ class GoSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'GoSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..hasRequiredFields = false; @@ -1314,7 +1314,7 @@ class MethodSettings_LongRunning extends $pb.GeneratedMessage { ..aOM<$0.Duration>(1, _omitFieldNames ? '' : 'initialPollDelay', subBuilder: $0.Duration.create) ..a<$core.double>(2, _omitFieldNames ? '' : 'pollDelayMultiplier', - $pb.PbFieldTypeInternal.OF) + $pb.PbFieldType.OF) ..aOM<$0.Duration>(3, _omitFieldNames ? '' : 'maxPollDelay', subBuilder: $0.Duration.create) ..aOM<$0.Duration>(4, _omitFieldNames ? '' : 'totalPollTimeout', @@ -1590,23 +1590,23 @@ class Client { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'methodSignature', 1051, - $pb.PbFieldTypeInternal.PS, - check: $pb.getCheckFunction($pb.PbFieldTypeInternal.PS)); + $pb.PbFieldType.PS, + check: $pb.getCheckFunction($pb.PbFieldType.PS)); static final defaultHost = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'defaultHost', 1049, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final oauthScopes = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'oauthScopes', 1050, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final apiVersion = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'apiVersion', 525000001, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(methodSignature); registry.add(defaultHost); diff --git a/protoc_plugin/lib/src/gen/google/api/http.pb.dart b/protoc_plugin/lib/src/gen/google/api/http.pb.dart index 3aba71831..bf3b4b687 100644 --- a/protoc_plugin/lib/src/gen/google/api/http.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/http.pb.dart @@ -45,7 +45,7 @@ class Http extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOB(2, _omitFieldNames ? '' : 'fullyDecodeReservedExpansion') ..hasRequiredFields = false; @@ -418,7 +418,7 @@ class HttpRule extends $pb.GeneratedMessage { ..aOM(8, _omitFieldNames ? '' : 'custom', subBuilder: CustomHttpPattern.create) ..pc(11, _omitFieldNames ? '' : 'additionalBindings', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOS(12, _omitFieldNames ? '' : 'responseBody') ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart index 04374313b..64ac278ad 100644 --- a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart @@ -399,7 +399,7 @@ class RoutingRule extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc(2, _omitFieldNames ? '' : 'routingParameters', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: RoutingParameter.create) ..hasRequiredFields = false; @@ -562,7 +562,7 @@ class Routing { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'routing', 72295729, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: RoutingRule.getDefault, subBuilder: RoutingRule.create); static void registerAllExtensions($pb.ExtensionRegistry registry) { diff --git a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart index 0c40bcc51..ec22fe316 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart @@ -52,11 +52,11 @@ class Version extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) ..a<$core.int>( - 1, _omitFieldNames ? '' : 'major', $pb.PbFieldTypeInternal.O3) + 1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) ..a<$core.int>( - 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldTypeInternal.O3) + 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) ..a<$core.int>( - 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) ..aOS(4, _omitFieldNames ? '' : 'suffix') ..hasRequiredFields = false; @@ -156,12 +156,12 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { ..aOM(3, _omitFieldNames ? '' : 'compilerVersion', subBuilder: Version.create) ..pc<$0.FileDescriptorProto>( - 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create) ..pc<$0.FileDescriptorProto>( 17, _omitFieldNames ? '' : 'sourceFileDescriptors', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -429,14 +429,14 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'error') ..a<$fixnum.Int64>(2, _omitFieldNames ? '' : 'supportedFeatures', - $pb.PbFieldTypeInternal.OU6, + $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..a<$core.int>( - 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.O3) ..a<$core.int>( - 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.O3) + 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.O3) ..pc( - 15, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: CodeGeneratorResponse_File.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart index 1f945e551..651b2c0cb 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart @@ -47,7 +47,7 @@ class FileDescriptorSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: FileDescriptorProto.create) ..hasExtensions = true; @@ -132,28 +132,28 @@ class FileDescriptorProto extends $pb.GeneratedMessage { ..aOS(2, _omitFieldNames ? '' : 'package') ..pPS(3, _omitFieldNames ? '' : 'dependency') ..pc( - 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 6, _omitFieldNames ? '' : 'service', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'service', $pb.PbFieldType.PM, subBuilder: ServiceDescriptorProto.create) ..pc( - 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FileOptions.create) ..aOM(9, _omitFieldNames ? '' : 'sourceCodeInfo', subBuilder: SourceCodeInfo.create) ..p<$core.int>(10, _omitFieldNames ? '' : 'publicDependency', - $pb.PbFieldTypeInternal.P3) + $pb.PbFieldType.P3) ..p<$core.int>( - 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldTypeInternal.P3) + 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldType.P3) ..aOS(12, _omitFieldNames ? '' : 'syntax') ..e( - 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -313,8 +313,8 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ExtensionRangeOptions.create); @@ -402,8 +402,8 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -496,31 +496,31 @@ class DescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'field', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'field', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..pc( - 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldTypeInternal.PM, + 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ExtensionRange.create) ..pc( - 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(7, _omitFieldNames ? '' : 'options', subBuilder: MessageOptions.create) ..pc( - 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldTypeInternal.PM, + 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldType.PM, subBuilder: OneofDescriptorProto.create) ..pc( - 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ReservedRange.create) ..pPS(10, _omitFieldNames ? '' : 'reservedName') ..e( - 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -636,7 +636,7 @@ class ExtensionRangeOptions_Declaration extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..a<$core.int>( - 1, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + 1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOS(2, _omitFieldNames ? '' : 'fullName') ..aOS(3, _omitFieldNames ? '' : 'type') ..aOB(5, _omitFieldNames ? '' : 'reserved') @@ -757,17 +757,17 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldType.PM, subBuilder: ExtensionRangeOptions_Declaration.create) ..e( - 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldType.OE, defaultOrMaker: ExtensionRangeOptions_VerificationState.UNVERIFIED, valueOf: ExtensionRangeOptions_VerificationState.valueOf, enumValues: ExtensionRangeOptions_VerificationState.values) ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -877,14 +877,14 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOS(1, _omitFieldNames ? '' : 'name') ..aOS(2, _omitFieldNames ? '' : 'extendee') ..a<$core.int>( - 3, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..e( - 4, _omitFieldNames ? '' : 'label', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, valueOf: FieldDescriptorProto_Label.valueOf, enumValues: FieldDescriptorProto_Label.values) ..e( - 5, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Type.TYPE_DOUBLE, valueOf: FieldDescriptorProto_Type.valueOf, enumValues: FieldDescriptorProto_Type.values) @@ -893,7 +893,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FieldOptions.create) ..a<$core.int>( - 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldTypeInternal.O3) + 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) ..aOS(10, _omitFieldNames ? '' : 'jsonName') ..aOB(17, _omitFieldNames ? '' : 'proto3Optional'); @@ -1167,8 +1167,8 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -1252,16 +1252,16 @@ class EnumDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'value', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'value', $pb.PbFieldType.PM, subBuilder: EnumValueDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumOptions.create) ..pc( - 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto_EnumReservedRange.create) ..pPS(5, _omitFieldNames ? '' : 'reservedName') ..e( - 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -1363,7 +1363,7 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..a<$core.int>( - 2, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + 2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumValueOptions.create); @@ -1450,7 +1450,7 @@ class ServiceDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'method', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'method', $pb.PbFieldType.PM, subBuilder: MethodDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ServiceOptions.create); @@ -1701,7 +1701,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(1, _omitFieldNames ? '' : 'javaPackage') ..aOS(8, _omitFieldNames ? '' : 'javaOuterClassname') ..e( - 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldTypeInternal.OE, + 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldType.OE, defaultOrMaker: FileOptions_OptimizeMode.SPEED, valueOf: FileOptions_OptimizeMode.valueOf, enumValues: FileOptions_OptimizeMode.values) @@ -1714,7 +1714,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOB(23, _omitFieldNames ? '' : 'deprecated') ..aOB(27, _omitFieldNames ? '' : 'javaStringCheckUtf8') ..a<$core.bool>( - 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldTypeInternal.OB, + 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldType.OB, defaultOrMaker: true) ..aOS(36, _omitFieldNames ? '' : 'objcClassPrefix') ..aOS(37, _omitFieldNames ? '' : 'csharpNamespace') @@ -1726,7 +1726,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2060,7 +2060,7 @@ class MessageOptions extends $pb.GeneratedMessage { ..aOM(12, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2238,7 +2238,7 @@ class FieldOptions_EditionDefault extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(2, _omitFieldNames ? '' : 'value') ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2320,18 +2320,18 @@ class FieldOptions_FeatureSupport extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e(1, _omitFieldNames ? '' : 'editionIntroduced', - $pb.PbFieldTypeInternal.OE, + $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..e(2, _omitFieldNames ? '' : 'editionDeprecated', - $pb.PbFieldTypeInternal.OE, + $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..aOS(3, _omitFieldNames ? '' : 'deprecationWarning') ..e( - 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2460,7 +2460,7 @@ class FieldOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_CType.STRING, valueOf: FieldOptions_CType.valueOf, enumValues: FieldOptions_CType.values) @@ -2468,7 +2468,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(3, _omitFieldNames ? '' : 'deprecated') ..aOB(5, _omitFieldNames ? '' : 'lazy') ..e( - 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_JSType.JS_NORMAL, valueOf: FieldOptions_JSType.valueOf, enumValues: FieldOptions_JSType.values) @@ -2476,17 +2476,17 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(15, _omitFieldNames ? '' : 'unverifiedLazy') ..aOB(16, _omitFieldNames ? '' : 'debugRedact') ..e( - 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldTypeInternal.OE, + 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_OptionRetention.RETENTION_UNKNOWN, valueOf: FieldOptions_OptionRetention.valueOf, enumValues: FieldOptions_OptionRetention.values) ..pc( - 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldTypeInternal.PE, + 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldType.PE, valueOf: FieldOptions_OptionTargetType.valueOf, enumValues: FieldOptions_OptionTargetType.values, defaultEnumValue: FieldOptions_OptionTargetType.TARGET_TYPE_UNKNOWN) ..pc(20, - _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldTypeInternal.PM, + _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, subBuilder: FieldOptions_EditionDefault.create) ..aOM(21, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) @@ -2494,7 +2494,7 @@ class FieldOptions extends $pb.GeneratedMessage { 22, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2724,7 +2724,7 @@ class OneofOptions extends $pb.GeneratedMessage { ..aOM(1, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2810,7 +2810,7 @@ class EnumOptions extends $pb.GeneratedMessage { ..aOM(7, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2938,7 +2938,7 @@ class EnumValueOptions extends $pb.GeneratedMessage { 4, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3052,7 +3052,7 @@ class ServiceOptions extends $pb.GeneratedMessage { ..aOM(34, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3142,14 +3142,14 @@ class MethodOptions extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOB(33, _omitFieldNames ? '' : 'deprecated') ..e(34, - _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldTypeInternal.OE, + _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, valueOf: MethodOptions_IdempotencyLevel.valueOf, enumValues: MethodOptions_IdempotencyLevel.values) ..aOM(35, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3249,7 +3249,7 @@ class UninterpretedOption_NamePart extends $pb.GeneratedMessage { createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'namePart') ..a<$core.bool>( - 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldTypeInternal.QB); + 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldType.QB); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') UninterpretedOption_NamePart clone() => @@ -3337,17 +3337,17 @@ class UninterpretedOption extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'name', $pb.PbFieldType.PM, subBuilder: UninterpretedOption_NamePart.create) ..aOS(3, _omitFieldNames ? '' : 'identifierValue') ..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'positiveIntValue', - $pb.PbFieldTypeInternal.OU6, + $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aInt64(5, _omitFieldNames ? '' : 'negativeIntValue') ..a<$core.double>( - 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldTypeInternal.OD) + 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldType.OD) ..a<$core.List<$core.int>>( - 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldTypeInternal.OY) + 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldType.OY) ..aOS(8, _omitFieldNames ? '' : 'aggregateValue'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -3524,40 +3524,40 @@ class FeatureSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_FieldPresence.FIELD_PRESENCE_UNKNOWN, valueOf: FeatureSet_FieldPresence.valueOf, enumValues: FeatureSet_FieldPresence.values) ..e( - 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnumType.ENUM_TYPE_UNKNOWN, valueOf: FeatureSet_EnumType.valueOf, enumValues: FeatureSet_EnumType.values) ..e( 3, _omitFieldNames ? '' : 'repeatedFieldEncoding', - $pb.PbFieldTypeInternal.OE, + $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_RepeatedFieldEncoding.REPEATED_FIELD_ENCODING_UNKNOWN, valueOf: FeatureSet_RepeatedFieldEncoding.valueOf, enumValues: FeatureSet_RepeatedFieldEncoding.values) ..e( - 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN, valueOf: FeatureSet_Utf8Validation.valueOf, enumValues: FeatureSet_Utf8Validation.values) ..e( - 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN, valueOf: FeatureSet_MessageEncoding.valueOf, enumValues: FeatureSet_MessageEncoding.values) ..e( - 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN, valueOf: FeatureSet_JsonFormat.valueOf, enumValues: FeatureSet_JsonFormat.values) ..e(7, - _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldTypeInternal.OE, + _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN, valueOf: FeatureSet_EnforceNamingStyle.valueOf, @@ -3565,7 +3565,7 @@ class FeatureSet extends $pb.GeneratedMessage { ..e( 8, _omitFieldNames ? '' : 'defaultSymbolVisibility', - $pb.PbFieldTypeInternal.OE, + $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_VisibilityFeature_DefaultSymbolVisibility .DEFAULT_SYMBOL_VISIBILITY_UNKNOWN, valueOf: FeatureSet_VisibilityFeature_DefaultSymbolVisibility.valueOf, @@ -3704,7 +3704,7 @@ class FeatureSetDefaults_FeatureSetEditionDefault extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -3806,15 +3806,15 @@ class FeatureSetDefaults extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldType.PM, subBuilder: FeatureSetDefaults_FeatureSetEditionDefault.create) ..e( - 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..e( - 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values); @@ -3899,8 +3899,8 @@ class SourceCodeInfo_Location extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) - ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) + ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldType.K3) ..aOS(3, _omitFieldNames ? '' : 'leadingComments') ..aOS(4, _omitFieldNames ? '' : 'trailingComments') ..pPS(6, _omitFieldNames ? '' : 'leadingDetachedComments') @@ -4058,7 +4058,7 @@ class SourceCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'location', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'location', $pb.PbFieldType.PM, subBuilder: SourceCodeInfo_Location.create) ..hasExtensions = true; @@ -4161,13 +4161,13 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) ..aOS(2, _omitFieldNames ? '' : 'sourceFile') ..a<$core.int>( - 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) + ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..e( - 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldType.OE, defaultOrMaker: GeneratedCodeInfo_Annotation_Semantic.NONE, valueOf: GeneratedCodeInfo_Annotation_Semantic.valueOf, enumValues: GeneratedCodeInfo_Annotation_Semantic.values) @@ -4274,7 +4274,7 @@ class GeneratedCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldType.PM, subBuilder: GeneratedCodeInfo_Annotation.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart index dc5428b0b..d58a9e1b8 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart @@ -106,7 +106,7 @@ class Duration extends $pb.GeneratedMessage with $mixin.DurationMixin { fromProto3Json: $mixin.DurationMixin.fromProto3JsonHelper) ..aInt64(1, _omitFieldNames ? '' : 'seconds') ..a<$core.int>( - 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldTypeInternal.O3) + 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index 67ea4cef5..d0464a069 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -181,7 +181,7 @@ class ProtobufField { /// Returns the tag number of the underlying proto field. int get number => descriptor.number; - /// Returns the constant in PbFieldTypeInternal corresponding to this type. + /// Returns the constant in PbFieldType corresponding to this type. String get typeConstant { var prefix = 'O'; if (isRequired) { @@ -191,7 +191,7 @@ class ProtobufField { } else if (isRepeated) { prefix = 'P'; } - return '$protobufImportPrefix.PbFieldTypeInternal.$prefix${baseType.typeConstantSuffix}'; + return '$protobufImportPrefix.PbFieldType.$prefix${baseType.typeConstantSuffix}'; } static String _formatArguments( @@ -260,7 +260,7 @@ class ProtobufField { 'const $protobufImportPrefix.PackageName(\'$package\')'; } } else if (isRepeated) { - if (typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.PS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.PS') { invocation = 'pPS'; } else { args.add(typeConstant); @@ -292,10 +292,10 @@ class ProtobufField { switch (type) { case '$coreImportPrefix.String': if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OS') { + '$protobufImportPrefix.PbFieldType.OS') { invocation = 'aOS'; } else if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.QS') { + '$protobufImportPrefix.PbFieldType.QS') { invocation = 'aQS'; } else { invocation = 'a<$type>'; @@ -304,7 +304,7 @@ class ProtobufField { break; case '$coreImportPrefix.bool': if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OB') { + '$protobufImportPrefix.PbFieldType.OB') { invocation = 'aOB'; } else { invocation = 'a<$type>'; @@ -319,7 +319,7 @@ class ProtobufField { } else { if (makeDefault == '$fixnumImportPrefix.Int64.ZERO' && type == '$fixnumImportPrefix.Int64' && - typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.O6') { + typeConstant == '$protobufImportPrefix.PbFieldType.O6') { invocation = 'aInt64'; } else { if (baseType.isMessage || baseType.isGroup) { diff --git a/protoc_plugin/test/goldens/extension.pb.dart b/protoc_plugin/test/goldens/extension.pb.dart index 1da48e7fc..32a5dcb75 100644 --- a/protoc_plugin/test/goldens/extension.pb.dart +++ b/protoc_plugin/test/goldens/extension.pb.dart @@ -1,4 +1,4 @@ -static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldTypeInternal.OS); +static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldType.OS); const $core.bool _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const $core.bool _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart b/protoc_plugin/test/goldens/messageGenerator.pb.dart index 7c285d54f..15d05a340 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart @@ -8,8 +8,8 @@ class PhoneNumber extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) - ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, defaultOrMaker: '\$') + ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$') ..aOS(4, _omitFieldNames ? '' : 'deprecatedField') ; diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta index a5992239b..faefae9b1 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1870 - end: 1876 + begin: 1854 + end: 1860 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1918 - end: 1924 + begin: 1902 + end: 1908 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2004 - end: 2013 + begin: 1988 + end: 1997 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2056 - end: 2067 + begin: 2040 + end: 2051 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2139 - end: 2143 + begin: 2123 + end: 2127 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2184 - end: 2188 + begin: 2168 + end: 2172 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2276 - end: 2283 + begin: 2260 + end: 2267 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2326 - end: 2335 + begin: 2310 + end: 2319 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2398 - end: 2402 + begin: 2382 + end: 2386 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2449 - end: 2453 + begin: 2433 + end: 2437 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2533 - end: 2540 + begin: 2517 + end: 2524 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2583 - end: 2592 + begin: 2567 + end: 2576 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2704 - end: 2719 + begin: 2688 + end: 2703 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2810 - end: 2825 + begin: 2794 + end: 2809 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2954 - end: 2972 + begin: 2938 + end: 2956 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3064 - end: 3084 + begin: 3048 + end: 3068 } diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart b/protoc_plugin/test/goldens/oneMessage.pb.dart index d408d4521..e38712f82 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart @@ -32,9 +32,8 @@ class PhoneNumber extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.O3) - ..a<$core.String>( - 3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, + ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.O3) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta index 6fdc950eb..44ec15bfc 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2234 - end: 2240 + begin: 2218 + end: 2224 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2282 - end: 2288 + begin: 2266 + end: 2272 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2368 - end: 2377 + begin: 2352 + end: 2361 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2420 - end: 2431 + begin: 2404 + end: 2415 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2491 - end: 2495 + begin: 2475 + end: 2479 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2537 - end: 2541 + begin: 2521 + end: 2525 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2623 - end: 2630 + begin: 2607 + end: 2614 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2673 - end: 2682 + begin: 2657 + end: 2666 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2745 - end: 2749 + begin: 2729 + end: 2733 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2796 - end: 2800 + begin: 2780 + end: 2784 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2880 - end: 2887 + begin: 2864 + end: 2871 } annotation: { path: 4 @@ -117,6 +117,6 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2930 - end: 2939 + begin: 2914 + end: 2923 } From f3021782afe2fcc33257d51a835e8b19f738e5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:37:32 +0100 Subject: [PATCH 16/22] Revert renaming --- protobuf/lib/src/protobuf/builder_info.dart | 31 ++- protobuf/lib/src/protobuf/coded_buffer.dart | 77 ++++--- .../lib/src/protobuf/coded_buffer_writer.dart | 46 ++-- .../lib/src/protobuf/extension_registry.dart | 2 +- protobuf/lib/src/protobuf/field_error.dart | 74 +++--- protobuf/lib/src/protobuf/field_info.dart | 32 +-- protobuf/lib/src/protobuf/field_set.dart | 8 +- protobuf/lib/src/protobuf/field_type.dart | 16 +- .../lib/src/protobuf/generated_message.dart | 2 +- protobuf/lib/src/protobuf/json.dart | 80 +++---- protobuf/lib/src/protobuf/pb_map.dart | 2 +- protobuf/lib/src/protobuf/proto3_json.dart | 134 +++++------ .../lib/src/protobuf/unknown_field_set.dart | 10 +- protobuf/lib/src/protobuf/wire_format.dart | 38 ++-- protobuf/test/codec_test.dart | 23 +- protobuf/test/list_test.dart | 12 +- protobuf/test/mock_util.dart | 20 +- protobuf/test/readonly_message_test.dart | 12 +- protoc_plugin/lib/src/base_type.dart | 2 +- .../lib/src/gen/dart_options.pb.dart | 19 +- .../lib/src/gen/google/api/client.pb.dart | 42 ++-- .../lib/src/gen/google/api/http.pb.dart | 7 +- .../lib/src/gen/google/api/routing.pb.dart | 6 +- .../google/protobuf/compiler/plugin.pb.dart | 25 +-- .../gen/google/protobuf/descriptor.pb.dart | 210 ++++++++---------- .../src/gen/google/protobuf/duration.pb.dart | 3 +- protoc_plugin/lib/src/protobuf_field.dart | 17 +- protoc_plugin/test/goldens/extension.pb.dart | 2 +- .../test/goldens/messageGenerator.pb.dart | 4 +- .../goldens/messageGenerator.pb.dart.meta | 64 +++--- protoc_plugin/test/goldens/oneMessage.pb.dart | 5 +- .../test/goldens/oneMessage.pb.dart.meta | 48 ++-- 32 files changed, 511 insertions(+), 562 deletions(-) diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index c236e58fa..d21b3dfa1 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -105,7 +105,7 @@ class BuilderInfo { name, tagNumber, index, - PbFieldTypeInternal.M, + PbFieldType.M, keyFieldType, valueFieldType, mapEntryBuilderInfo, @@ -179,13 +179,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.OS String with no default value to reduce generated + /// Adds PbFieldType.OS String with no default value to reduce generated /// code size. void aOS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.OS, + PbFieldType.OS, null, null, null, @@ -194,13 +194,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.PS String with no default value. + /// Adds PbFieldType.PS String with no default value. void pPS(int tagNumber, String name, {String? protoName}) { addRepeated( tagNumber, name, - PbFieldTypeInternal.PS, - getCheckFunction(PbFieldTypeInternal.PS), + PbFieldType.PS, + getCheckFunction(PbFieldType.PS), null, null, null, @@ -208,12 +208,12 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.QS String with no default value. + /// Adds PbFieldType.QS String with no default value. void aQS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.QS, + PbFieldType.QS, null, null, null, @@ -227,7 +227,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.O6, + PbFieldType.O6, Int64.ZERO, null, null, @@ -241,7 +241,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OB, + PbFieldType.OB, null, null, null, @@ -275,8 +275,8 @@ class BuilderInfo { // Repeated, not a message, group, or enum. void p(int tagNumber, String name, int fieldType, {String? protoName}) { assert( - !PbFieldTypeInternal.isGroupOrMessage(fieldType) && - !PbFieldTypeInternal.isEnum(fieldType), + !PbFieldType.isGroupOrMessage(fieldType) && + !PbFieldType.isEnum(fieldType), ); addRepeated( tagNumber, @@ -302,8 +302,7 @@ class BuilderInfo { String? protoName, }) { assert( - PbFieldTypeInternal.isGroupOrMessage(fieldType) || - PbFieldTypeInternal.isEnum(fieldType), + PbFieldType.isGroupOrMessage(fieldType) || PbFieldType.isEnum(fieldType), ); addRepeated( tagNumber, @@ -327,7 +326,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OM, + PbFieldType.OM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, @@ -345,7 +344,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.QM, + PbFieldType.QM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index c1cc0dbb6..0150e1b51 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -54,25 +54,24 @@ void _mergeFromCodedBufferReader( // Ignore required/optional packed/unpacked. var fieldType = fi.type; - fieldType &= - ~(PbFieldTypeInternal.PACKED_BIT | PbFieldTypeInternal.REQUIRED_BIT); + fieldType &= ~(PbFieldType.PACKED_BIT | PbFieldType.REQUIRED_BIT); switch (fieldType) { - case PbFieldTypeInternal.OPTIONAL_BOOL: + case PbFieldType.OPTIONAL_BOOL: fs._setFieldUnchecked(meta, fi, input.readBool()); break; - case PbFieldTypeInternal.OPTIONAL_BYTES: + case PbFieldType.OPTIONAL_BYTES: fs._setFieldUnchecked(meta, fi, input.readBytes()); break; - case PbFieldTypeInternal.OPTIONAL_STRING: + case PbFieldType.OPTIONAL_STRING: fs._setFieldUnchecked(meta, fi, input.readString()); break; - case PbFieldTypeInternal.OPTIONAL_FLOAT: + case PbFieldType.OPTIONAL_FLOAT: fs._setFieldUnchecked(meta, fi, input.readFloat()); break; - case PbFieldTypeInternal.OPTIONAL_DOUBLE: + case PbFieldType.OPTIONAL_DOUBLE: fs._setFieldUnchecked(meta, fi, input.readDouble()); break; - case PbFieldTypeInternal.OPTIONAL_ENUM: + case PbFieldType.OPTIONAL_ENUM: final rawValue = input.readEnum(); final value = meta._decodeEnum(tagNumber, registry, rawValue); if (value == null) { @@ -82,7 +81,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, value); } break; - case PbFieldTypeInternal.OPTIONAL_GROUP: + case PbFieldType.OPTIONAL_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); final oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { @@ -91,37 +90,37 @@ void _mergeFromCodedBufferReader( input.readGroup(tagNumber, subMessage, registry); fs._setFieldUnchecked(meta, fi, subMessage); break; - case PbFieldTypeInternal.OPTIONAL_INT32: + case PbFieldType.OPTIONAL_INT32: fs._setFieldUnchecked(meta, fi, input.readInt32()); break; - case PbFieldTypeInternal.OPTIONAL_INT64: + case PbFieldType.OPTIONAL_INT64: fs._setFieldUnchecked(meta, fi, input.readInt64()); break; - case PbFieldTypeInternal.OPTIONAL_SINT32: + case PbFieldType.OPTIONAL_SINT32: fs._setFieldUnchecked(meta, fi, input.readSint32()); break; - case PbFieldTypeInternal.OPTIONAL_SINT64: + case PbFieldType.OPTIONAL_SINT64: fs._setFieldUnchecked(meta, fi, input.readSint64()); break; - case PbFieldTypeInternal.OPTIONAL_UINT32: + case PbFieldType.OPTIONAL_UINT32: fs._setFieldUnchecked(meta, fi, input.readUint32()); break; - case PbFieldTypeInternal.OPTIONAL_UINT64: + case PbFieldType.OPTIONAL_UINT64: fs._setFieldUnchecked(meta, fi, input.readUint64()); break; - case PbFieldTypeInternal.OPTIONAL_FIXED32: + case PbFieldType.OPTIONAL_FIXED32: fs._setFieldUnchecked(meta, fi, input.readFixed32()); break; - case PbFieldTypeInternal.OPTIONAL_FIXED64: + case PbFieldType.OPTIONAL_FIXED64: fs._setFieldUnchecked(meta, fi, input.readFixed64()); break; - case PbFieldTypeInternal.OPTIONAL_SFIXED32: + case PbFieldType.OPTIONAL_SFIXED32: fs._setFieldUnchecked(meta, fi, input.readSfixed32()); break; - case PbFieldTypeInternal.OPTIONAL_SFIXED64: + case PbFieldType.OPTIONAL_SFIXED64: fs._setFieldUnchecked(meta, fi, input.readSfixed64()); break; - case PbFieldTypeInternal.OPTIONAL_MESSAGE: + case PbFieldType.OPTIONAL_MESSAGE: final GeneratedMessage? oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { input.readMessage(oldValue, registry); @@ -131,7 +130,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, subMessage); } break; - case PbFieldTypeInternal.REPEATED_BOOL: + case PbFieldType.REPEATED_BOOL: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -151,17 +150,17 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readBool()); } break; - case PbFieldTypeInternal.REPEATED_BYTES: + case PbFieldType.REPEATED_BYTES: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readBytes()); break; - case PbFieldTypeInternal.REPEATED_STRING: + case PbFieldType.REPEATED_STRING: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readString()); break; - case PbFieldTypeInternal.REPEATED_FLOAT: + case PbFieldType.REPEATED_FLOAT: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -178,7 +177,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFloat()); } break; - case PbFieldTypeInternal.REPEATED_DOUBLE: + case PbFieldType.REPEATED_DOUBLE: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -195,7 +194,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readDouble()); } break; - case PbFieldTypeInternal.REPEATED_ENUM: + case PbFieldType.REPEATED_ENUM: final list = fs._ensureRepeatedField(meta, fi); _readPackableToListEnum( list, @@ -207,13 +206,13 @@ void _mergeFromCodedBufferReader( registry, ); break; - case PbFieldTypeInternal.REPEATED_GROUP: + case PbFieldType.REPEATED_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readGroup(tagNumber, subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal.REPEATED_INT32: + case PbFieldType.REPEATED_INT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -230,7 +229,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt32()); } break; - case PbFieldTypeInternal.REPEATED_INT64: + case PbFieldType.REPEATED_INT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -247,7 +246,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt64()); } break; - case PbFieldTypeInternal.REPEATED_SINT32: + case PbFieldType.REPEATED_SINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -264,7 +263,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint32()); } break; - case PbFieldTypeInternal.REPEATED_SINT64: + case PbFieldType.REPEATED_SINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -281,7 +280,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint64()); } break; - case PbFieldTypeInternal.REPEATED_UINT32: + case PbFieldType.REPEATED_UINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -298,7 +297,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint32()); } break; - case PbFieldTypeInternal.REPEATED_UINT64: + case PbFieldType.REPEATED_UINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -315,7 +314,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint64()); } break; - case PbFieldTypeInternal.REPEATED_FIXED32: + case PbFieldType.REPEATED_FIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -332,7 +331,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed32()); } break; - case PbFieldTypeInternal.REPEATED_FIXED64: + case PbFieldType.REPEATED_FIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -349,7 +348,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed64()); } break; - case PbFieldTypeInternal.REPEATED_SFIXED32: + case PbFieldType.REPEATED_SFIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -366,7 +365,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed32()); } break; - case PbFieldTypeInternal.REPEATED_SFIXED64: + case PbFieldType.REPEATED_SFIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -383,13 +382,13 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed64()); } break; - case PbFieldTypeInternal.REPEATED_MESSAGE: + case PbFieldType.REPEATED_MESSAGE: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readMessage(subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal.MAP: + case PbFieldType.MAP: final mapFieldInfo = fi as MapFieldInfo; final mapEntryMeta = mapFieldInfo.mapEntryBuilderInfo; fs diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index f3f483af1..8809ce297 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -65,9 +65,9 @@ class CodedBufferWriter { } void writeField(int fieldNumber, int fieldType, Object? fieldValue) { - final valueType = PbFieldTypeInternal.baseType(fieldType); + final valueType = PbFieldType.baseType(fieldType); - if ((fieldType & PbFieldTypeInternal.PACKED_BIT) != 0) { + if ((fieldType & PbFieldType.PACKED_BIT) != 0) { final list = fieldValue as List; if (list.isNotEmpty) { _writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); @@ -80,7 +80,7 @@ class CodedBufferWriter { return; } - if ((fieldType & PbFieldTypeInternal.MAP_BIT) != 0) { + if ((fieldType & PbFieldType.MAP_BIT) != 0) { final map = fieldValue as PbMap; final keyWireFormat = _wireTypes[_valueTypeIndex(map.keyFieldType)]; final valueWireFormat = _wireTypes[_valueTypeIndex(map.valueFieldType)]; @@ -107,7 +107,7 @@ class CodedBufferWriter { final wireFormat = _wireTypes[_valueTypeIndex(valueType)]; - if ((fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0) { + if ((fieldType & PbFieldType.REPEATED_BIT) != 0) { final list = fieldValue as List; for (var i = 0; i < list.length; i++) { _writeValue(fieldNumber, valueType, list[i], wireFormat); @@ -353,10 +353,10 @@ class CodedBufferWriter { void _writeValueAs(int valueType, dynamic value) { switch (valueType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: _writeVarint32(value ? 1 : 0); break; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: final List bytes = value; if (bytes is Uint8List) { _writeBytesNoTag(bytes); @@ -366,7 +366,7 @@ class CodedBufferWriter { _writeBytesNoTag(Uint8List.fromList(bytes)); } break; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: final String string = value; if (string.isEmpty) { _writeEmptyBytes(); @@ -374,17 +374,17 @@ class CodedBufferWriter { _writeBytesNoTag(const Utf8Encoder().convert(string)); } break; - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.DOUBLE_BIT: _writeDouble(value); break; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: _writeFloat(value); break; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: final ProtobufEnum enum_ = value; _writeVarint32(enum_.value & 0xffffffff); break; - case PbFieldTypeInternal.GROUP_BIT: + case PbFieldType.GROUP_BIT: // `value` is `UnknownFieldSet` or `GeneratedMessage`. Test for // `UnknownFieldSet` as it doesn't have subtypes, so the type test will // be fast. @@ -399,37 +399,37 @@ class CodedBufferWriter { message.writeToCodedBufferWriter(this); } break; - case PbFieldTypeInternal.INT32_BIT: + case PbFieldType.INT32_BIT: _writeVarint64(Int64(value)); break; - case PbFieldTypeInternal.INT64_BIT: + case PbFieldType.INT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal.SINT32_BIT: + case PbFieldType.SINT32_BIT: _writeVarint32(_encodeZigZag32(value)); break; - case PbFieldTypeInternal.SINT64_BIT: + case PbFieldType.SINT64_BIT: _writeVarint64(_encodeZigZag64(value)); break; - case PbFieldTypeInternal.UINT32_BIT: + case PbFieldType.UINT32_BIT: _writeVarint32(value); break; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.FIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.FIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.SFIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.SFIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.MESSAGE_BIT: final mark = _startLengthDelimited(); final GeneratedMessage msg = value; msg.writeToCodedBufferWriter(this); @@ -459,7 +459,7 @@ class CodedBufferWriter { ) { _writeTag(fieldNumber, wireFormat); _writeValueAs(valueType, value); - if (valueType == PbFieldTypeInternal.GROUP_BIT) { + if (valueType == PbFieldType.GROUP_BIT) { _writeTag(fieldNumber, WIRETYPE_END_GROUP); } } diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index 16cb448a1..f7de71afc 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart @@ -181,7 +181,7 @@ T _reparseMessage( final messageMapDynamic = message._fieldSet._values[field.index!]; if (messageMapDynamic == null) continue; final PbMap messageMap = messageMapDynamic; - if (PbFieldTypeInternal.isGroupOrMessage(field.valueFieldType)) { + if (PbFieldType.isGroupOrMessage(field.valueFieldType)) { for (final key in messageMap.keys) { final GeneratedMessage value = messageMap[key]; final reparsedValue = _reparseMessage(value, extensionRegistry); diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index d8a04ad9c..0381cc75c 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -10,53 +10,53 @@ part of 'internal.dart'; /// For enums, group, and message fields, this check is only approximate, /// because the exact type isn't included in [fieldType]. String? _getFieldError(int fieldType, var value) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is! bool) return 'not type bool'; return null; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is! List) return 'not List'; return null; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is! String) return 'not type String'; return null; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: if (value is! double) return 'not type double'; if (!_isFloat32(value)) return 'out of range for float'; return null; - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.DOUBLE_BIT: if (value is! double) return 'not type double'; return null; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: if (value is! ProtobufEnum) return 'not type ProtobufEnum'; return null; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: if (value is! int) return 'not type int'; if (!_isSigned32(value)) return 'out of range for signed 32-bit int'; return null; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: if (value is! int) return 'not type int'; if (!_isUnsigned32(value)) return 'out of range for unsigned 32-bit int'; return null; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 if (value is! Int64) return 'not Int64'; return null; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: if (value is! GeneratedMessage) return 'not a GeneratedMessage'; return null; default: @@ -74,33 +74,33 @@ String? _getFieldError(int fieldType, var value) { /// @nodoc CheckFunc getCheckFunction(int fieldType) { switch (fieldType & ~0x7) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.BYTES_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: - case PbFieldTypeInternal.ENUM_BIT: - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.BOOL_BIT: + case PbFieldType.BYTES_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.DOUBLE_BIT: + case PbFieldType.ENUM_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 return _checkNotNull; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: return _checkFloat; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: return _checkSigned32; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: return _checkUnsigned32; } throw ArgumentError('check function not implemented: $fieldType'); diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index fed7d8d38..dbdd7d0ee 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -65,7 +65,7 @@ class FieldInfo { /// The value is `null` for extension fields. final int? index; - /// Type of this field. See [PbFieldTypeInternal]. + /// Type of this field. See [PbFieldType]. final int type; /// Constructs the default value of a field. @@ -114,11 +114,11 @@ class FieldInfo { _protoName = protoName, assert(type != 0), assert( - !PbFieldTypeInternal.isGroupOrMessage(type) || + !PbFieldType.isGroupOrMessage(type) || subBuilder != null || - PbFieldTypeInternal.isMapField(type), + PbFieldType.isMapField(type), ), - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(!PbFieldType.isEnum(type) || valueOf != null); // Represents a field that has been removed by a program transformation. FieldInfo.dummy(this.index) @@ -146,11 +146,11 @@ class FieldInfo { String? protoName, }) : makeDefault = (() => PbList(check: check)), _protoName = protoName, - assert(PbFieldTypeInternal.isRepeated(type)), - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(PbFieldType.isRepeated(type)), + assert(!PbFieldType.isEnum(type) || valueOf != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { - if (defaultOrMaker == null) return PbFieldTypeInternal.defaultForType(type); + if (defaultOrMaker == null) return PbFieldType.defaultForType(type); if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; return () => defaultOrMaker; } @@ -159,11 +159,11 @@ class FieldInfo { /// been removed by a program transformation. bool get _isDummy => tagNumber == 0; - bool get isRequired => PbFieldTypeInternal.isRequired(type); - bool get isRepeated => PbFieldTypeInternal.isRepeated(type); - bool get isGroupOrMessage => PbFieldTypeInternal.isGroupOrMessage(type); - bool get isEnum => PbFieldTypeInternal.isEnum(type); - bool get isMapField => PbFieldTypeInternal.isMapField(type); + bool get isRequired => PbFieldType.isRequired(type); + bool get isRepeated => PbFieldType.isRepeated(type); + bool get isGroupOrMessage => PbFieldType.isGroupOrMessage(type); + bool get isEnum => PbFieldType.isEnum(type); + bool get isMapField => PbFieldType.isMapField(type); /// Returns a read-only default value for a field. Unlike /// [GeneratedMessage.getField], doesn't create a repeated field. @@ -178,7 +178,7 @@ class FieldInfo { /// That is, it doesn't contain any required fields that aren't initialized. bool _hasRequiredValues(dynamic value) { if (value == null) return !isRequired; // missing is okay if optional - if (!PbFieldTypeInternal.isGroupOrMessage(type)) { + if (!PbFieldType.isGroupOrMessage(type)) { return true; // primitive and present } @@ -203,7 +203,7 @@ class FieldInfo { void _appendInvalidFields(List problems, value, String prefix) { if (value == null) { if (isRequired) problems.add('$prefix$name'); - } else if (!PbFieldTypeInternal.isGroupOrMessage(type)) { + } else if (!PbFieldType.isGroupOrMessage(type)) { // primitive and present } else if (!isRepeated) { // Required message/group: recurse. @@ -297,7 +297,7 @@ class MapFieldInfo extends FieldInfo?> { this.valueCreator, { ProtobufEnum? defaultEnumValue, String? protoName, - }) : assert(PbFieldTypeInternal.isMapField(type)), + }) : assert(PbFieldType.isMapField(type)), super( name, tagNumber, @@ -307,7 +307,7 @@ class MapFieldInfo extends FieldInfo?> { defaultEnumValue: defaultEnumValue, protoName: protoName, ) { - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(!PbFieldType.isEnum(type) || valueOf != null); } FieldInfo get valueFieldInfo => diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index f7c260883..980c03c61 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -626,11 +626,11 @@ class FieldSet { } hash = HashUtils.combine(hash, fi.tagNumber); - if (PbFieldTypeInternal.isBytes(fi.type)) { + if (PbFieldType.isBytes(fi.type)) { // Bytes are represented as a List (Usually with byte-data). // We special case that to match our equality semantics. hash = HashUtils.combine(hash, HashUtils.hashObjects(value)); - } else if (!PbFieldTypeInternal.isEnum(fi.type)) { + } else if (!PbFieldType.isEnum(fi.type)) { hash = HashUtils.combine(hash, value.hashCode); } else if (fi.isRepeated) { final PbList list = value; @@ -772,7 +772,7 @@ class FieldSet { final MapFieldInfo f = fi as dynamic; final PbMap map = f._ensureMapField(meta, this) as dynamic; - if (PbFieldTypeInternal.isGroupOrMessage(f.valueFieldType)) { + if (PbFieldType.isGroupOrMessage(f.valueFieldType)) { final PbMap fieldValueMap = fieldValue; for (final entry in fieldValueMap.entries) { map[entry.key] = entry.value.deepCopy(); @@ -784,7 +784,7 @@ class FieldSet { } if (fi.isRepeated) { - if (PbFieldTypeInternal.isGroupOrMessage(otherFi.type)) { + if (PbFieldType.isGroupOrMessage(otherFi.type)) { // fieldValue must be a PbList of GeneratedMessage. final PbList pbList = fieldValue; final repeatedFields = fi._ensureRepeatedField(meta, this); diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index a3e6cb4ae..67b3194e8 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -6,26 +6,24 @@ part of 'internal.dart'; /// Defines constants and functions for dealing with fieldType bits. -class PbFieldTypeInternal { +class PbFieldType { static bool isRepeated(int fieldType) => - (fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0; + (fieldType & PbFieldType.REPEATED_BIT) != 0; static bool isRequired(int fieldType) => - (fieldType & PbFieldTypeInternal.REQUIRED_BIT) != 0; + (fieldType & PbFieldType.REQUIRED_BIT) != 0; static bool isEnum(int fieldType) => - PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.ENUM_BIT; + PbFieldType.baseType(fieldType) == PbFieldType.ENUM_BIT; static bool isBytes(int fieldType) => - PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.BYTES_BIT; + PbFieldType.baseType(fieldType) == PbFieldType.BYTES_BIT; static bool isGroupOrMessage(int fieldType) => - (fieldType & - (PbFieldTypeInternal.GROUP_BIT | PbFieldTypeInternal.MESSAGE_BIT)) != - 0; + (fieldType & (PbFieldType.GROUP_BIT | PbFieldType.MESSAGE_BIT)) != 0; static bool isMapField(int fieldType) => - (fieldType & PbFieldTypeInternal.MAP_BIT) != 0; + (fieldType & PbFieldType.MAP_BIT) != 0; /// Returns the base field type without any of the required, repeated /// and packed bits. diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 0660a072f..35caa69bb 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -418,7 +418,7 @@ abstract class GeneratedMessage { /// Sets the value of a non-repeated extension field to [value]. void setExtension(Extension extension, Object value) { - if (PbFieldTypeInternal.isRepeated(extension.type)) { + if (PbFieldType.isRepeated(extension.type)) { throw ArgumentError( _fieldSet._setFieldFailedMessage( extension, diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index df74de5be..5021fc07f 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -6,24 +6,24 @@ part of 'internal.dart'; Map _writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { - final baseType = PbFieldTypeInternal.baseType(fieldType); + final baseType = PbFieldType.baseType(fieldType); - if (PbFieldTypeInternal.isRepeated(fieldType)) { + if (PbFieldType.isRepeated(fieldType)) { final PbList list = fieldValue; return List.from(list.map((e) => convertToMap(e, baseType))); } switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.BOOL_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { return nan; @@ -35,22 +35,22 @@ Map _writeToJsonMap(FieldSet fs) { return fieldValue.toInt(); } return value; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: // Encode 'bytes' as a base64-encoded string. return base64Encode(fieldValue as List); - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value; // assume |value| < 2^52 - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned(); - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: @@ -73,7 +73,7 @@ Map _writeToJsonMap(FieldSet fs) { if (value == null || (value is List && value.isEmpty)) { continue; // It's missing, repeated, or an empty byte array. } - if (PbFieldTypeInternal.isMapField(fi.type)) { + if (PbFieldType.isMapField(fi.type)) { result['${fi.tagNumber}'] = writeMap( value, fi as MapFieldInfo, @@ -246,8 +246,8 @@ dynamic _convertJsonValue( ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is bool) { return value; } else if (value is String) { @@ -265,20 +265,20 @@ dynamic _convertJsonValue( } expectedType = 'bool (true, false, "true", "false", 1, 0)'; break; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is String) { return base64Decode(value); } expectedType = 'Base64 String'; break; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is String) { return value; } expectedType = 'String'; break; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value is double) { return value; @@ -289,7 +289,7 @@ dynamic _convertJsonValue( } expectedType = 'num or stringified num'; break; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: // Allow quoted values, although we don't emit them. if (value is String) { value = int.parse(value); @@ -302,15 +302,15 @@ dynamic _convertJsonValue( } expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: if (value is int) return value; if (value is String) return int.parse(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: int? validatedValue; if (value is int) validatedValue = value; if (value is String) validatedValue = int.parse(value); @@ -320,17 +320,17 @@ dynamic _convertJsonValue( if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) return Int64.parseInt(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; final subMessage = meta._makeEmptyMessage(tagNumber, registry); diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 0d929091a..2816eb69f 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -124,7 +124,7 @@ class PbMap extends MapBase { PbMap freeze() { _isReadOnly = true; - if (PbFieldTypeInternal.isGroupOrMessage(valueFieldType)) { + if (PbFieldType.isGroupOrMessage(valueFieldType)) { for (final subMessage in values as Iterable) { subMessage.freeze(); } diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index 61632bc1a..0fe4849c6 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -6,26 +6,26 @@ part of 'internal.dart'; Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { - final baseType = PbFieldTypeInternal.baseType(keyType); + final baseType = PbFieldType.baseType(keyType); - assert(!PbFieldTypeInternal.isRepeated(keyType)); + assert(!PbFieldType.isRepeated(keyType)); switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: return key ? 'true' : 'false'; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return key; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: return (key as Int64).toStringUnsigned(); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return key.toString(); default: throw StateError('Not a valid key type $keyType'); @@ -35,33 +35,33 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { Object? valueToProto3Json(dynamic fieldValue, int? fieldType) { if (fieldValue == null) return null; - if (PbFieldTypeInternal.isGroupOrMessage(fieldType!)) { + if (PbFieldType.isGroupOrMessage(fieldType!)) { return _writeToProto3Json( (fieldValue as GeneratedMessage)._fieldSet, typeRegistry, ); - } else if (PbFieldTypeInternal.isEnum(fieldType)) { + } else if (PbFieldType.isEnum(fieldType)) { return (fieldValue as ProtobufEnum).name; } else { - final baseType = PbFieldTypeInternal.baseType(fieldType); + final baseType = PbFieldType.baseType(fieldType); switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: return fieldValue as bool; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return fieldValue; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return nan; @@ -73,9 +73,9 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { return value.toInt(); } return value; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: return (fieldValue as Int64).toStringUnsigned(); - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: return base64Encode(fieldValue); default: throw StateError( @@ -176,13 +176,13 @@ void _mergeFromProto3Json( void recursionHelper(Object? json, FieldSet fieldSet) { Object? convertProto3JsonValue(Object value, FieldInfo fieldInfo) { final fieldType = fieldInfo.type; - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is bool) { return value; } throw context.parseException('Expected bool value', json); - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is String) { Uint8List result; try { @@ -199,13 +199,13 @@ void _mergeFromProto3Json( 'Expected bytes encoded as base64 String', value, ); - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is String) { return value; } throw context.parseException('Expected String value', value); - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: if (value is double) { return value; } else if (value is num) { @@ -221,7 +221,7 @@ void _mergeFromProto3Json( 'Expected a double represented as a String or number', value, ); - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: if (value is String) { // TODO(sigurdm): Do we want to avoid linear search here? Measure... final result = @@ -245,8 +245,8 @@ void _mergeFromProto3Json( 'Expected enum as a string or integer', value, ); - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: int result; if (value is int) { result = value; @@ -259,9 +259,9 @@ void _mergeFromProto3Json( ); } return _check32BitUnsignedProto3(result, context); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: int result; if (value is int) { result = value; @@ -275,7 +275,7 @@ void _mergeFromProto3Json( } _check32BitSignedProto3(result, context); return result; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: Int64 result; if (value is int) { result = Int64(value); @@ -288,10 +288,10 @@ void _mergeFromProto3Json( ); } return result; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) { Int64 result; @@ -309,8 +309,8 @@ void _mergeFromProto3Json( 'Expected int or stringified int', value, ); - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: final subMessage = fieldInfo.subBuilder!(); recursionHelper(value, subMessage._fieldSet); return subMessage; @@ -320,8 +320,8 @@ void _mergeFromProto3Json( } Object decodeMapKey(String key, int fieldType) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: switch (key) { case 'true': return true; @@ -333,26 +333,26 @@ void _mergeFromProto3Json( key, ); } - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return key; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: // TODO(sigurdm): We do not throw on negative values here. // That would probably require going via bignum. return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return _check32BitSignedProto3( _tryParse32BitProto3(key, context), context, ); - case PbFieldTypeInternal.UINT32_BIT: + case PbFieldType.UINT32_BIT: return _check32BitUnsignedProto3( _tryParse32BitProto3(key, context), context, @@ -400,7 +400,7 @@ void _mergeFromProto3Json( } } - if (PbFieldTypeInternal.isMapField(fieldInfo.type)) { + if (PbFieldType.isMapField(fieldInfo.type)) { if (value is Map) { final mapFieldInfo = fieldInfo as MapFieldInfo; final Map fieldValues = fieldSet._ensureMapField(meta, fieldInfo); @@ -421,7 +421,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a map', value); } - } else if (PbFieldTypeInternal.isRepeated(fieldInfo.type)) { + } else if (PbFieldType.isRepeated(fieldInfo.type)) { if (value is List) { final values = fieldSet._ensureRepeatedField(meta, fieldInfo); for (var i = 0; i < value.length; i++) { @@ -433,7 +433,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a list', value); } - } else if (PbFieldTypeInternal.isGroupOrMessage(fieldInfo.type)) { + } else if (PbFieldType.isGroupOrMessage(fieldInfo.type)) { // TODO(sigurdm) consider a cleaner separation between parsing and // merging. final parsedSubMessage = diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 9702c5670..196c6b4fe 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -283,11 +283,11 @@ class UnknownFieldSetField { output.writeField(fieldNumber, type, value); } - write(PbFieldTypeInternal.REPEATED_UINT64, varints); - write(PbFieldTypeInternal.REPEATED_FIXED32, fixed32s); - write(PbFieldTypeInternal.REPEATED_FIXED64, fixed64s); - write(PbFieldTypeInternal.REPEATED_BYTES, lengthDelimited); - write(PbFieldTypeInternal.REPEATED_GROUP, groups); + write(PbFieldType.REPEATED_UINT64, varints); + write(PbFieldType.REPEATED_FIXED32, fixed32s); + write(PbFieldType.REPEATED_FIXED64, fixed64s); + write(PbFieldType.REPEATED_BYTES, lengthDelimited); + write(PbFieldType.REPEATED_GROUP, groups); } void addGroup(UnknownFieldSet value) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index 16e400b4a..375ee4b2d 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -38,32 +38,32 @@ int makeTag(int fieldNumber, int tag) => (fieldNumber << _TAG_TYPE_BITS) | tag; /// Returns true if the wireType can be merged into the given fieldType. bool _wireTypeMatches(int fieldType, int wireType) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.ENUM_BIT: - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.UINT64_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: + case PbFieldType.ENUM_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.UINT64_BIT: return wireType == WIRETYPE_VARINT || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return wireType == WIRETYPE_FIXED32 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.DOUBLE_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.DOUBLE_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: return wireType == WIRETYPE_FIXED64 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.BYTES_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.BYTES_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.MESSAGE_BIT: return wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.GROUP_BIT: + case PbFieldType.GROUP_BIT: return wireType == WIRETYPE_START_GROUP; default: return false; diff --git a/protobuf/test/codec_test.dart b/protobuf/test/codec_test.dart index 650259c1e..215e90d7f 100644 --- a/protobuf/test/codec_test.dart +++ b/protobuf/test/codec_test.dart @@ -29,7 +29,7 @@ void main() { }; } - final int32ToBytes = convertToBytes(PbFieldTypeInternal.O3); + final int32ToBytes = convertToBytes(PbFieldType.O3); test('testInt32RoundTrips', () { final roundtrip = roundtripTester( @@ -60,7 +60,7 @@ void main() { test('testSint32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint32(), - toBytes: convertToBytes(PbFieldTypeInternal.OS3), + toBytes: convertToBytes(PbFieldType.OS3), ); roundtrip(0, [0x00]); @@ -72,7 +72,7 @@ void main() { test('testSint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OS6), + toBytes: convertToBytes(PbFieldType.OS6), ); roundtrip(make64(0), [0x00]); @@ -84,7 +84,7 @@ void main() { test('testFixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OF3), + toBytes: convertToBytes(PbFieldType.OF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -96,7 +96,7 @@ void main() { test('testFixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OF6), + toBytes: convertToBytes(PbFieldType.OF6), ); roundtrip(make64(0, 0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -126,7 +126,7 @@ void main() { test('testSfixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF3), + toBytes: convertToBytes(PbFieldType.OSF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -138,7 +138,7 @@ void main() { test('testSfixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF6), + toBytes: convertToBytes(PbFieldType.OSF6), ); roundtrip(make64(0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -183,7 +183,7 @@ void main() { : equals(expected); List dataToBytes(ByteData byteData) => Uint8List.view(byteData.buffer); - final floatToBytes = convertToBytes(PbFieldTypeInternal.OF); + final floatToBytes = convertToBytes(PbFieldType.OF); int floatToBits(double value) => makeData(floatToBytes(value)).getUint32(0, Endian.little); @@ -197,7 +197,7 @@ void main() { expect(readFloat(bits), doubleEquals(value)); } - final doubleToBytes = convertToBytes(PbFieldTypeInternal.OD); + final doubleToBytes = convertToBytes(PbFieldType.OD); void test64(List hilo, double value) { // Encode a double to its wire format. @@ -732,7 +732,7 @@ void main() { test('testVarint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readUint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OU6), + toBytes: convertToBytes(PbFieldType.OU6), ); roundtrip(make64(0), [0x00]); @@ -794,8 +794,7 @@ void main() { }); test('testWriteTo', () { - final writer = - CodedBufferWriter()..writeField(0, PbFieldTypeInternal.O3, 1337); + final writer = CodedBufferWriter()..writeField(0, PbFieldType.O3, 1337); expect(writer.lengthInBytes, 3); final buffer = Uint8List(5); buffer[0] = 0x55; diff --git a/protobuf/test/list_test.dart b/protobuf/test/list_test.dart index 319b730d9..23e995100 100644 --- a/protobuf/test/list_test.dart +++ b/protobuf/test/list_test.dart @@ -98,9 +98,7 @@ void main() { }); test('PbList for signed int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.P3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.P3)); expect(() { list.add(-2147483649); @@ -128,9 +126,7 @@ void main() { }); test('PBList for unsigned int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PU3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PU3)); expect(() { list.add(-1); @@ -158,9 +154,7 @@ void main() { }); test('PbList for float validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PF), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PF)); expect(() { list.add(3.4028234663852886E39); diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index 8b5edd66d..fdd385ea3 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -9,28 +9,22 @@ import 'package:protobuf/protobuf.dart' BuilderInfo, CreateBuilderFunc, GeneratedMessage, - PbFieldTypeInternal, + PbFieldType, ProtobufEnum; final mockEnumValues = [ProtobufEnum(1, 'a'), ProtobufEnum(2, 'b')]; BuilderInfo mockInfo(String className, CreateBuilderFunc create) { return BuilderInfo(className, createEmptyInstance: create) - ..a(1, 'val', PbFieldTypeInternal.O3, defaultOrMaker: 42) - ..a(2, 'str', PbFieldTypeInternal.OS) - ..a( - 3, - 'child', - PbFieldTypeInternal.OM, - defaultOrMaker: create, - subBuilder: create, - ) - ..p(4, 'int32s', PbFieldTypeInternal.P3) - ..a(5, 'int64', PbFieldTypeInternal.O6) + ..a(1, 'val', PbFieldType.O3, defaultOrMaker: 42) + ..a(2, 'str', PbFieldType.OS) + ..a(3, 'child', PbFieldType.OM, defaultOrMaker: create, subBuilder: create) + ..p(4, 'int32s', PbFieldType.P3) + ..a(5, 'int64', PbFieldType.O6) // 6 is reserved for extensions in other tests. ..e( 7, 'enm', - PbFieldTypeInternal.OE, + PbFieldType.OE, defaultOrMaker: mockEnumValues.first, valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), enumValues: mockEnumValues, diff --git a/protobuf/test/readonly_message_test.dart b/protobuf/test/readonly_message_test.dart index dba11f208..cf5b37d59 100644 --- a/protobuf/test/readonly_message_test.dart +++ b/protobuf/test/readonly_message_test.dart @@ -3,11 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:protobuf/protobuf.dart' - show - BuilderInfo, - GeneratedMessage, - PbFieldTypeInternal, - UnknownFieldSetField; + show BuilderInfo, GeneratedMessage, PbFieldType, UnknownFieldSetField; import 'package:test/test.dart'; Matcher throwsUnsupportedError(Matcher expectedMessage) => throwsA( @@ -27,9 +23,9 @@ class Rec extends GeneratedMessage { @override BuilderInfo info_ = BuilderInfo('rec') - ..a(1, 'value', PbFieldTypeInternal.O3) - ..pc(2, 'sub', PbFieldTypeInternal.PM, subBuilder: Rec.create) - ..p(10, 'ints', PbFieldTypeInternal.P3); + ..a(1, 'value', PbFieldType.O3) + ..pc(2, 'sub', PbFieldType.PM, subBuilder: Rec.create) + ..p(10, 'ints', PbFieldType.P3); int get value => $_get(0, 0); set value(int v) { diff --git a/protoc_plugin/lib/src/base_type.dart b/protoc_plugin/lib/src/base_type.dart index 6a96832c6..0f5d08c60 100644 --- a/protoc_plugin/lib/src/base_type.dart +++ b/protoc_plugin/lib/src/base_type.dart @@ -12,7 +12,7 @@ class BaseType { /// The name of the Dart type when in the same package. final String unprefixed; - /// The suffix of the constant for this type in PbFieldTypeInternal. + /// The suffix of the constant for this type in PbFieldType. /// (For example, 'B' for boolean or '3' for int32.) final String typeConstantSuffix; diff --git a/protoc_plugin/lib/src/gen/dart_options.pb.dart b/protoc_plugin/lib/src/gen/dart_options.pb.dart index 8b53eb43f..5534342aa 100644 --- a/protoc_plugin/lib/src/gen/dart_options.pb.dart +++ b/protoc_plugin/lib/src/gen/dart_options.pb.dart @@ -125,8 +125,7 @@ class Imports extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Imports', package: const $pb.PackageName(_omitMessageNames ? '' : 'dart_options'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldTypeInternal.PM, + ..pc(1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, subBuilder: DartMixin.create) ..hasRequiredFields = false; @@ -166,44 +165,44 @@ class Dart_options { _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'imports', 28125061, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: Imports.getDefault, subBuilder: Imports.create); static final defaultMixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'defaultMixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final mixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.MessageOptions', _omitFieldNames ? '' : 'mixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final overrideGetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideGetter', 28205290, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideSetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideSetter', 28937366, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideHasMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideHasMethod', 28937461, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideClearMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideClearMethod', 28907907, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final dartName = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'dartName', 28700919, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(imports); registry.add(defaultMixin); diff --git a/protoc_plugin/lib/src/gen/google/api/client.pb.dart b/protoc_plugin/lib/src/gen/google/api/client.pb.dart index 16590b7f6..4660db8c8 100644 --- a/protoc_plugin/lib/src/gen/google/api/client.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/client.pb.dart @@ -53,7 +53,7 @@ class CommonLanguageSettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'referenceDocsUri') ..pc( - 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldTypeInternal.KE, + 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldType.KE, valueOf: ClientLibraryDestination.valueOf, enumValues: ClientLibraryDestination.values, defaultEnumValue: @@ -164,7 +164,7 @@ class ClientLibrarySettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'version') ..e<$1.LaunchStage>( - 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldType.OE, defaultOrMaker: $1.LaunchStage.LAUNCH_STAGE_UNSPECIFIED, valueOf: $1.LaunchStage.valueOf, enumValues: $1.LaunchStage.values) @@ -389,7 +389,7 @@ class Publishing extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldType.PM, subBuilder: MethodSettings.create) ..aOS(101, _omitFieldNames ? '' : 'newIssueUri') ..aOS(102, _omitFieldNames ? '' : 'documentationUri') @@ -398,13 +398,13 @@ class Publishing extends $pb.GeneratedMessage { ..pPS(105, _omitFieldNames ? '' : 'codeownerGithubTeams') ..aOS(106, _omitFieldNames ? '' : 'docTagPrefix') ..e( - 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldTypeInternal.OE, + 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldType.OE, defaultOrMaker: ClientLibraryOrganization.CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED, valueOf: ClientLibraryOrganization.valueOf, enumValues: ClientLibraryOrganization.values) - ..pc(109, _omitFieldNames ? '' : 'librarySettings', - $pb.PbFieldTypeInternal.PM, + ..pc( + 109, _omitFieldNames ? '' : 'librarySettings', $pb.PbFieldType.PM, subBuilder: ClientLibrarySettings.create) ..aOS(110, _omitFieldNames ? '' : 'protoReferenceDocumentationUri') ..aOS(111, _omitFieldNames ? '' : 'restReferenceDocumentationUri') @@ -568,8 +568,8 @@ class JavaSettings extends $pb.GeneratedMessage { ..m<$core.String, $core.String>( 2, _omitFieldNames ? '' : 'serviceClassNames', entryClassName: 'JavaSettings.ServiceClassNamesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..aOM(3, _omitFieldNames ? '' : 'common', subBuilder: CommonLanguageSettings.create) @@ -1055,14 +1055,14 @@ class DotnetSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'DotnetSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..m<$core.String, $core.String>( 3, _omitFieldNames ? '' : 'renamedResources', entryClassName: 'DotnetSettings.RenamedResourcesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..pPS(4, _omitFieldNames ? '' : 'ignoredResources') ..pPS(5, _omitFieldNames ? '' : 'forcedNamespaceAliases') @@ -1229,8 +1229,8 @@ class GoSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'GoSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..hasRequiredFields = false; @@ -1313,8 +1313,8 @@ class MethodSettings_LongRunning extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM<$0.Duration>(1, _omitFieldNames ? '' : 'initialPollDelay', subBuilder: $0.Duration.create) - ..a<$core.double>(2, _omitFieldNames ? '' : 'pollDelayMultiplier', - $pb.PbFieldTypeInternal.OF) + ..a<$core.double>( + 2, _omitFieldNames ? '' : 'pollDelayMultiplier', $pb.PbFieldType.OF) ..aOM<$0.Duration>(3, _omitFieldNames ? '' : 'maxPollDelay', subBuilder: $0.Duration.create) ..aOM<$0.Duration>(4, _omitFieldNames ? '' : 'totalPollTimeout', @@ -1590,23 +1590,23 @@ class Client { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'methodSignature', 1051, - $pb.PbFieldTypeInternal.PS, - check: $pb.getCheckFunction($pb.PbFieldTypeInternal.PS)); + $pb.PbFieldType.PS, + check: $pb.getCheckFunction($pb.PbFieldType.PS)); static final defaultHost = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'defaultHost', 1049, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final oauthScopes = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'oauthScopes', 1050, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final apiVersion = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'apiVersion', 525000001, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(methodSignature); registry.add(defaultHost); diff --git a/protoc_plugin/lib/src/gen/google/api/http.pb.dart b/protoc_plugin/lib/src/gen/google/api/http.pb.dart index 3aba71831..2fa07e333 100644 --- a/protoc_plugin/lib/src/gen/google/api/http.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/http.pb.dart @@ -44,8 +44,7 @@ class Http extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Http', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldTypeInternal.PM, + ..pc(1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOB(2, _omitFieldNames ? '' : 'fullyDecodeReservedExpansion') ..hasRequiredFields = false; @@ -417,8 +416,8 @@ class HttpRule extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'body') ..aOM(8, _omitFieldNames ? '' : 'custom', subBuilder: CustomHttpPattern.create) - ..pc(11, _omitFieldNames ? '' : 'additionalBindings', - $pb.PbFieldTypeInternal.PM, + ..pc( + 11, _omitFieldNames ? '' : 'additionalBindings', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOS(12, _omitFieldNames ? '' : 'responseBody') ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart index 04374313b..c8c7627e3 100644 --- a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart @@ -398,8 +398,8 @@ class RoutingRule extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'RoutingRule', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc(2, _omitFieldNames ? '' : 'routingParameters', - $pb.PbFieldTypeInternal.PM, + ..pc( + 2, _omitFieldNames ? '' : 'routingParameters', $pb.PbFieldType.PM, subBuilder: RoutingParameter.create) ..hasRequiredFields = false; @@ -562,7 +562,7 @@ class Routing { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'routing', 72295729, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: RoutingRule.getDefault, subBuilder: RoutingRule.create); static void registerAllExtensions($pb.ExtensionRegistry registry) { diff --git a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart index 0c40bcc51..023287aa7 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart @@ -51,12 +51,9 @@ class Version extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'major', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) ..aOS(4, _omitFieldNames ? '' : 'suffix') ..hasRequiredFields = false; @@ -156,12 +153,10 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { ..aOM(3, _omitFieldNames ? '' : 'compilerVersion', subBuilder: Version.create) ..pc<$0.FileDescriptorProto>( - 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create) ..pc<$0.FileDescriptorProto>( - 17, - _omitFieldNames ? '' : 'sourceFileDescriptors', - $pb.PbFieldTypeInternal.PM, + 17, _omitFieldNames ? '' : 'sourceFileDescriptors', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -428,15 +423,15 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'error') - ..a<$fixnum.Int64>(2, _omitFieldNames ? '' : 'supportedFeatures', - $pb.PbFieldTypeInternal.OU6, + ..a<$fixnum.Int64>( + 2, _omitFieldNames ? '' : 'supportedFeatures', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..a<$core.int>( - 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.O3) ..a<$core.int>( - 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.O3) + 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.O3) ..pc( - 15, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: CodeGeneratorResponse_File.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart index 1f945e551..fe6bf4716 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart @@ -47,7 +47,7 @@ class FileDescriptorSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: FileDescriptorProto.create) ..hasExtensions = true; @@ -132,28 +132,27 @@ class FileDescriptorProto extends $pb.GeneratedMessage { ..aOS(2, _omitFieldNames ? '' : 'package') ..pPS(3, _omitFieldNames ? '' : 'dependency') ..pc( - 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 6, _omitFieldNames ? '' : 'service', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'service', $pb.PbFieldType.PM, subBuilder: ServiceDescriptorProto.create) ..pc( - 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FileOptions.create) ..aOM(9, _omitFieldNames ? '' : 'sourceCodeInfo', subBuilder: SourceCodeInfo.create) - ..p<$core.int>(10, _omitFieldNames ? '' : 'publicDependency', - $pb.PbFieldTypeInternal.P3) ..p<$core.int>( - 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldTypeInternal.P3) + 10, _omitFieldNames ? '' : 'publicDependency', $pb.PbFieldType.P3) + ..p<$core.int>( + 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldType.P3) ..aOS(12, _omitFieldNames ? '' : 'syntax') - ..e( - 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -312,9 +311,8 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ExtensionRangeOptions.create); @@ -401,9 +399,8 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -496,31 +493,31 @@ class DescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'field', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'field', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..pc( - 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldTypeInternal.PM, + 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ExtensionRange.create) ..pc( - 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(7, _omitFieldNames ? '' : 'options', subBuilder: MessageOptions.create) ..pc( - 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldTypeInternal.PM, + 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldType.PM, subBuilder: OneofDescriptorProto.create) ..pc( - 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ReservedRange.create) ..pPS(10, _omitFieldNames ? '' : 'reservedName') ..e( - 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -635,8 +632,7 @@ class ExtensionRangeOptions_Declaration extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOS(2, _omitFieldNames ? '' : 'fullName') ..aOS(3, _omitFieldNames ? '' : 'type') ..aOB(5, _omitFieldNames ? '' : 'reserved') @@ -757,17 +753,17 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldType.PM, subBuilder: ExtensionRangeOptions_Declaration.create) ..e( - 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldType.OE, defaultOrMaker: ExtensionRangeOptions_VerificationState.UNVERIFIED, valueOf: ExtensionRangeOptions_VerificationState.valueOf, enumValues: ExtensionRangeOptions_VerificationState.values) ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -876,15 +872,14 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..aOS(2, _omitFieldNames ? '' : 'extendee') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..e( - 4, _omitFieldNames ? '' : 'label', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, valueOf: FieldDescriptorProto_Label.valueOf, enumValues: FieldDescriptorProto_Label.values) ..e( - 5, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Type.TYPE_DOUBLE, valueOf: FieldDescriptorProto_Type.valueOf, enumValues: FieldDescriptorProto_Type.values) @@ -892,8 +887,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'defaultValue') ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FieldOptions.create) - ..a<$core.int>( - 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) ..aOS(10, _omitFieldNames ? '' : 'jsonName') ..aOB(17, _omitFieldNames ? '' : 'proto3Optional'); @@ -1166,9 +1160,8 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -1252,16 +1245,16 @@ class EnumDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'value', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'value', $pb.PbFieldType.PM, subBuilder: EnumValueDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumOptions.create) ..pc( - 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto_EnumReservedRange.create) ..pPS(5, _omitFieldNames ? '' : 'reservedName') ..e( - 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -1362,8 +1355,7 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumValueOptions.create); @@ -1450,7 +1442,7 @@ class ServiceDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'method', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'method', $pb.PbFieldType.PM, subBuilder: MethodDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ServiceOptions.create); @@ -1701,7 +1693,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(1, _omitFieldNames ? '' : 'javaPackage') ..aOS(8, _omitFieldNames ? '' : 'javaOuterClassname') ..e( - 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldTypeInternal.OE, + 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldType.OE, defaultOrMaker: FileOptions_OptimizeMode.SPEED, valueOf: FileOptions_OptimizeMode.valueOf, enumValues: FileOptions_OptimizeMode.values) @@ -1714,7 +1706,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOB(23, _omitFieldNames ? '' : 'deprecated') ..aOB(27, _omitFieldNames ? '' : 'javaStringCheckUtf8') ..a<$core.bool>( - 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldTypeInternal.OB, + 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldType.OB, defaultOrMaker: true) ..aOS(36, _omitFieldNames ? '' : 'objcClassPrefix') ..aOS(37, _omitFieldNames ? '' : 'csharpNamespace') @@ -1725,8 +1717,8 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(45, _omitFieldNames ? '' : 'rubyPackage') ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2059,8 +2051,8 @@ class MessageOptions extends $pb.GeneratedMessage { ..aOB(11, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(12, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2237,8 +2229,7 @@ class FieldOptions_EditionDefault extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(2, _omitFieldNames ? '' : 'value') - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2319,19 +2310,18 @@ class FieldOptions_FeatureSupport extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e(1, _omitFieldNames ? '' : 'editionIntroduced', - $pb.PbFieldTypeInternal.OE, + ..e( + 1, _omitFieldNames ? '' : 'editionIntroduced', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e(2, _omitFieldNames ? '' : 'editionDeprecated', - $pb.PbFieldTypeInternal.OE, + ..e( + 2, _omitFieldNames ? '' : 'editionDeprecated', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..aOS(3, _omitFieldNames ? '' : 'deprecationWarning') - ..e( - 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldTypeInternal.OE, + ..e(4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2460,7 +2450,7 @@ class FieldOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_CType.STRING, valueOf: FieldOptions_CType.valueOf, enumValues: FieldOptions_CType.values) @@ -2468,7 +2458,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(3, _omitFieldNames ? '' : 'deprecated') ..aOB(5, _omitFieldNames ? '' : 'lazy') ..e( - 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_JSType.JS_NORMAL, valueOf: FieldOptions_JSType.valueOf, enumValues: FieldOptions_JSType.values) @@ -2476,25 +2466,25 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(15, _omitFieldNames ? '' : 'unverifiedLazy') ..aOB(16, _omitFieldNames ? '' : 'debugRedact') ..e( - 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldTypeInternal.OE, + 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_OptionRetention.RETENTION_UNKNOWN, valueOf: FieldOptions_OptionRetention.valueOf, enumValues: FieldOptions_OptionRetention.values) ..pc( - 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldTypeInternal.PE, + 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldType.PE, valueOf: FieldOptions_OptionTargetType.valueOf, enumValues: FieldOptions_OptionTargetType.values, defaultEnumValue: FieldOptions_OptionTargetType.TARGET_TYPE_UNKNOWN) - ..pc(20, - _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldTypeInternal.PM, + ..pc( + 20, _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, subBuilder: FieldOptions_EditionDefault.create) ..aOM(21, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..aOM( 22, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2723,8 +2713,8 @@ class OneofOptions extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM(1, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2809,8 +2799,8 @@ class EnumOptions extends $pb.GeneratedMessage { ..aOB(6, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(7, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2937,8 +2927,8 @@ class EnumValueOptions extends $pb.GeneratedMessage { ..aOM( 4, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3051,8 +3041,8 @@ class ServiceOptions extends $pb.GeneratedMessage { ..aOB(33, _omitFieldNames ? '' : 'deprecated') ..aOM(34, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3141,15 +3131,15 @@ class MethodOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOB(33, _omitFieldNames ? '' : 'deprecated') - ..e(34, - _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldTypeInternal.OE, + ..e( + 34, _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, valueOf: MethodOptions_IdempotencyLevel.valueOf, enumValues: MethodOptions_IdempotencyLevel.values) ..aOM(35, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3249,7 +3239,7 @@ class UninterpretedOption_NamePart extends $pb.GeneratedMessage { createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'namePart') ..a<$core.bool>( - 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldTypeInternal.QB); + 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldType.QB); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') UninterpretedOption_NamePart clone() => @@ -3337,17 +3327,17 @@ class UninterpretedOption extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'name', $pb.PbFieldType.PM, subBuilder: UninterpretedOption_NamePart.create) ..aOS(3, _omitFieldNames ? '' : 'identifierValue') - ..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'positiveIntValue', - $pb.PbFieldTypeInternal.OU6, + ..a<$fixnum.Int64>( + 4, _omitFieldNames ? '' : 'positiveIntValue', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aInt64(5, _omitFieldNames ? '' : 'negativeIntValue') ..a<$core.double>( - 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldTypeInternal.OD) + 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldType.OD) ..a<$core.List<$core.int>>( - 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldTypeInternal.OY) + 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldType.OY) ..aOS(8, _omitFieldNames ? '' : 'aggregateValue'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -3524,48 +3514,44 @@ class FeatureSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_FieldPresence.FIELD_PRESENCE_UNKNOWN, valueOf: FeatureSet_FieldPresence.valueOf, enumValues: FeatureSet_FieldPresence.values) ..e( - 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnumType.ENUM_TYPE_UNKNOWN, valueOf: FeatureSet_EnumType.valueOf, enumValues: FeatureSet_EnumType.values) ..e( - 3, - _omitFieldNames ? '' : 'repeatedFieldEncoding', - $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'repeatedFieldEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_RepeatedFieldEncoding.REPEATED_FIELD_ENCODING_UNKNOWN, valueOf: FeatureSet_RepeatedFieldEncoding.valueOf, enumValues: FeatureSet_RepeatedFieldEncoding.values) ..e( - 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN, valueOf: FeatureSet_Utf8Validation.valueOf, enumValues: FeatureSet_Utf8Validation.values) ..e( - 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN, valueOf: FeatureSet_MessageEncoding.valueOf, enumValues: FeatureSet_MessageEncoding.values) ..e( - 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN, valueOf: FeatureSet_JsonFormat.valueOf, enumValues: FeatureSet_JsonFormat.values) - ..e(7, - _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldTypeInternal.OE, + ..e( + 7, _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN, valueOf: FeatureSet_EnforceNamingStyle.valueOf, enumValues: FeatureSet_EnforceNamingStyle.values) ..e( - 8, - _omitFieldNames ? '' : 'defaultSymbolVisibility', - $pb.PbFieldTypeInternal.OE, + 8, _omitFieldNames ? '' : 'defaultSymbolVisibility', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_VisibilityFeature_DefaultSymbolVisibility .DEFAULT_SYMBOL_VISIBILITY_UNKNOWN, valueOf: FeatureSet_VisibilityFeature_DefaultSymbolVisibility.valueOf, @@ -3703,8 +3689,7 @@ class FeatureSetDefaults_FeatureSetEditionDefault extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -3806,15 +3791,13 @@ class FeatureSetDefaults extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldType.PM, subBuilder: FeatureSetDefaults_FeatureSetEditionDefault.create) - ..e( - 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.OE, + ..e(4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e( - 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.OE, + ..e(5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values); @@ -3899,8 +3882,8 @@ class SourceCodeInfo_Location extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) - ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) + ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldType.K3) ..aOS(3, _omitFieldNames ? '' : 'leadingComments') ..aOS(4, _omitFieldNames ? '' : 'trailingComments') ..pPS(6, _omitFieldNames ? '' : 'leadingDetachedComments') @@ -4058,7 +4041,7 @@ class SourceCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'location', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'location', $pb.PbFieldType.PM, subBuilder: SourceCodeInfo_Location.create) ..hasExtensions = true; @@ -4161,13 +4144,12 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) ..aOS(2, _omitFieldNames ? '' : 'sourceFile') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) + ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..e( - 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldType.OE, defaultOrMaker: GeneratedCodeInfo_Annotation_Semantic.NONE, valueOf: GeneratedCodeInfo_Annotation_Semantic.valueOf, enumValues: GeneratedCodeInfo_Annotation_Semantic.values) @@ -4274,7 +4256,7 @@ class GeneratedCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldType.PM, subBuilder: GeneratedCodeInfo_Annotation.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart index dc5428b0b..5cba2308c 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart @@ -105,8 +105,7 @@ class Duration extends $pb.GeneratedMessage with $mixin.DurationMixin { toProto3Json: $mixin.DurationMixin.toProto3JsonHelper, fromProto3Json: $mixin.DurationMixin.fromProto3JsonHelper) ..aInt64(1, _omitFieldNames ? '' : 'seconds') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index 67ea4cef5..af3ec5921 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -181,7 +181,7 @@ class ProtobufField { /// Returns the tag number of the underlying proto field. int get number => descriptor.number; - /// Returns the constant in PbFieldTypeInternal corresponding to this type. + /// Returns the constant in PbFieldType corresponding to this type. String get typeConstant { var prefix = 'O'; if (isRequired) { @@ -191,7 +191,7 @@ class ProtobufField { } else if (isRepeated) { prefix = 'P'; } - return '$protobufImportPrefix.PbFieldTypeInternal.$prefix${baseType.typeConstantSuffix}'; + return '$protobufImportPrefix.PbFieldType.$prefix${baseType.typeConstantSuffix}'; } static String _formatArguments( @@ -260,7 +260,7 @@ class ProtobufField { 'const $protobufImportPrefix.PackageName(\'$package\')'; } } else if (isRepeated) { - if (typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.PS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.PS') { invocation = 'pPS'; } else { args.add(typeConstant); @@ -291,11 +291,9 @@ class ProtobufField { } else if (makeDefault == null) { switch (type) { case '$coreImportPrefix.String': - if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OS') { invocation = 'aOS'; - } else if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.QS') { + } else if (typeConstant == '$protobufImportPrefix.PbFieldType.QS') { invocation = 'aQS'; } else { invocation = 'a<$type>'; @@ -303,8 +301,7 @@ class ProtobufField { } break; case '$coreImportPrefix.bool': - if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OB') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OB') { invocation = 'aOB'; } else { invocation = 'a<$type>'; @@ -319,7 +316,7 @@ class ProtobufField { } else { if (makeDefault == '$fixnumImportPrefix.Int64.ZERO' && type == '$fixnumImportPrefix.Int64' && - typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.O6') { + typeConstant == '$protobufImportPrefix.PbFieldType.O6') { invocation = 'aInt64'; } else { if (baseType.isMessage || baseType.isGroup) { diff --git a/protoc_plugin/test/goldens/extension.pb.dart b/protoc_plugin/test/goldens/extension.pb.dart index 1da48e7fc..32a5dcb75 100644 --- a/protoc_plugin/test/goldens/extension.pb.dart +++ b/protoc_plugin/test/goldens/extension.pb.dart @@ -1,4 +1,4 @@ -static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldTypeInternal.OS); +static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldType.OS); const $core.bool _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const $core.bool _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart b/protoc_plugin/test/goldens/messageGenerator.pb.dart index 7c285d54f..15d05a340 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart @@ -8,8 +8,8 @@ class PhoneNumber extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) - ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, defaultOrMaker: '\$') + ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$') ..aOS(4, _omitFieldNames ? '' : 'deprecatedField') ; diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta index a5992239b..faefae9b1 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1870 - end: 1876 + begin: 1854 + end: 1860 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1918 - end: 1924 + begin: 1902 + end: 1908 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2004 - end: 2013 + begin: 1988 + end: 1997 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2056 - end: 2067 + begin: 2040 + end: 2051 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2139 - end: 2143 + begin: 2123 + end: 2127 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2184 - end: 2188 + begin: 2168 + end: 2172 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2276 - end: 2283 + begin: 2260 + end: 2267 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2326 - end: 2335 + begin: 2310 + end: 2319 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2398 - end: 2402 + begin: 2382 + end: 2386 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2449 - end: 2453 + begin: 2433 + end: 2437 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2533 - end: 2540 + begin: 2517 + end: 2524 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2583 - end: 2592 + begin: 2567 + end: 2576 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2704 - end: 2719 + begin: 2688 + end: 2703 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2810 - end: 2825 + begin: 2794 + end: 2809 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2954 - end: 2972 + begin: 2938 + end: 2956 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3064 - end: 3084 + begin: 3048 + end: 3068 } diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart b/protoc_plugin/test/goldens/oneMessage.pb.dart index d408d4521..e38712f82 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart @@ -32,9 +32,8 @@ class PhoneNumber extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.O3) - ..a<$core.String>( - 3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, + ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.O3) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta index 6fdc950eb..44ec15bfc 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2234 - end: 2240 + begin: 2218 + end: 2224 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2282 - end: 2288 + begin: 2266 + end: 2272 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2368 - end: 2377 + begin: 2352 + end: 2361 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2420 - end: 2431 + begin: 2404 + end: 2415 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2491 - end: 2495 + begin: 2475 + end: 2479 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2537 - end: 2541 + begin: 2521 + end: 2525 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2623 - end: 2630 + begin: 2607 + end: 2614 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2673 - end: 2682 + begin: 2657 + end: 2666 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2745 - end: 2749 + begin: 2729 + end: 2733 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2796 - end: 2800 + begin: 2780 + end: 2784 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2880 - end: 2887 + begin: 2864 + end: 2871 } annotation: { path: 4 @@ -117,6 +117,6 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2930 - end: 2939 + begin: 2914 + end: 2923 } From a187a9d3c88b3410470b9a47876da569d414838e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:39:26 +0100 Subject: [PATCH 17/22] Revert renaming --- protobuf/lib/src/protobuf/builder_info.dart | 31 ++- protobuf/lib/src/protobuf/coded_buffer.dart | 77 ++++--- .../lib/src/protobuf/coded_buffer_writer.dart | 46 ++-- .../lib/src/protobuf/extension_registry.dart | 2 +- protobuf/lib/src/protobuf/field_error.dart | 74 +++--- protobuf/lib/src/protobuf/field_info.dart | 32 +-- protobuf/lib/src/protobuf/field_set.dart | 8 +- protobuf/lib/src/protobuf/field_type.dart | 16 +- .../lib/src/protobuf/generated_message.dart | 2 +- protobuf/lib/src/protobuf/json/json.dart | 80 +++---- protobuf/lib/src/protobuf/json/json_web.dart | 80 +++---- protobuf/lib/src/protobuf/pb_map.dart | 2 +- protobuf/lib/src/protobuf/proto3_json.dart | 134 +++++------ .../lib/src/protobuf/unknown_field_set.dart | 10 +- protobuf/lib/src/protobuf/wire_format.dart | 38 ++-- protobuf/test/codec_test.dart | 23 +- protobuf/test/list_test.dart | 12 +- protobuf/test/mock_util.dart | 20 +- protobuf/test/readonly_message_test.dart | 12 +- protoc_plugin/lib/src/base_type.dart | 2 +- .../lib/src/gen/dart_options.pb.dart | 19 +- .../lib/src/gen/google/api/client.pb.dart | 42 ++-- .../lib/src/gen/google/api/http.pb.dart | 7 +- .../lib/src/gen/google/api/routing.pb.dart | 6 +- .../google/protobuf/compiler/plugin.pb.dart | 25 +-- .../gen/google/protobuf/descriptor.pb.dart | 210 ++++++++---------- .../src/gen/google/protobuf/duration.pb.dart | 3 +- protoc_plugin/lib/src/protobuf_field.dart | 17 +- protoc_plugin/test/goldens/extension.pb.dart | 2 +- .../test/goldens/messageGenerator.pb.dart | 4 +- .../goldens/messageGenerator.pb.dart.meta | 64 +++--- protoc_plugin/test/goldens/oneMessage.pb.dart | 5 +- .../test/goldens/oneMessage.pb.dart.meta | 48 ++-- 33 files changed, 551 insertions(+), 602 deletions(-) diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index c236e58fa..d21b3dfa1 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -105,7 +105,7 @@ class BuilderInfo { name, tagNumber, index, - PbFieldTypeInternal.M, + PbFieldType.M, keyFieldType, valueFieldType, mapEntryBuilderInfo, @@ -179,13 +179,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.OS String with no default value to reduce generated + /// Adds PbFieldType.OS String with no default value to reduce generated /// code size. void aOS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.OS, + PbFieldType.OS, null, null, null, @@ -194,13 +194,13 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.PS String with no default value. + /// Adds PbFieldType.PS String with no default value. void pPS(int tagNumber, String name, {String? protoName}) { addRepeated( tagNumber, name, - PbFieldTypeInternal.PS, - getCheckFunction(PbFieldTypeInternal.PS), + PbFieldType.PS, + getCheckFunction(PbFieldType.PS), null, null, null, @@ -208,12 +208,12 @@ class BuilderInfo { ); } - /// Adds PbFieldTypeInternal.QS String with no default value. + /// Adds PbFieldType.QS String with no default value. void aQS(int tagNumber, String name, {String? protoName}) { add( tagNumber, name, - PbFieldTypeInternal.QS, + PbFieldType.QS, null, null, null, @@ -227,7 +227,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.O6, + PbFieldType.O6, Int64.ZERO, null, null, @@ -241,7 +241,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OB, + PbFieldType.OB, null, null, null, @@ -275,8 +275,8 @@ class BuilderInfo { // Repeated, not a message, group, or enum. void p(int tagNumber, String name, int fieldType, {String? protoName}) { assert( - !PbFieldTypeInternal.isGroupOrMessage(fieldType) && - !PbFieldTypeInternal.isEnum(fieldType), + !PbFieldType.isGroupOrMessage(fieldType) && + !PbFieldType.isEnum(fieldType), ); addRepeated( tagNumber, @@ -302,8 +302,7 @@ class BuilderInfo { String? protoName, }) { assert( - PbFieldTypeInternal.isGroupOrMessage(fieldType) || - PbFieldTypeInternal.isEnum(fieldType), + PbFieldType.isGroupOrMessage(fieldType) || PbFieldType.isEnum(fieldType), ); addRepeated( tagNumber, @@ -327,7 +326,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.OM, + PbFieldType.OM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, @@ -345,7 +344,7 @@ class BuilderInfo { add( tagNumber, name, - PbFieldTypeInternal.QM, + PbFieldType.QM, GeneratedMessage._defaultMakerFor(subBuilder), subBuilder, null, diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index c1cc0dbb6..0150e1b51 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -54,25 +54,24 @@ void _mergeFromCodedBufferReader( // Ignore required/optional packed/unpacked. var fieldType = fi.type; - fieldType &= - ~(PbFieldTypeInternal.PACKED_BIT | PbFieldTypeInternal.REQUIRED_BIT); + fieldType &= ~(PbFieldType.PACKED_BIT | PbFieldType.REQUIRED_BIT); switch (fieldType) { - case PbFieldTypeInternal.OPTIONAL_BOOL: + case PbFieldType.OPTIONAL_BOOL: fs._setFieldUnchecked(meta, fi, input.readBool()); break; - case PbFieldTypeInternal.OPTIONAL_BYTES: + case PbFieldType.OPTIONAL_BYTES: fs._setFieldUnchecked(meta, fi, input.readBytes()); break; - case PbFieldTypeInternal.OPTIONAL_STRING: + case PbFieldType.OPTIONAL_STRING: fs._setFieldUnchecked(meta, fi, input.readString()); break; - case PbFieldTypeInternal.OPTIONAL_FLOAT: + case PbFieldType.OPTIONAL_FLOAT: fs._setFieldUnchecked(meta, fi, input.readFloat()); break; - case PbFieldTypeInternal.OPTIONAL_DOUBLE: + case PbFieldType.OPTIONAL_DOUBLE: fs._setFieldUnchecked(meta, fi, input.readDouble()); break; - case PbFieldTypeInternal.OPTIONAL_ENUM: + case PbFieldType.OPTIONAL_ENUM: final rawValue = input.readEnum(); final value = meta._decodeEnum(tagNumber, registry, rawValue); if (value == null) { @@ -82,7 +81,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, value); } break; - case PbFieldTypeInternal.OPTIONAL_GROUP: + case PbFieldType.OPTIONAL_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); final oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { @@ -91,37 +90,37 @@ void _mergeFromCodedBufferReader( input.readGroup(tagNumber, subMessage, registry); fs._setFieldUnchecked(meta, fi, subMessage); break; - case PbFieldTypeInternal.OPTIONAL_INT32: + case PbFieldType.OPTIONAL_INT32: fs._setFieldUnchecked(meta, fi, input.readInt32()); break; - case PbFieldTypeInternal.OPTIONAL_INT64: + case PbFieldType.OPTIONAL_INT64: fs._setFieldUnchecked(meta, fi, input.readInt64()); break; - case PbFieldTypeInternal.OPTIONAL_SINT32: + case PbFieldType.OPTIONAL_SINT32: fs._setFieldUnchecked(meta, fi, input.readSint32()); break; - case PbFieldTypeInternal.OPTIONAL_SINT64: + case PbFieldType.OPTIONAL_SINT64: fs._setFieldUnchecked(meta, fi, input.readSint64()); break; - case PbFieldTypeInternal.OPTIONAL_UINT32: + case PbFieldType.OPTIONAL_UINT32: fs._setFieldUnchecked(meta, fi, input.readUint32()); break; - case PbFieldTypeInternal.OPTIONAL_UINT64: + case PbFieldType.OPTIONAL_UINT64: fs._setFieldUnchecked(meta, fi, input.readUint64()); break; - case PbFieldTypeInternal.OPTIONAL_FIXED32: + case PbFieldType.OPTIONAL_FIXED32: fs._setFieldUnchecked(meta, fi, input.readFixed32()); break; - case PbFieldTypeInternal.OPTIONAL_FIXED64: + case PbFieldType.OPTIONAL_FIXED64: fs._setFieldUnchecked(meta, fi, input.readFixed64()); break; - case PbFieldTypeInternal.OPTIONAL_SFIXED32: + case PbFieldType.OPTIONAL_SFIXED32: fs._setFieldUnchecked(meta, fi, input.readSfixed32()); break; - case PbFieldTypeInternal.OPTIONAL_SFIXED64: + case PbFieldType.OPTIONAL_SFIXED64: fs._setFieldUnchecked(meta, fi, input.readSfixed64()); break; - case PbFieldTypeInternal.OPTIONAL_MESSAGE: + case PbFieldType.OPTIONAL_MESSAGE: final GeneratedMessage? oldValue = fs._getFieldOrNull(fi); if (oldValue != null) { input.readMessage(oldValue, registry); @@ -131,7 +130,7 @@ void _mergeFromCodedBufferReader( fs._setFieldUnchecked(meta, fi, subMessage); } break; - case PbFieldTypeInternal.REPEATED_BOOL: + case PbFieldType.REPEATED_BOOL: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -151,17 +150,17 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readBool()); } break; - case PbFieldTypeInternal.REPEATED_BYTES: + case PbFieldType.REPEATED_BYTES: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readBytes()); break; - case PbFieldTypeInternal.REPEATED_STRING: + case PbFieldType.REPEATED_STRING: final list = fs._ensureRepeatedField(meta, fi); list._checkModifiable('add'); list._addUnchecked(input.readString()); break; - case PbFieldTypeInternal.REPEATED_FLOAT: + case PbFieldType.REPEATED_FLOAT: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -178,7 +177,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFloat()); } break; - case PbFieldTypeInternal.REPEATED_DOUBLE: + case PbFieldType.REPEATED_DOUBLE: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -195,7 +194,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readDouble()); } break; - case PbFieldTypeInternal.REPEATED_ENUM: + case PbFieldType.REPEATED_ENUM: final list = fs._ensureRepeatedField(meta, fi); _readPackableToListEnum( list, @@ -207,13 +206,13 @@ void _mergeFromCodedBufferReader( registry, ); break; - case PbFieldTypeInternal.REPEATED_GROUP: + case PbFieldType.REPEATED_GROUP: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readGroup(tagNumber, subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal.REPEATED_INT32: + case PbFieldType.REPEATED_INT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -230,7 +229,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt32()); } break; - case PbFieldTypeInternal.REPEATED_INT64: + case PbFieldType.REPEATED_INT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -247,7 +246,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readInt64()); } break; - case PbFieldTypeInternal.REPEATED_SINT32: + case PbFieldType.REPEATED_SINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -264,7 +263,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint32()); } break; - case PbFieldTypeInternal.REPEATED_SINT64: + case PbFieldType.REPEATED_SINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -281,7 +280,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSint64()); } break; - case PbFieldTypeInternal.REPEATED_UINT32: + case PbFieldType.REPEATED_UINT32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -298,7 +297,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint32()); } break; - case PbFieldTypeInternal.REPEATED_UINT64: + case PbFieldType.REPEATED_UINT64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -315,7 +314,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readUint64()); } break; - case PbFieldTypeInternal.REPEATED_FIXED32: + case PbFieldType.REPEATED_FIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -332,7 +331,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed32()); } break; - case PbFieldTypeInternal.REPEATED_FIXED64: + case PbFieldType.REPEATED_FIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -349,7 +348,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readFixed64()); } break; - case PbFieldTypeInternal.REPEATED_SFIXED32: + case PbFieldType.REPEATED_SFIXED32: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -366,7 +365,7 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed32()); } break; - case PbFieldTypeInternal.REPEATED_SFIXED64: + case PbFieldType.REPEATED_SFIXED64: final list = fs._ensureRepeatedField(meta, fi); if (wireType == WIRETYPE_LENGTH_DELIMITED) { final limit = input.readInt32(); @@ -383,13 +382,13 @@ void _mergeFromCodedBufferReader( list._addUnchecked(input.readSfixed64()); } break; - case PbFieldTypeInternal.REPEATED_MESSAGE: + case PbFieldType.REPEATED_MESSAGE: final subMessage = meta._makeEmptyMessage(tagNumber, registry); input.readMessage(subMessage, registry); final list = fs._ensureRepeatedField(meta, fi); list.add(subMessage); break; - case PbFieldTypeInternal.MAP: + case PbFieldType.MAP: final mapFieldInfo = fi as MapFieldInfo; final mapEntryMeta = mapFieldInfo.mapEntryBuilderInfo; fs diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index f3f483af1..8809ce297 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -65,9 +65,9 @@ class CodedBufferWriter { } void writeField(int fieldNumber, int fieldType, Object? fieldValue) { - final valueType = PbFieldTypeInternal.baseType(fieldType); + final valueType = PbFieldType.baseType(fieldType); - if ((fieldType & PbFieldTypeInternal.PACKED_BIT) != 0) { + if ((fieldType & PbFieldType.PACKED_BIT) != 0) { final list = fieldValue as List; if (list.isNotEmpty) { _writeTag(fieldNumber, WIRETYPE_LENGTH_DELIMITED); @@ -80,7 +80,7 @@ class CodedBufferWriter { return; } - if ((fieldType & PbFieldTypeInternal.MAP_BIT) != 0) { + if ((fieldType & PbFieldType.MAP_BIT) != 0) { final map = fieldValue as PbMap; final keyWireFormat = _wireTypes[_valueTypeIndex(map.keyFieldType)]; final valueWireFormat = _wireTypes[_valueTypeIndex(map.valueFieldType)]; @@ -107,7 +107,7 @@ class CodedBufferWriter { final wireFormat = _wireTypes[_valueTypeIndex(valueType)]; - if ((fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0) { + if ((fieldType & PbFieldType.REPEATED_BIT) != 0) { final list = fieldValue as List; for (var i = 0; i < list.length; i++) { _writeValue(fieldNumber, valueType, list[i], wireFormat); @@ -353,10 +353,10 @@ class CodedBufferWriter { void _writeValueAs(int valueType, dynamic value) { switch (valueType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: _writeVarint32(value ? 1 : 0); break; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: final List bytes = value; if (bytes is Uint8List) { _writeBytesNoTag(bytes); @@ -366,7 +366,7 @@ class CodedBufferWriter { _writeBytesNoTag(Uint8List.fromList(bytes)); } break; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: final String string = value; if (string.isEmpty) { _writeEmptyBytes(); @@ -374,17 +374,17 @@ class CodedBufferWriter { _writeBytesNoTag(const Utf8Encoder().convert(string)); } break; - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.DOUBLE_BIT: _writeDouble(value); break; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: _writeFloat(value); break; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: final ProtobufEnum enum_ = value; _writeVarint32(enum_.value & 0xffffffff); break; - case PbFieldTypeInternal.GROUP_BIT: + case PbFieldType.GROUP_BIT: // `value` is `UnknownFieldSet` or `GeneratedMessage`. Test for // `UnknownFieldSet` as it doesn't have subtypes, so the type test will // be fast. @@ -399,37 +399,37 @@ class CodedBufferWriter { message.writeToCodedBufferWriter(this); } break; - case PbFieldTypeInternal.INT32_BIT: + case PbFieldType.INT32_BIT: _writeVarint64(Int64(value)); break; - case PbFieldTypeInternal.INT64_BIT: + case PbFieldType.INT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal.SINT32_BIT: + case PbFieldType.SINT32_BIT: _writeVarint32(_encodeZigZag32(value)); break; - case PbFieldTypeInternal.SINT64_BIT: + case PbFieldType.SINT64_BIT: _writeVarint64(_encodeZigZag64(value)); break; - case PbFieldTypeInternal.UINT32_BIT: + case PbFieldType.UINT32_BIT: _writeVarint32(value); break; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: _writeVarint64(value); break; - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.FIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.FIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.SFIXED32_BIT: _writeInt32(value); break; - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.SFIXED64_BIT: _writeInt64(value); break; - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.MESSAGE_BIT: final mark = _startLengthDelimited(); final GeneratedMessage msg = value; msg.writeToCodedBufferWriter(this); @@ -459,7 +459,7 @@ class CodedBufferWriter { ) { _writeTag(fieldNumber, wireFormat); _writeValueAs(valueType, value); - if (valueType == PbFieldTypeInternal.GROUP_BIT) { + if (valueType == PbFieldType.GROUP_BIT) { _writeTag(fieldNumber, WIRETYPE_END_GROUP); } } diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index 16cb448a1..f7de71afc 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart @@ -181,7 +181,7 @@ T _reparseMessage( final messageMapDynamic = message._fieldSet._values[field.index!]; if (messageMapDynamic == null) continue; final PbMap messageMap = messageMapDynamic; - if (PbFieldTypeInternal.isGroupOrMessage(field.valueFieldType)) { + if (PbFieldType.isGroupOrMessage(field.valueFieldType)) { for (final key in messageMap.keys) { final GeneratedMessage value = messageMap[key]; final reparsedValue = _reparseMessage(value, extensionRegistry); diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index d8a04ad9c..0381cc75c 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -10,53 +10,53 @@ part of 'internal.dart'; /// For enums, group, and message fields, this check is only approximate, /// because the exact type isn't included in [fieldType]. String? _getFieldError(int fieldType, var value) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is! bool) return 'not type bool'; return null; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is! List) return 'not List'; return null; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is! String) return 'not type String'; return null; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: if (value is! double) return 'not type double'; if (!_isFloat32(value)) return 'out of range for float'; return null; - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.DOUBLE_BIT: if (value is! double) return 'not type double'; return null; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: if (value is! ProtobufEnum) return 'not type ProtobufEnum'; return null; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: if (value is! int) return 'not type int'; if (!_isSigned32(value)) return 'out of range for signed 32-bit int'; return null; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: if (value is! int) return 'not type int'; if (!_isUnsigned32(value)) return 'out of range for unsigned 32-bit int'; return null; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 if (value is! Int64) return 'not Int64'; return null; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: if (value is! GeneratedMessage) return 'not a GeneratedMessage'; return null; default: @@ -74,33 +74,33 @@ String? _getFieldError(int fieldType, var value) { /// @nodoc CheckFunc getCheckFunction(int fieldType) { switch (fieldType & ~0x7) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.BYTES_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: - case PbFieldTypeInternal.ENUM_BIT: - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.BOOL_BIT: + case PbFieldType.BYTES_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.DOUBLE_BIT: + case PbFieldType.ENUM_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: // We always use the full range of the same Dart type. // It's up to the caller to treat the Int64 as signed or unsigned. // See: https://github.com/google/protobuf.dart/issues/44 return _checkNotNull; - case PbFieldTypeInternal.FLOAT_BIT: + case PbFieldType.FLOAT_BIT: return _checkFloat; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: return _checkSigned32; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: return _checkUnsigned32; } throw ArgumentError('check function not implemented: $fieldType'); diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index fed7d8d38..dbdd7d0ee 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -65,7 +65,7 @@ class FieldInfo { /// The value is `null` for extension fields. final int? index; - /// Type of this field. See [PbFieldTypeInternal]. + /// Type of this field. See [PbFieldType]. final int type; /// Constructs the default value of a field. @@ -114,11 +114,11 @@ class FieldInfo { _protoName = protoName, assert(type != 0), assert( - !PbFieldTypeInternal.isGroupOrMessage(type) || + !PbFieldType.isGroupOrMessage(type) || subBuilder != null || - PbFieldTypeInternal.isMapField(type), + PbFieldType.isMapField(type), ), - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(!PbFieldType.isEnum(type) || valueOf != null); // Represents a field that has been removed by a program transformation. FieldInfo.dummy(this.index) @@ -146,11 +146,11 @@ class FieldInfo { String? protoName, }) : makeDefault = (() => PbList(check: check)), _protoName = protoName, - assert(PbFieldTypeInternal.isRepeated(type)), - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(PbFieldType.isRepeated(type)), + assert(!PbFieldType.isEnum(type) || valueOf != null); static MakeDefaultFunc? findMakeDefault(int type, dynamic defaultOrMaker) { - if (defaultOrMaker == null) return PbFieldTypeInternal.defaultForType(type); + if (defaultOrMaker == null) return PbFieldType.defaultForType(type); if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; return () => defaultOrMaker; } @@ -159,11 +159,11 @@ class FieldInfo { /// been removed by a program transformation. bool get _isDummy => tagNumber == 0; - bool get isRequired => PbFieldTypeInternal.isRequired(type); - bool get isRepeated => PbFieldTypeInternal.isRepeated(type); - bool get isGroupOrMessage => PbFieldTypeInternal.isGroupOrMessage(type); - bool get isEnum => PbFieldTypeInternal.isEnum(type); - bool get isMapField => PbFieldTypeInternal.isMapField(type); + bool get isRequired => PbFieldType.isRequired(type); + bool get isRepeated => PbFieldType.isRepeated(type); + bool get isGroupOrMessage => PbFieldType.isGroupOrMessage(type); + bool get isEnum => PbFieldType.isEnum(type); + bool get isMapField => PbFieldType.isMapField(type); /// Returns a read-only default value for a field. Unlike /// [GeneratedMessage.getField], doesn't create a repeated field. @@ -178,7 +178,7 @@ class FieldInfo { /// That is, it doesn't contain any required fields that aren't initialized. bool _hasRequiredValues(dynamic value) { if (value == null) return !isRequired; // missing is okay if optional - if (!PbFieldTypeInternal.isGroupOrMessage(type)) { + if (!PbFieldType.isGroupOrMessage(type)) { return true; // primitive and present } @@ -203,7 +203,7 @@ class FieldInfo { void _appendInvalidFields(List problems, value, String prefix) { if (value == null) { if (isRequired) problems.add('$prefix$name'); - } else if (!PbFieldTypeInternal.isGroupOrMessage(type)) { + } else if (!PbFieldType.isGroupOrMessage(type)) { // primitive and present } else if (!isRepeated) { // Required message/group: recurse. @@ -297,7 +297,7 @@ class MapFieldInfo extends FieldInfo?> { this.valueCreator, { ProtobufEnum? defaultEnumValue, String? protoName, - }) : assert(PbFieldTypeInternal.isMapField(type)), + }) : assert(PbFieldType.isMapField(type)), super( name, tagNumber, @@ -307,7 +307,7 @@ class MapFieldInfo extends FieldInfo?> { defaultEnumValue: defaultEnumValue, protoName: protoName, ) { - assert(!PbFieldTypeInternal.isEnum(type) || valueOf != null); + assert(!PbFieldType.isEnum(type) || valueOf != null); } FieldInfo get valueFieldInfo => diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index f7c260883..980c03c61 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -626,11 +626,11 @@ class FieldSet { } hash = HashUtils.combine(hash, fi.tagNumber); - if (PbFieldTypeInternal.isBytes(fi.type)) { + if (PbFieldType.isBytes(fi.type)) { // Bytes are represented as a List (Usually with byte-data). // We special case that to match our equality semantics. hash = HashUtils.combine(hash, HashUtils.hashObjects(value)); - } else if (!PbFieldTypeInternal.isEnum(fi.type)) { + } else if (!PbFieldType.isEnum(fi.type)) { hash = HashUtils.combine(hash, value.hashCode); } else if (fi.isRepeated) { final PbList list = value; @@ -772,7 +772,7 @@ class FieldSet { final MapFieldInfo f = fi as dynamic; final PbMap map = f._ensureMapField(meta, this) as dynamic; - if (PbFieldTypeInternal.isGroupOrMessage(f.valueFieldType)) { + if (PbFieldType.isGroupOrMessage(f.valueFieldType)) { final PbMap fieldValueMap = fieldValue; for (final entry in fieldValueMap.entries) { map[entry.key] = entry.value.deepCopy(); @@ -784,7 +784,7 @@ class FieldSet { } if (fi.isRepeated) { - if (PbFieldTypeInternal.isGroupOrMessage(otherFi.type)) { + if (PbFieldType.isGroupOrMessage(otherFi.type)) { // fieldValue must be a PbList of GeneratedMessage. final PbList pbList = fieldValue; final repeatedFields = fi._ensureRepeatedField(meta, this); diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index a3e6cb4ae..67b3194e8 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -6,26 +6,24 @@ part of 'internal.dart'; /// Defines constants and functions for dealing with fieldType bits. -class PbFieldTypeInternal { +class PbFieldType { static bool isRepeated(int fieldType) => - (fieldType & PbFieldTypeInternal.REPEATED_BIT) != 0; + (fieldType & PbFieldType.REPEATED_BIT) != 0; static bool isRequired(int fieldType) => - (fieldType & PbFieldTypeInternal.REQUIRED_BIT) != 0; + (fieldType & PbFieldType.REQUIRED_BIT) != 0; static bool isEnum(int fieldType) => - PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.ENUM_BIT; + PbFieldType.baseType(fieldType) == PbFieldType.ENUM_BIT; static bool isBytes(int fieldType) => - PbFieldTypeInternal.baseType(fieldType) == PbFieldTypeInternal.BYTES_BIT; + PbFieldType.baseType(fieldType) == PbFieldType.BYTES_BIT; static bool isGroupOrMessage(int fieldType) => - (fieldType & - (PbFieldTypeInternal.GROUP_BIT | PbFieldTypeInternal.MESSAGE_BIT)) != - 0; + (fieldType & (PbFieldType.GROUP_BIT | PbFieldType.MESSAGE_BIT)) != 0; static bool isMapField(int fieldType) => - (fieldType & PbFieldTypeInternal.MAP_BIT) != 0; + (fieldType & PbFieldType.MAP_BIT) != 0; /// Returns the base field type without any of the required, repeated /// and packed bits. diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 7c8073281..9b5c866a4 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -408,7 +408,7 @@ abstract class GeneratedMessage { /// Sets the value of a non-repeated extension field to [value]. void setExtension(Extension extension, Object value) { - if (PbFieldTypeInternal.isRepeated(extension.type)) { + if (PbFieldType.isRepeated(extension.type)) { throw ArgumentError( _fieldSet._setFieldFailedMessage( extension, diff --git a/protobuf/lib/src/protobuf/json/json.dart b/protobuf/lib/src/protobuf/json/json.dart index d32e336c5..f9bc916e7 100644 --- a/protobuf/lib/src/protobuf/json/json.dart +++ b/protobuf/lib/src/protobuf/json/json.dart @@ -14,24 +14,24 @@ export 'json_vm.dart' if (dart.library.js_interop) 'json_web.dart'; Map writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { - final baseType = PbFieldTypeInternal.baseType(fieldType); + final baseType = PbFieldType.baseType(fieldType); - if (PbFieldTypeInternal.isRepeated(fieldType)) { + if (PbFieldType.isRepeated(fieldType)) { final PbList list = fieldValue; return List.from(list.map((e) => convertToMap(e, baseType))); } switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.BOOL_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: final value = fieldValue as double; if (value.isNaN) { return nan; @@ -43,22 +43,22 @@ Map writeToJsonMap(FieldSet fs) { return fieldValue.toInt(); } return value; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: // Encode 'bytes' as a base64-encoded string. return base64Encode(fieldValue as List); - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value; // assume |value| < 2^52 - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned(); - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: @@ -81,7 +81,7 @@ Map writeToJsonMap(FieldSet fs) { if (value == null || (value is List && value.isEmpty)) { continue; // It's missing, repeated, or an empty byte array. } - if (PbFieldTypeInternal.isMapField(fi.type)) { + if (PbFieldType.isMapField(fi.type)) { result['${fi.tagNumber}'] = writeMap( value, fi as MapFieldInfo, @@ -254,8 +254,8 @@ dynamic _convertJsonValue( ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is bool) { return value; } else if (value is String) { @@ -273,20 +273,20 @@ dynamic _convertJsonValue( } expectedType = 'bool (true, false, "true", "false", 1, 0)'; break; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is String) { return base64Decode(value); } expectedType = 'Base64 String'; break; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is String) { return value; } expectedType = 'String'; break; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value is double) { return value; @@ -297,7 +297,7 @@ dynamic _convertJsonValue( } expectedType = 'num or stringified num'; break; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: // Allow quoted values, although we don't emit them. if (value is String) { value = int.parse(value); @@ -310,15 +310,15 @@ dynamic _convertJsonValue( } expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: if (value is int) return value; if (value is String) return int.parse(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: int? validatedValue; if (value is int) validatedValue = value; if (value is String) validatedValue = int.parse(value); @@ -328,17 +328,17 @@ dynamic _convertJsonValue( if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) return Int64.parseInt(value); expectedType = 'int or stringified int'; break; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: if (value is Map) { final messageValue = value as Map; final subMessage = meta.makeEmptyMessage(tagNumber, registry); diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index eeb74ec47..6b8e1e80f 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -47,9 +47,9 @@ String writeToJsonString(FieldSet fs) { JSObject _writeToRawJs(FieldSet fs) { JSAny convertToRawJs(dynamic fieldValue, int fieldType) { - final baseType = PbFieldTypeInternal.baseType(fieldType); + final baseType = PbFieldType.baseType(fieldType); - if (PbFieldTypeInternal.isRepeated(fieldType)) { + if (PbFieldType.isRepeated(fieldType)) { final PbList list = fieldValue; final length = list.length; final jsArray = JSArray.withLength(length); @@ -61,24 +61,24 @@ JSObject _writeToRawJs(FieldSet fs) { } switch (baseType) { - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: final int value = fieldValue; return value.toJS; - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: final bool value = fieldValue; return value.toJS; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: final String value = fieldValue; return value.toJS; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return nan.toJS; @@ -91,28 +91,28 @@ JSObject _writeToRawJs(FieldSet fs) { } return value.toJS; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: // Encode 'bytes' as a base64-encoded string. final List value = fieldValue; return base64Encode(value).toJS; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: final ProtobufEnum enum_ = fieldValue; return enum_.value.toJS; // assume |value| < 2^52 - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: final Int64 int_ = fieldValue; return int_.toString().toJS; - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: final Int64 int_ = fieldValue; return int_.toStringUnsigned().toJS; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: final GeneratedMessage msg = fieldValue; return _writeToRawJs(msg.fieldSet); @@ -147,7 +147,7 @@ JSObject _writeToRawJs(FieldSet fs) { if (value == null || (value is List && value.isEmpty)) { continue; // It's missing, repeated, or an empty byte array. } - if (PbFieldTypeInternal.isMapField(fi.type)) { + if (PbFieldType.isMapField(fi.type)) { result.setProperty( fi.tagNumber.toJS, writeMap(value, fi as MapFieldInfo), @@ -350,8 +350,8 @@ Object? _convertRawJsValue( ExtensionRegistry? registry, ) { String expectedType; // for exception message - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value.isA()) { return value.as().toDart; } else if (value.isA()) { @@ -370,18 +370,18 @@ Object? _convertRawJsValue( } } expectedType = 'bool (true, false, "true", "false", 1, 0)'; - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value.isA()) { return base64Decode(value.as().toDart); } expectedType = 'Base64 String'; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value.isA()) { return value.as().toDart; } expectedType = 'String'; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value.isA()) { final jsNum = value.as(); @@ -390,7 +390,7 @@ Object? _convertRawJsValue( return double.parse(value.as().toDart); } expectedType = 'num or stringified num'; - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: // Allow quoted values, although we don't emit them. if (value.isA()) { value = int.parse(value.as().toDart).toJS; @@ -406,9 +406,9 @@ Object? _convertRawJsValue( ); } expectedType = 'int or stringified int'; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: if (Number.isInteger(value)) { return value.as().toDartInt; } @@ -416,8 +416,8 @@ Object? _convertRawJsValue( return int.parse(value.as().toDart); } expectedType = 'int or stringified int'; - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: int? validatedValue; if (Number.isInteger(value)) { validatedValue = value.as().toDartInt; @@ -430,11 +430,11 @@ Object? _convertRawJsValue( } if (validatedValue != null) return validatedValue; expectedType = 'int or stringified int'; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: if (Number.isInteger(value)) { return Int64(value.as().toDartInt); } @@ -442,8 +442,8 @@ Object? _convertRawJsValue( return Int64.parseInt(value.as().toDart); } expectedType = 'int or stringified int'; - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: if (getPrototypeOf(value).strictEquals(objectPrototype).toDart) { final subMessage = meta.makeEmptyMessage(tagNumber, registry); _mergeFromRawJsMap(subMessage.fieldSet, value.as(), registry); diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 0d929091a..2816eb69f 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -124,7 +124,7 @@ class PbMap extends MapBase { PbMap freeze() { _isReadOnly = true; - if (PbFieldTypeInternal.isGroupOrMessage(valueFieldType)) { + if (PbFieldType.isGroupOrMessage(valueFieldType)) { for (final subMessage in values as Iterable) { subMessage.freeze(); } diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index 61632bc1a..0fe4849c6 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -6,26 +6,26 @@ part of 'internal.dart'; Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { - final baseType = PbFieldTypeInternal.baseType(keyType); + final baseType = PbFieldType.baseType(keyType); - assert(!PbFieldTypeInternal.isRepeated(keyType)); + assert(!PbFieldType.isRepeated(keyType)); switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: return key ? 'true' : 'false'; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return key; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: return (key as Int64).toStringUnsigned(); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return key.toString(); default: throw StateError('Not a valid key type $keyType'); @@ -35,33 +35,33 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { Object? valueToProto3Json(dynamic fieldValue, int? fieldType) { if (fieldValue == null) return null; - if (PbFieldTypeInternal.isGroupOrMessage(fieldType!)) { + if (PbFieldType.isGroupOrMessage(fieldType!)) { return _writeToProto3Json( (fieldValue as GeneratedMessage)._fieldSet, typeRegistry, ); - } else if (PbFieldTypeInternal.isEnum(fieldType)) { + } else if (PbFieldType.isEnum(fieldType)) { return (fieldValue as ProtobufEnum).name; } else { - final baseType = PbFieldTypeInternal.baseType(fieldType); + final baseType = PbFieldType.baseType(fieldType); switch (baseType) { - case PbFieldTypeInternal.BOOL_BIT: + case PbFieldType.BOOL_BIT: return fieldValue as bool; - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return fieldValue; - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return fieldValue; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return fieldValue.toString(); - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: final double value = fieldValue; if (value.isNaN) { return nan; @@ -73,9 +73,9 @@ Object? _writeToProto3Json(FieldSet fs, TypeRegistry typeRegistry) { return value.toInt(); } return value; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: return (fieldValue as Int64).toStringUnsigned(); - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: return base64Encode(fieldValue); default: throw StateError( @@ -176,13 +176,13 @@ void _mergeFromProto3Json( void recursionHelper(Object? json, FieldSet fieldSet) { Object? convertProto3JsonValue(Object value, FieldInfo fieldInfo) { final fieldType = fieldInfo.type; - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: if (value is bool) { return value; } throw context.parseException('Expected bool value', json); - case PbFieldTypeInternal.BYTES_BIT: + case PbFieldType.BYTES_BIT: if (value is String) { Uint8List result; try { @@ -199,13 +199,13 @@ void _mergeFromProto3Json( 'Expected bytes encoded as base64 String', value, ); - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: if (value is String) { return value; } throw context.parseException('Expected String value', value); - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.DOUBLE_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.DOUBLE_BIT: if (value is double) { return value; } else if (value is num) { @@ -221,7 +221,7 @@ void _mergeFromProto3Json( 'Expected a double represented as a String or number', value, ); - case PbFieldTypeInternal.ENUM_BIT: + case PbFieldType.ENUM_BIT: if (value is String) { // TODO(sigurdm): Do we want to avoid linear search here? Measure... final result = @@ -245,8 +245,8 @@ void _mergeFromProto3Json( 'Expected enum as a string or integer', value, ); - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.FIXED32_BIT: int result; if (value is int) { result = value; @@ -259,9 +259,9 @@ void _mergeFromProto3Json( ); } return _check32BitUnsignedProto3(result, context); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SFIXED32_BIT: int result; if (value is int) { result = value; @@ -275,7 +275,7 @@ void _mergeFromProto3Json( } _check32BitSignedProto3(result, context); return result; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: Int64 result; if (value is int) { result = Int64(value); @@ -288,10 +288,10 @@ void _mergeFromProto3Json( ); } return result; - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: if (value is int) return Int64(value); if (value is String) { Int64 result; @@ -309,8 +309,8 @@ void _mergeFromProto3Json( 'Expected int or stringified int', value, ); - case PbFieldTypeInternal.GROUP_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.GROUP_BIT: + case PbFieldType.MESSAGE_BIT: final subMessage = fieldInfo.subBuilder!(); recursionHelper(value, subMessage._fieldSet); return subMessage; @@ -320,8 +320,8 @@ void _mergeFromProto3Json( } Object decodeMapKey(String key, int fieldType) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: switch (key) { case 'true': return true; @@ -333,26 +333,26 @@ void _mergeFromProto3Json( key, ); } - case PbFieldTypeInternal.STRING_BIT: + case PbFieldType.STRING_BIT: return key; - case PbFieldTypeInternal.UINT64_BIT: + case PbFieldType.UINT64_BIT: // TODO(sigurdm): We do not throw on negative values here. // That would probably require going via bignum. return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: - case PbFieldTypeInternal.FIXED64_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.SFIXED64_BIT: + case PbFieldType.FIXED64_BIT: return _tryParse64BitProto3(json, key, context); - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return _check32BitSignedProto3( _tryParse32BitProto3(key, context), context, ); - case PbFieldTypeInternal.UINT32_BIT: + case PbFieldType.UINT32_BIT: return _check32BitUnsignedProto3( _tryParse32BitProto3(key, context), context, @@ -400,7 +400,7 @@ void _mergeFromProto3Json( } } - if (PbFieldTypeInternal.isMapField(fieldInfo.type)) { + if (PbFieldType.isMapField(fieldInfo.type)) { if (value is Map) { final mapFieldInfo = fieldInfo as MapFieldInfo; final Map fieldValues = fieldSet._ensureMapField(meta, fieldInfo); @@ -421,7 +421,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a map', value); } - } else if (PbFieldTypeInternal.isRepeated(fieldInfo.type)) { + } else if (PbFieldType.isRepeated(fieldInfo.type)) { if (value is List) { final values = fieldSet._ensureRepeatedField(meta, fieldInfo); for (var i = 0; i < value.length; i++) { @@ -433,7 +433,7 @@ void _mergeFromProto3Json( } else { throw context.parseException('Expected a list', value); } - } else if (PbFieldTypeInternal.isGroupOrMessage(fieldInfo.type)) { + } else if (PbFieldType.isGroupOrMessage(fieldInfo.type)) { // TODO(sigurdm) consider a cleaner separation between parsing and // merging. final parsedSubMessage = diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 9702c5670..196c6b4fe 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -283,11 +283,11 @@ class UnknownFieldSetField { output.writeField(fieldNumber, type, value); } - write(PbFieldTypeInternal.REPEATED_UINT64, varints); - write(PbFieldTypeInternal.REPEATED_FIXED32, fixed32s); - write(PbFieldTypeInternal.REPEATED_FIXED64, fixed64s); - write(PbFieldTypeInternal.REPEATED_BYTES, lengthDelimited); - write(PbFieldTypeInternal.REPEATED_GROUP, groups); + write(PbFieldType.REPEATED_UINT64, varints); + write(PbFieldType.REPEATED_FIXED32, fixed32s); + write(PbFieldType.REPEATED_FIXED64, fixed64s); + write(PbFieldType.REPEATED_BYTES, lengthDelimited); + write(PbFieldType.REPEATED_GROUP, groups); } void addGroup(UnknownFieldSet value) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index 16e400b4a..375ee4b2d 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -38,32 +38,32 @@ int makeTag(int fieldNumber, int tag) => (fieldNumber << _TAG_TYPE_BITS) | tag; /// Returns true if the wireType can be merged into the given fieldType. bool _wireTypeMatches(int fieldType, int wireType) { - switch (PbFieldTypeInternal.baseType(fieldType)) { - case PbFieldTypeInternal.BOOL_BIT: - case PbFieldTypeInternal.ENUM_BIT: - case PbFieldTypeInternal.INT32_BIT: - case PbFieldTypeInternal.INT64_BIT: - case PbFieldTypeInternal.SINT32_BIT: - case PbFieldTypeInternal.SINT64_BIT: - case PbFieldTypeInternal.UINT32_BIT: - case PbFieldTypeInternal.UINT64_BIT: + switch (PbFieldType.baseType(fieldType)) { + case PbFieldType.BOOL_BIT: + case PbFieldType.ENUM_BIT: + case PbFieldType.INT32_BIT: + case PbFieldType.INT64_BIT: + case PbFieldType.SINT32_BIT: + case PbFieldType.SINT64_BIT: + case PbFieldType.UINT32_BIT: + case PbFieldType.UINT64_BIT: return wireType == WIRETYPE_VARINT || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.FLOAT_BIT: - case PbFieldTypeInternal.FIXED32_BIT: - case PbFieldTypeInternal.SFIXED32_BIT: + case PbFieldType.FLOAT_BIT: + case PbFieldType.FIXED32_BIT: + case PbFieldType.SFIXED32_BIT: return wireType == WIRETYPE_FIXED32 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.DOUBLE_BIT: - case PbFieldTypeInternal.FIXED64_BIT: - case PbFieldTypeInternal.SFIXED64_BIT: + case PbFieldType.DOUBLE_BIT: + case PbFieldType.FIXED64_BIT: + case PbFieldType.SFIXED64_BIT: return wireType == WIRETYPE_FIXED64 || wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.BYTES_BIT: - case PbFieldTypeInternal.STRING_BIT: - case PbFieldTypeInternal.MESSAGE_BIT: + case PbFieldType.BYTES_BIT: + case PbFieldType.STRING_BIT: + case PbFieldType.MESSAGE_BIT: return wireType == WIRETYPE_LENGTH_DELIMITED; - case PbFieldTypeInternal.GROUP_BIT: + case PbFieldType.GROUP_BIT: return wireType == WIRETYPE_START_GROUP; default: return false; diff --git a/protobuf/test/codec_test.dart b/protobuf/test/codec_test.dart index 650259c1e..215e90d7f 100644 --- a/protobuf/test/codec_test.dart +++ b/protobuf/test/codec_test.dart @@ -29,7 +29,7 @@ void main() { }; } - final int32ToBytes = convertToBytes(PbFieldTypeInternal.O3); + final int32ToBytes = convertToBytes(PbFieldType.O3); test('testInt32RoundTrips', () { final roundtrip = roundtripTester( @@ -60,7 +60,7 @@ void main() { test('testSint32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint32(), - toBytes: convertToBytes(PbFieldTypeInternal.OS3), + toBytes: convertToBytes(PbFieldType.OS3), ); roundtrip(0, [0x00]); @@ -72,7 +72,7 @@ void main() { test('testSint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OS6), + toBytes: convertToBytes(PbFieldType.OS6), ); roundtrip(make64(0), [0x00]); @@ -84,7 +84,7 @@ void main() { test('testFixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OF3), + toBytes: convertToBytes(PbFieldType.OF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -96,7 +96,7 @@ void main() { test('testFixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readFixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OF6), + toBytes: convertToBytes(PbFieldType.OF6), ); roundtrip(make64(0, 0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -126,7 +126,7 @@ void main() { test('testSfixed32', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed32(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF3), + toBytes: convertToBytes(PbFieldType.OSF3), ); roundtrip(0, [0x00, 0x00, 0x00, 0x00]); @@ -138,7 +138,7 @@ void main() { test('testSfixed64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readSfixed64(), - toBytes: convertToBytes(PbFieldTypeInternal.OSF6), + toBytes: convertToBytes(PbFieldType.OSF6), ); roundtrip(make64(0), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); @@ -183,7 +183,7 @@ void main() { : equals(expected); List dataToBytes(ByteData byteData) => Uint8List.view(byteData.buffer); - final floatToBytes = convertToBytes(PbFieldTypeInternal.OF); + final floatToBytes = convertToBytes(PbFieldType.OF); int floatToBits(double value) => makeData(floatToBytes(value)).getUint32(0, Endian.little); @@ -197,7 +197,7 @@ void main() { expect(readFloat(bits), doubleEquals(value)); } - final doubleToBytes = convertToBytes(PbFieldTypeInternal.OD); + final doubleToBytes = convertToBytes(PbFieldType.OD); void test64(List hilo, double value) { // Encode a double to its wire format. @@ -732,7 +732,7 @@ void main() { test('testVarint64', () { final roundtrip = roundtripTester( fromBytes: (CodedBufferReader reader) => reader.readUint64(), - toBytes: convertToBytes(PbFieldTypeInternal.OU6), + toBytes: convertToBytes(PbFieldType.OU6), ); roundtrip(make64(0), [0x00]); @@ -794,8 +794,7 @@ void main() { }); test('testWriteTo', () { - final writer = - CodedBufferWriter()..writeField(0, PbFieldTypeInternal.O3, 1337); + final writer = CodedBufferWriter()..writeField(0, PbFieldType.O3, 1337); expect(writer.lengthInBytes, 3); final buffer = Uint8List(5); buffer[0] = 0x55; diff --git a/protobuf/test/list_test.dart b/protobuf/test/list_test.dart index 319b730d9..23e995100 100644 --- a/protobuf/test/list_test.dart +++ b/protobuf/test/list_test.dart @@ -98,9 +98,7 @@ void main() { }); test('PbList for signed int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.P3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.P3)); expect(() { list.add(-2147483649); @@ -128,9 +126,7 @@ void main() { }); test('PBList for unsigned int32 validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PU3), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PU3)); expect(() { list.add(-1); @@ -158,9 +154,7 @@ void main() { }); test('PbList for float validates items', () { - final List list = PbList( - check: getCheckFunction(PbFieldTypeInternal.PF), - ); + final List list = PbList(check: getCheckFunction(PbFieldType.PF)); expect(() { list.add(3.4028234663852886E39); diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index 8b5edd66d..fdd385ea3 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -9,28 +9,22 @@ import 'package:protobuf/protobuf.dart' BuilderInfo, CreateBuilderFunc, GeneratedMessage, - PbFieldTypeInternal, + PbFieldType, ProtobufEnum; final mockEnumValues = [ProtobufEnum(1, 'a'), ProtobufEnum(2, 'b')]; BuilderInfo mockInfo(String className, CreateBuilderFunc create) { return BuilderInfo(className, createEmptyInstance: create) - ..a(1, 'val', PbFieldTypeInternal.O3, defaultOrMaker: 42) - ..a(2, 'str', PbFieldTypeInternal.OS) - ..a( - 3, - 'child', - PbFieldTypeInternal.OM, - defaultOrMaker: create, - subBuilder: create, - ) - ..p(4, 'int32s', PbFieldTypeInternal.P3) - ..a(5, 'int64', PbFieldTypeInternal.O6) + ..a(1, 'val', PbFieldType.O3, defaultOrMaker: 42) + ..a(2, 'str', PbFieldType.OS) + ..a(3, 'child', PbFieldType.OM, defaultOrMaker: create, subBuilder: create) + ..p(4, 'int32s', PbFieldType.P3) + ..a(5, 'int64', PbFieldType.O6) // 6 is reserved for extensions in other tests. ..e( 7, 'enm', - PbFieldTypeInternal.OE, + PbFieldType.OE, defaultOrMaker: mockEnumValues.first, valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), enumValues: mockEnumValues, diff --git a/protobuf/test/readonly_message_test.dart b/protobuf/test/readonly_message_test.dart index dba11f208..cf5b37d59 100644 --- a/protobuf/test/readonly_message_test.dart +++ b/protobuf/test/readonly_message_test.dart @@ -3,11 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:protobuf/protobuf.dart' - show - BuilderInfo, - GeneratedMessage, - PbFieldTypeInternal, - UnknownFieldSetField; + show BuilderInfo, GeneratedMessage, PbFieldType, UnknownFieldSetField; import 'package:test/test.dart'; Matcher throwsUnsupportedError(Matcher expectedMessage) => throwsA( @@ -27,9 +23,9 @@ class Rec extends GeneratedMessage { @override BuilderInfo info_ = BuilderInfo('rec') - ..a(1, 'value', PbFieldTypeInternal.O3) - ..pc(2, 'sub', PbFieldTypeInternal.PM, subBuilder: Rec.create) - ..p(10, 'ints', PbFieldTypeInternal.P3); + ..a(1, 'value', PbFieldType.O3) + ..pc(2, 'sub', PbFieldType.PM, subBuilder: Rec.create) + ..p(10, 'ints', PbFieldType.P3); int get value => $_get(0, 0); set value(int v) { diff --git a/protoc_plugin/lib/src/base_type.dart b/protoc_plugin/lib/src/base_type.dart index 6a96832c6..0f5d08c60 100644 --- a/protoc_plugin/lib/src/base_type.dart +++ b/protoc_plugin/lib/src/base_type.dart @@ -12,7 +12,7 @@ class BaseType { /// The name of the Dart type when in the same package. final String unprefixed; - /// The suffix of the constant for this type in PbFieldTypeInternal. + /// The suffix of the constant for this type in PbFieldType. /// (For example, 'B' for boolean or '3' for int32.) final String typeConstantSuffix; diff --git a/protoc_plugin/lib/src/gen/dart_options.pb.dart b/protoc_plugin/lib/src/gen/dart_options.pb.dart index 8b53eb43f..5534342aa 100644 --- a/protoc_plugin/lib/src/gen/dart_options.pb.dart +++ b/protoc_plugin/lib/src/gen/dart_options.pb.dart @@ -125,8 +125,7 @@ class Imports extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Imports', package: const $pb.PackageName(_omitMessageNames ? '' : 'dart_options'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldTypeInternal.PM, + ..pc(1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, subBuilder: DartMixin.create) ..hasRequiredFields = false; @@ -166,44 +165,44 @@ class Dart_options { _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'imports', 28125061, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: Imports.getDefault, subBuilder: Imports.create); static final defaultMixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FileOptions', _omitFieldNames ? '' : 'defaultMixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final mixin = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.MessageOptions', _omitFieldNames ? '' : 'mixin', 96128839, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final overrideGetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideGetter', 28205290, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideSetter = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideSetter', 28937366, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideHasMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideHasMethod', 28937461, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final overrideClearMethod = $pb.Extension<$core.bool>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'overrideClearMethod', 28907907, - $pb.PbFieldTypeInternal.OB); + $pb.PbFieldType.OB); static final dartName = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.FieldOptions', _omitFieldNames ? '' : 'dartName', 28700919, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(imports); registry.add(defaultMixin); diff --git a/protoc_plugin/lib/src/gen/google/api/client.pb.dart b/protoc_plugin/lib/src/gen/google/api/client.pb.dart index 16590b7f6..4660db8c8 100644 --- a/protoc_plugin/lib/src/gen/google/api/client.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/client.pb.dart @@ -53,7 +53,7 @@ class CommonLanguageSettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'referenceDocsUri') ..pc( - 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldTypeInternal.KE, + 2, _omitFieldNames ? '' : 'destinations', $pb.PbFieldType.KE, valueOf: ClientLibraryDestination.valueOf, enumValues: ClientLibraryDestination.values, defaultEnumValue: @@ -164,7 +164,7 @@ class ClientLibrarySettings extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'version') ..e<$1.LaunchStage>( - 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'launchStage', $pb.PbFieldType.OE, defaultOrMaker: $1.LaunchStage.LAUNCH_STAGE_UNSPECIFIED, valueOf: $1.LaunchStage.valueOf, enumValues: $1.LaunchStage.values) @@ -389,7 +389,7 @@ class Publishing extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'methodSettings', $pb.PbFieldType.PM, subBuilder: MethodSettings.create) ..aOS(101, _omitFieldNames ? '' : 'newIssueUri') ..aOS(102, _omitFieldNames ? '' : 'documentationUri') @@ -398,13 +398,13 @@ class Publishing extends $pb.GeneratedMessage { ..pPS(105, _omitFieldNames ? '' : 'codeownerGithubTeams') ..aOS(106, _omitFieldNames ? '' : 'docTagPrefix') ..e( - 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldTypeInternal.OE, + 107, _omitFieldNames ? '' : 'organization', $pb.PbFieldType.OE, defaultOrMaker: ClientLibraryOrganization.CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED, valueOf: ClientLibraryOrganization.valueOf, enumValues: ClientLibraryOrganization.values) - ..pc(109, _omitFieldNames ? '' : 'librarySettings', - $pb.PbFieldTypeInternal.PM, + ..pc( + 109, _omitFieldNames ? '' : 'librarySettings', $pb.PbFieldType.PM, subBuilder: ClientLibrarySettings.create) ..aOS(110, _omitFieldNames ? '' : 'protoReferenceDocumentationUri') ..aOS(111, _omitFieldNames ? '' : 'restReferenceDocumentationUri') @@ -568,8 +568,8 @@ class JavaSettings extends $pb.GeneratedMessage { ..m<$core.String, $core.String>( 2, _omitFieldNames ? '' : 'serviceClassNames', entryClassName: 'JavaSettings.ServiceClassNamesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..aOM(3, _omitFieldNames ? '' : 'common', subBuilder: CommonLanguageSettings.create) @@ -1055,14 +1055,14 @@ class DotnetSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'DotnetSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..m<$core.String, $core.String>( 3, _omitFieldNames ? '' : 'renamedResources', entryClassName: 'DotnetSettings.RenamedResourcesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..pPS(4, _omitFieldNames ? '' : 'ignoredResources') ..pPS(5, _omitFieldNames ? '' : 'forcedNamespaceAliases') @@ -1229,8 +1229,8 @@ class GoSettings extends $pb.GeneratedMessage { subBuilder: CommonLanguageSettings.create) ..m<$core.String, $core.String>(2, _omitFieldNames ? '' : 'renamedServices', entryClassName: 'GoSettings.RenamedServicesEntry', - keyFieldType: $pb.PbFieldTypeInternal.OS, - valueFieldType: $pb.PbFieldTypeInternal.OS, + keyFieldType: $pb.PbFieldType.OS, + valueFieldType: $pb.PbFieldType.OS, packageName: const $pb.PackageName('google.api')) ..hasRequiredFields = false; @@ -1313,8 +1313,8 @@ class MethodSettings_LongRunning extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM<$0.Duration>(1, _omitFieldNames ? '' : 'initialPollDelay', subBuilder: $0.Duration.create) - ..a<$core.double>(2, _omitFieldNames ? '' : 'pollDelayMultiplier', - $pb.PbFieldTypeInternal.OF) + ..a<$core.double>( + 2, _omitFieldNames ? '' : 'pollDelayMultiplier', $pb.PbFieldType.OF) ..aOM<$0.Duration>(3, _omitFieldNames ? '' : 'maxPollDelay', subBuilder: $0.Duration.create) ..aOM<$0.Duration>(4, _omitFieldNames ? '' : 'totalPollTimeout', @@ -1590,23 +1590,23 @@ class Client { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'methodSignature', 1051, - $pb.PbFieldTypeInternal.PS, - check: $pb.getCheckFunction($pb.PbFieldTypeInternal.PS)); + $pb.PbFieldType.PS, + check: $pb.getCheckFunction($pb.PbFieldType.PS)); static final defaultHost = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'defaultHost', 1049, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final oauthScopes = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'oauthScopes', 1050, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static final apiVersion = $pb.Extension<$core.String>( _omitMessageNames ? '' : 'google.protobuf.ServiceOptions', _omitFieldNames ? '' : 'apiVersion', 525000001, - $pb.PbFieldTypeInternal.OS); + $pb.PbFieldType.OS); static void registerAllExtensions($pb.ExtensionRegistry registry) { registry.add(methodSignature); registry.add(defaultHost); diff --git a/protoc_plugin/lib/src/gen/google/api/http.pb.dart b/protoc_plugin/lib/src/gen/google/api/http.pb.dart index 3aba71831..2fa07e333 100644 --- a/protoc_plugin/lib/src/gen/google/api/http.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/http.pb.dart @@ -44,8 +44,7 @@ class Http extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Http', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldTypeInternal.PM, + ..pc(1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOB(2, _omitFieldNames ? '' : 'fullyDecodeReservedExpansion') ..hasRequiredFields = false; @@ -417,8 +416,8 @@ class HttpRule extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'body') ..aOM(8, _omitFieldNames ? '' : 'custom', subBuilder: CustomHttpPattern.create) - ..pc(11, _omitFieldNames ? '' : 'additionalBindings', - $pb.PbFieldTypeInternal.PM, + ..pc( + 11, _omitFieldNames ? '' : 'additionalBindings', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOS(12, _omitFieldNames ? '' : 'responseBody') ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart index 04374313b..c8c7627e3 100644 --- a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart @@ -398,8 +398,8 @@ class RoutingRule extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'RoutingRule', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc(2, _omitFieldNames ? '' : 'routingParameters', - $pb.PbFieldTypeInternal.PM, + ..pc( + 2, _omitFieldNames ? '' : 'routingParameters', $pb.PbFieldType.PM, subBuilder: RoutingParameter.create) ..hasRequiredFields = false; @@ -562,7 +562,7 @@ class Routing { _omitMessageNames ? '' : 'google.protobuf.MethodOptions', _omitFieldNames ? '' : 'routing', 72295729, - $pb.PbFieldTypeInternal.OM, + $pb.PbFieldType.OM, defaultOrMaker: RoutingRule.getDefault, subBuilder: RoutingRule.create); static void registerAllExtensions($pb.ExtensionRegistry registry) { diff --git a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart index 0c40bcc51..023287aa7 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart @@ -51,12 +51,9 @@ class Version extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'major', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) ..aOS(4, _omitFieldNames ? '' : 'suffix') ..hasRequiredFields = false; @@ -156,12 +153,10 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { ..aOM(3, _omitFieldNames ? '' : 'compilerVersion', subBuilder: Version.create) ..pc<$0.FileDescriptorProto>( - 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create) ..pc<$0.FileDescriptorProto>( - 17, - _omitFieldNames ? '' : 'sourceFileDescriptors', - $pb.PbFieldTypeInternal.PM, + 17, _omitFieldNames ? '' : 'sourceFileDescriptors', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -428,15 +423,15 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'error') - ..a<$fixnum.Int64>(2, _omitFieldNames ? '' : 'supportedFeatures', - $pb.PbFieldTypeInternal.OU6, + ..a<$fixnum.Int64>( + 2, _omitFieldNames ? '' : 'supportedFeatures', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..a<$core.int>( - 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.O3) + 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.O3) ..a<$core.int>( - 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.O3) + 4, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.O3) ..pc( - 15, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 15, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: CodeGeneratorResponse_File.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart index 1f945e551..fe6bf4716 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart @@ -47,7 +47,7 @@ class FileDescriptorSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'file', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'file', $pb.PbFieldType.PM, subBuilder: FileDescriptorProto.create) ..hasExtensions = true; @@ -132,28 +132,27 @@ class FileDescriptorProto extends $pb.GeneratedMessage { ..aOS(2, _omitFieldNames ? '' : 'package') ..pPS(3, _omitFieldNames ? '' : 'dependency') ..pc( - 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 6, _omitFieldNames ? '' : 'service', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'service', $pb.PbFieldType.PM, subBuilder: ServiceDescriptorProto.create) ..pc( - 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 7, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FileOptions.create) ..aOM(9, _omitFieldNames ? '' : 'sourceCodeInfo', subBuilder: SourceCodeInfo.create) - ..p<$core.int>(10, _omitFieldNames ? '' : 'publicDependency', - $pb.PbFieldTypeInternal.P3) ..p<$core.int>( - 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldTypeInternal.P3) + 10, _omitFieldNames ? '' : 'publicDependency', $pb.PbFieldType.P3) + ..p<$core.int>( + 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldType.P3) ..aOS(12, _omitFieldNames ? '' : 'syntax') - ..e( - 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -312,9 +311,8 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ExtensionRangeOptions.create); @@ -401,9 +399,8 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -496,31 +493,31 @@ class DescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'field', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'field', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..pc( - 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldTypeInternal.PM, + 3, _omitFieldNames ? '' : 'nestedType', $pb.PbFieldType.PM, subBuilder: DescriptorProto.create) ..pc( - 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto.create) ..pc( - 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldTypeInternal.PM, + 5, _omitFieldNames ? '' : 'extensionRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ExtensionRange.create) ..pc( - 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldTypeInternal.PM, + 6, _omitFieldNames ? '' : 'extension', $pb.PbFieldType.PM, subBuilder: FieldDescriptorProto.create) ..aOM(7, _omitFieldNames ? '' : 'options', subBuilder: MessageOptions.create) ..pc( - 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldTypeInternal.PM, + 8, _omitFieldNames ? '' : 'oneofDecl', $pb.PbFieldType.PM, subBuilder: OneofDescriptorProto.create) ..pc( - 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 9, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: DescriptorProto_ReservedRange.create) ..pPS(10, _omitFieldNames ? '' : 'reservedName') ..e( - 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 11, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -635,8 +632,7 @@ class ExtensionRangeOptions_Declaration extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOS(2, _omitFieldNames ? '' : 'fullName') ..aOS(3, _omitFieldNames ? '' : 'type') ..aOB(5, _omitFieldNames ? '' : 'reserved') @@ -757,17 +753,17 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'declaration', $pb.PbFieldType.PM, subBuilder: ExtensionRangeOptions_Declaration.create) ..e( - 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'verification', $pb.PbFieldType.OE, defaultOrMaker: ExtensionRangeOptions_VerificationState.UNVERIFIED, valueOf: ExtensionRangeOptions_VerificationState.valueOf, enumValues: ExtensionRangeOptions_VerificationState.values) ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -876,15 +872,14 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..aOS(2, _omitFieldNames ? '' : 'extendee') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..e( - 4, _omitFieldNames ? '' : 'label', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, valueOf: FieldDescriptorProto_Label.valueOf, enumValues: FieldDescriptorProto_Label.values) ..e( - 5, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Type.TYPE_DOUBLE, valueOf: FieldDescriptorProto_Type.valueOf, enumValues: FieldDescriptorProto_Type.values) @@ -892,8 +887,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'defaultValue') ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FieldOptions.create) - ..a<$core.int>( - 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) ..aOS(10, _omitFieldNames ? '' : 'jsonName') ..aOB(17, _omitFieldNames ? '' : 'proto3Optional'); @@ -1166,9 +1160,8 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -1252,16 +1245,16 @@ class EnumDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'value', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'value', $pb.PbFieldType.PM, subBuilder: EnumValueDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumOptions.create) ..pc( - 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldTypeInternal.PM, + 4, _omitFieldNames ? '' : 'reservedRange', $pb.PbFieldType.PM, subBuilder: EnumDescriptorProto_EnumReservedRange.create) ..pPS(5, _omitFieldNames ? '' : 'reservedName') ..e( - 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'visibility', $pb.PbFieldType.OE, defaultOrMaker: SymbolVisibility.VISIBILITY_UNSET, valueOf: SymbolVisibility.valueOf, enumValues: SymbolVisibility.values); @@ -1362,8 +1355,7 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'number', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumValueOptions.create); @@ -1450,7 +1442,7 @@ class ServiceDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..pc( - 2, _omitFieldNames ? '' : 'method', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'method', $pb.PbFieldType.PM, subBuilder: MethodDescriptorProto.create) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ServiceOptions.create); @@ -1701,7 +1693,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(1, _omitFieldNames ? '' : 'javaPackage') ..aOS(8, _omitFieldNames ? '' : 'javaOuterClassname') ..e( - 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldTypeInternal.OE, + 9, _omitFieldNames ? '' : 'optimizeFor', $pb.PbFieldType.OE, defaultOrMaker: FileOptions_OptimizeMode.SPEED, valueOf: FileOptions_OptimizeMode.valueOf, enumValues: FileOptions_OptimizeMode.values) @@ -1714,7 +1706,7 @@ class FileOptions extends $pb.GeneratedMessage { ..aOB(23, _omitFieldNames ? '' : 'deprecated') ..aOB(27, _omitFieldNames ? '' : 'javaStringCheckUtf8') ..a<$core.bool>( - 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldTypeInternal.OB, + 31, _omitFieldNames ? '' : 'ccEnableArenas', $pb.PbFieldType.OB, defaultOrMaker: true) ..aOS(36, _omitFieldNames ? '' : 'objcClassPrefix') ..aOS(37, _omitFieldNames ? '' : 'csharpNamespace') @@ -1725,8 +1717,8 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(45, _omitFieldNames ? '' : 'rubyPackage') ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2059,8 +2051,8 @@ class MessageOptions extends $pb.GeneratedMessage { ..aOB(11, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(12, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2237,8 +2229,7 @@ class FieldOptions_EditionDefault extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(2, _omitFieldNames ? '' : 'value') - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2319,19 +2310,18 @@ class FieldOptions_FeatureSupport extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e(1, _omitFieldNames ? '' : 'editionIntroduced', - $pb.PbFieldTypeInternal.OE, + ..e( + 1, _omitFieldNames ? '' : 'editionIntroduced', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e(2, _omitFieldNames ? '' : 'editionDeprecated', - $pb.PbFieldTypeInternal.OE, + ..e( + 2, _omitFieldNames ? '' : 'editionDeprecated', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..aOS(3, _omitFieldNames ? '' : 'deprecationWarning') - ..e( - 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldTypeInternal.OE, + ..e(4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2460,7 +2450,7 @@ class FieldOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'ctype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_CType.STRING, valueOf: FieldOptions_CType.valueOf, enumValues: FieldOptions_CType.values) @@ -2468,7 +2458,7 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(3, _omitFieldNames ? '' : 'deprecated') ..aOB(5, _omitFieldNames ? '' : 'lazy') ..e( - 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jstype', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_JSType.JS_NORMAL, valueOf: FieldOptions_JSType.valueOf, enumValues: FieldOptions_JSType.values) @@ -2476,25 +2466,25 @@ class FieldOptions extends $pb.GeneratedMessage { ..aOB(15, _omitFieldNames ? '' : 'unverifiedLazy') ..aOB(16, _omitFieldNames ? '' : 'debugRedact') ..e( - 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldTypeInternal.OE, + 17, _omitFieldNames ? '' : 'retention', $pb.PbFieldType.OE, defaultOrMaker: FieldOptions_OptionRetention.RETENTION_UNKNOWN, valueOf: FieldOptions_OptionRetention.valueOf, enumValues: FieldOptions_OptionRetention.values) ..pc( - 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldTypeInternal.PE, + 19, _omitFieldNames ? '' : 'targets', $pb.PbFieldType.PE, valueOf: FieldOptions_OptionTargetType.valueOf, enumValues: FieldOptions_OptionTargetType.values, defaultEnumValue: FieldOptions_OptionTargetType.TARGET_TYPE_UNKNOWN) - ..pc(20, - _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldTypeInternal.PM, + ..pc( + 20, _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, subBuilder: FieldOptions_EditionDefault.create) ..aOM(21, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..aOM( 22, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2723,8 +2713,8 @@ class OneofOptions extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM(1, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2809,8 +2799,8 @@ class EnumOptions extends $pb.GeneratedMessage { ..aOB(6, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(7, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2937,8 +2927,8 @@ class EnumValueOptions extends $pb.GeneratedMessage { ..aOM( 4, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3051,8 +3041,8 @@ class ServiceOptions extends $pb.GeneratedMessage { ..aOB(33, _omitFieldNames ? '' : 'deprecated') ..aOM(34, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3141,15 +3131,15 @@ class MethodOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOB(33, _omitFieldNames ? '' : 'deprecated') - ..e(34, - _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldTypeInternal.OE, + ..e( + 34, _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, valueOf: MethodOptions_IdempotencyLevel.valueOf, enumValues: MethodOptions_IdempotencyLevel.values) ..aOM(35, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldTypeInternal.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3249,7 +3239,7 @@ class UninterpretedOption_NamePart extends $pb.GeneratedMessage { createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'namePart') ..a<$core.bool>( - 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldTypeInternal.QB); + 2, _omitFieldNames ? '' : 'isExtension', $pb.PbFieldType.QB); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') UninterpretedOption_NamePart clone() => @@ -3337,17 +3327,17 @@ class UninterpretedOption extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 2, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.PM, + 2, _omitFieldNames ? '' : 'name', $pb.PbFieldType.PM, subBuilder: UninterpretedOption_NamePart.create) ..aOS(3, _omitFieldNames ? '' : 'identifierValue') - ..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'positiveIntValue', - $pb.PbFieldTypeInternal.OU6, + ..a<$fixnum.Int64>( + 4, _omitFieldNames ? '' : 'positiveIntValue', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aInt64(5, _omitFieldNames ? '' : 'negativeIntValue') ..a<$core.double>( - 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldTypeInternal.OD) + 6, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldType.OD) ..a<$core.List<$core.int>>( - 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldTypeInternal.OY) + 7, _omitFieldNames ? '' : 'stringValue', $pb.PbFieldType.OY) ..aOS(8, _omitFieldNames ? '' : 'aggregateValue'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -3524,48 +3514,44 @@ class FeatureSet extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..e( - 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldTypeInternal.OE, + 1, _omitFieldNames ? '' : 'fieldPresence', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_FieldPresence.FIELD_PRESENCE_UNKNOWN, valueOf: FeatureSet_FieldPresence.valueOf, enumValues: FeatureSet_FieldPresence.values) ..e( - 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldTypeInternal.OE, + 2, _omitFieldNames ? '' : 'enumType', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnumType.ENUM_TYPE_UNKNOWN, valueOf: FeatureSet_EnumType.valueOf, enumValues: FeatureSet_EnumType.values) ..e( - 3, - _omitFieldNames ? '' : 'repeatedFieldEncoding', - $pb.PbFieldTypeInternal.OE, + 3, _omitFieldNames ? '' : 'repeatedFieldEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_RepeatedFieldEncoding.REPEATED_FIELD_ENCODING_UNKNOWN, valueOf: FeatureSet_RepeatedFieldEncoding.valueOf, enumValues: FeatureSet_RepeatedFieldEncoding.values) ..e( - 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldTypeInternal.OE, + 4, _omitFieldNames ? '' : 'utf8Validation', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN, valueOf: FeatureSet_Utf8Validation.valueOf, enumValues: FeatureSet_Utf8Validation.values) ..e( - 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'messageEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN, valueOf: FeatureSet_MessageEncoding.valueOf, enumValues: FeatureSet_MessageEncoding.values) ..e( - 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldTypeInternal.OE, + 6, _omitFieldNames ? '' : 'jsonFormat', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN, valueOf: FeatureSet_JsonFormat.valueOf, enumValues: FeatureSet_JsonFormat.values) - ..e(7, - _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldTypeInternal.OE, + ..e( + 7, _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN, valueOf: FeatureSet_EnforceNamingStyle.valueOf, enumValues: FeatureSet_EnforceNamingStyle.values) ..e( - 8, - _omitFieldNames ? '' : 'defaultSymbolVisibility', - $pb.PbFieldTypeInternal.OE, + 8, _omitFieldNames ? '' : 'defaultSymbolVisibility', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_VisibilityFeature_DefaultSymbolVisibility .DEFAULT_SYMBOL_VISIBILITY_UNKNOWN, valueOf: FeatureSet_VisibilityFeature_DefaultSymbolVisibility.valueOf, @@ -3703,8 +3689,7 @@ class FeatureSetDefaults_FeatureSetEditionDefault extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldTypeInternal.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -3806,15 +3791,13 @@ class FeatureSetDefaults extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldType.PM, subBuilder: FeatureSetDefaults_FeatureSetEditionDefault.create) - ..e( - 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldTypeInternal.OE, + ..e(4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e( - 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldTypeInternal.OE, + ..e(5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values); @@ -3899,8 +3882,8 @@ class SourceCodeInfo_Location extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) - ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) + ..p<$core.int>(2, _omitFieldNames ? '' : 'span', $pb.PbFieldType.K3) ..aOS(3, _omitFieldNames ? '' : 'leadingComments') ..aOS(4, _omitFieldNames ? '' : 'trailingComments') ..pPS(6, _omitFieldNames ? '' : 'leadingDetachedComments') @@ -4058,7 +4041,7 @@ class SourceCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'location', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'location', $pb.PbFieldType.PM, subBuilder: SourceCodeInfo_Location.create) ..hasExtensions = true; @@ -4161,13 +4144,12 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldTypeInternal.K3) + ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) ..aOS(2, _omitFieldNames ? '' : 'sourceFile') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldTypeInternal.O3) - ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) + ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..e( - 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldTypeInternal.OE, + 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldType.OE, defaultOrMaker: GeneratedCodeInfo_Annotation_Semantic.NONE, valueOf: GeneratedCodeInfo_Annotation_Semantic.valueOf, enumValues: GeneratedCodeInfo_Annotation_Semantic.values) @@ -4274,7 +4256,7 @@ class GeneratedCodeInfo extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..pc( - 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldTypeInternal.PM, + 1, _omitFieldNames ? '' : 'annotation', $pb.PbFieldType.PM, subBuilder: GeneratedCodeInfo_Annotation.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart index dc5428b0b..5cba2308c 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart @@ -105,8 +105,7 @@ class Duration extends $pb.GeneratedMessage with $mixin.DurationMixin { toProto3Json: $mixin.DurationMixin.toProto3JsonHelper, fromProto3Json: $mixin.DurationMixin.fromProto3JsonHelper) ..aInt64(1, _omitFieldNames ? '' : 'seconds') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldTypeInternal.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index 67ea4cef5..af3ec5921 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -181,7 +181,7 @@ class ProtobufField { /// Returns the tag number of the underlying proto field. int get number => descriptor.number; - /// Returns the constant in PbFieldTypeInternal corresponding to this type. + /// Returns the constant in PbFieldType corresponding to this type. String get typeConstant { var prefix = 'O'; if (isRequired) { @@ -191,7 +191,7 @@ class ProtobufField { } else if (isRepeated) { prefix = 'P'; } - return '$protobufImportPrefix.PbFieldTypeInternal.$prefix${baseType.typeConstantSuffix}'; + return '$protobufImportPrefix.PbFieldType.$prefix${baseType.typeConstantSuffix}'; } static String _formatArguments( @@ -260,7 +260,7 @@ class ProtobufField { 'const $protobufImportPrefix.PackageName(\'$package\')'; } } else if (isRepeated) { - if (typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.PS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.PS') { invocation = 'pPS'; } else { args.add(typeConstant); @@ -291,11 +291,9 @@ class ProtobufField { } else if (makeDefault == null) { switch (type) { case '$coreImportPrefix.String': - if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OS') { invocation = 'aOS'; - } else if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.QS') { + } else if (typeConstant == '$protobufImportPrefix.PbFieldType.QS') { invocation = 'aQS'; } else { invocation = 'a<$type>'; @@ -303,8 +301,7 @@ class ProtobufField { } break; case '$coreImportPrefix.bool': - if (typeConstant == - '$protobufImportPrefix.PbFieldTypeInternal.OB') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OB') { invocation = 'aOB'; } else { invocation = 'a<$type>'; @@ -319,7 +316,7 @@ class ProtobufField { } else { if (makeDefault == '$fixnumImportPrefix.Int64.ZERO' && type == '$fixnumImportPrefix.Int64' && - typeConstant == '$protobufImportPrefix.PbFieldTypeInternal.O6') { + typeConstant == '$protobufImportPrefix.PbFieldType.O6') { invocation = 'aInt64'; } else { if (baseType.isMessage || baseType.isGroup) { diff --git a/protoc_plugin/test/goldens/extension.pb.dart b/protoc_plugin/test/goldens/extension.pb.dart index 1da48e7fc..32a5dcb75 100644 --- a/protoc_plugin/test/goldens/extension.pb.dart +++ b/protoc_plugin/test/goldens/extension.pb.dart @@ -1,4 +1,4 @@ -static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldTypeInternal.OS); +static final clientInfo = $pb.Extension<$core.String>(_omitMessageNames ? '' : 'Card', _omitFieldNames ? '' : 'clientInfo', 261486461, $pb.PbFieldType.OS); const $core.bool _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const $core.bool _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart b/protoc_plugin/test/goldens/messageGenerator.pb.dart index 7c285d54f..15d05a340 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart @@ -8,8 +8,8 @@ class PhoneNumber extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) - ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, defaultOrMaker: '\$') + ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: PhoneNumber_PhoneType.MOBILE, valueOf: PhoneNumber_PhoneType.valueOf, enumValues: PhoneNumber_PhoneType.values) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$') ..aOS(4, _omitFieldNames ? '' : 'deprecatedField') ; diff --git a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta index a5992239b..faefae9b1 100644 --- a/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta +++ b/protoc_plugin/test/goldens/messageGenerator.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1870 - end: 1876 + begin: 1854 + end: 1860 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 1918 - end: 1924 + begin: 1902 + end: 1908 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2004 - end: 2013 + begin: 1988 + end: 1997 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 1 sourceFile: - begin: 2056 - end: 2067 + begin: 2040 + end: 2051 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2139 - end: 2143 + begin: 2123 + end: 2127 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2184 - end: 2188 + begin: 2168 + end: 2172 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2276 - end: 2283 + begin: 2260 + end: 2267 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 0 sourceFile: - begin: 2326 - end: 2335 + begin: 2310 + end: 2319 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2398 - end: 2402 + begin: 2382 + end: 2386 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2449 - end: 2453 + begin: 2433 + end: 2437 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2533 - end: 2540 + begin: 2517 + end: 2524 } annotation: { path: 4 @@ -117,8 +117,8 @@ annotation: { path: 2 path: 2 sourceFile: - begin: 2583 - end: 2592 + begin: 2567 + end: 2576 } annotation: { path: 4 @@ -126,8 +126,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2704 - end: 2719 + begin: 2688 + end: 2703 } annotation: { path: 4 @@ -135,8 +135,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2810 - end: 2825 + begin: 2794 + end: 2809 } annotation: { path: 4 @@ -144,8 +144,8 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 2954 - end: 2972 + begin: 2938 + end: 2956 } annotation: { path: 4 @@ -153,6 +153,6 @@ annotation: { path: 2 path: 3 sourceFile: - begin: 3064 - end: 3084 + begin: 3048 + end: 3068 } diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart b/protoc_plugin/test/goldens/oneMessage.pb.dart index d408d4521..e38712f82 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart @@ -32,9 +32,8 @@ class PhoneNumber extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create) ..aQS(1, _omitFieldNames ? '' : 'number') - ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldTypeInternal.O3) - ..a<$core.String>( - 3, _omitFieldNames ? '' : 'name', $pb.PbFieldTypeInternal.OS, + ..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.O3) + ..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$'); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta index 6fdc950eb..44ec15bfc 100644 --- a/protoc_plugin/test/goldens/oneMessage.pb.dart.meta +++ b/protoc_plugin/test/goldens/oneMessage.pb.dart.meta @@ -18,8 +18,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2234 - end: 2240 + begin: 2218 + end: 2224 } annotation: { path: 4 @@ -27,8 +27,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2282 - end: 2288 + begin: 2266 + end: 2272 } annotation: { path: 4 @@ -36,8 +36,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2368 - end: 2377 + begin: 2352 + end: 2361 } annotation: { path: 4 @@ -45,8 +45,8 @@ annotation: { path: 2 path: 0 sourceFile: test - begin: 2420 - end: 2431 + begin: 2404 + end: 2415 } annotation: { path: 4 @@ -54,8 +54,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2491 - end: 2495 + begin: 2475 + end: 2479 } annotation: { path: 4 @@ -63,8 +63,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2537 - end: 2541 + begin: 2521 + end: 2525 } annotation: { path: 4 @@ -72,8 +72,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2623 - end: 2630 + begin: 2607 + end: 2614 } annotation: { path: 4 @@ -81,8 +81,8 @@ annotation: { path: 2 path: 1 sourceFile: test - begin: 2673 - end: 2682 + begin: 2657 + end: 2666 } annotation: { path: 4 @@ -90,8 +90,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2745 - end: 2749 + begin: 2729 + end: 2733 } annotation: { path: 4 @@ -99,8 +99,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2796 - end: 2800 + begin: 2780 + end: 2784 } annotation: { path: 4 @@ -108,8 +108,8 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2880 - end: 2887 + begin: 2864 + end: 2871 } annotation: { path: 4 @@ -117,6 +117,6 @@ annotation: { path: 2 path: 2 sourceFile: test - begin: 2930 - end: 2939 + begin: 2914 + end: 2923 } From 38e9653906077de0e5271cd3305eba6ac7d5eb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:43:29 +0100 Subject: [PATCH 18/22] Formatting --- .../lib/src/gen/dart_options.pb.dart | 3 +- .../lib/src/gen/google/api/client.pb.dart | 8 +- .../lib/src/gen/google/api/http.pb.dart | 7 +- .../lib/src/gen/google/api/routing.pb.dart | 4 +- .../google/protobuf/compiler/plugin.pb.dart | 17 +-- .../gen/google/protobuf/descriptor.pb.dart | 114 ++++++++---------- .../src/gen/google/protobuf/duration.pb.dart | 3 +- protoc_plugin/lib/src/protobuf_field.dart | 9 +- 8 files changed, 68 insertions(+), 97 deletions(-) diff --git a/protoc_plugin/lib/src/gen/dart_options.pb.dart b/protoc_plugin/lib/src/gen/dart_options.pb.dart index b582465bf..5534342aa 100644 --- a/protoc_plugin/lib/src/gen/dart_options.pb.dart +++ b/protoc_plugin/lib/src/gen/dart_options.pb.dart @@ -125,8 +125,7 @@ class Imports extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Imports', package: const $pb.PackageName(_omitMessageNames ? '' : 'dart_options'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, + ..pc(1, _omitFieldNames ? '' : 'mixins', $pb.PbFieldType.PM, subBuilder: DartMixin.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/client.pb.dart b/protoc_plugin/lib/src/gen/google/api/client.pb.dart index 79b1a177a..4660db8c8 100644 --- a/protoc_plugin/lib/src/gen/google/api/client.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/client.pb.dart @@ -403,8 +403,8 @@ class Publishing extends $pb.GeneratedMessage { ClientLibraryOrganization.CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED, valueOf: ClientLibraryOrganization.valueOf, enumValues: ClientLibraryOrganization.values) - ..pc(109, _omitFieldNames ? '' : 'librarySettings', - $pb.PbFieldType.PM, + ..pc( + 109, _omitFieldNames ? '' : 'librarySettings', $pb.PbFieldType.PM, subBuilder: ClientLibrarySettings.create) ..aOS(110, _omitFieldNames ? '' : 'protoReferenceDocumentationUri') ..aOS(111, _omitFieldNames ? '' : 'restReferenceDocumentationUri') @@ -1313,8 +1313,8 @@ class MethodSettings_LongRunning extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM<$0.Duration>(1, _omitFieldNames ? '' : 'initialPollDelay', subBuilder: $0.Duration.create) - ..a<$core.double>(2, _omitFieldNames ? '' : 'pollDelayMultiplier', - $pb.PbFieldType.OF) + ..a<$core.double>( + 2, _omitFieldNames ? '' : 'pollDelayMultiplier', $pb.PbFieldType.OF) ..aOM<$0.Duration>(3, _omitFieldNames ? '' : 'maxPollDelay', subBuilder: $0.Duration.create) ..aOM<$0.Duration>(4, _omitFieldNames ? '' : 'totalPollTimeout', diff --git a/protoc_plugin/lib/src/gen/google/api/http.pb.dart b/protoc_plugin/lib/src/gen/google/api/http.pb.dart index bf3b4b687..2fa07e333 100644 --- a/protoc_plugin/lib/src/gen/google/api/http.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/http.pb.dart @@ -44,8 +44,7 @@ class Http extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Http', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc( - 1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, + ..pc(1, _omitFieldNames ? '' : 'rules', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOB(2, _omitFieldNames ? '' : 'fullyDecodeReservedExpansion') ..hasRequiredFields = false; @@ -417,8 +416,8 @@ class HttpRule extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'body') ..aOM(8, _omitFieldNames ? '' : 'custom', subBuilder: CustomHttpPattern.create) - ..pc(11, _omitFieldNames ? '' : 'additionalBindings', - $pb.PbFieldType.PM, + ..pc( + 11, _omitFieldNames ? '' : 'additionalBindings', $pb.PbFieldType.PM, subBuilder: HttpRule.create) ..aOS(12, _omitFieldNames ? '' : 'responseBody') ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart index 64ac278ad..c8c7627e3 100644 --- a/protoc_plugin/lib/src/gen/google/api/routing.pb.dart +++ b/protoc_plugin/lib/src/gen/google/api/routing.pb.dart @@ -398,8 +398,8 @@ class RoutingRule extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'RoutingRule', package: const $pb.PackageName(_omitMessageNames ? '' : 'google.api'), createEmptyInstance: create) - ..pc(2, _omitFieldNames ? '' : 'routingParameters', - $pb.PbFieldType.PM, + ..pc( + 2, _omitFieldNames ? '' : 'routingParameters', $pb.PbFieldType.PM, subBuilder: RoutingParameter.create) ..hasRequiredFields = false; diff --git a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart index ec22fe316..023287aa7 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/compiler/plugin.pb.dart @@ -51,12 +51,9 @@ class Version extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'major', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'minor', $pb.PbFieldType.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'patch', $pb.PbFieldType.O3) ..aOS(4, _omitFieldNames ? '' : 'suffix') ..hasRequiredFields = false; @@ -159,9 +156,7 @@ class CodeGeneratorRequest extends $pb.GeneratedMessage { 15, _omitFieldNames ? '' : 'protoFile', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create) ..pc<$0.FileDescriptorProto>( - 17, - _omitFieldNames ? '' : 'sourceFileDescriptors', - $pb.PbFieldType.PM, + 17, _omitFieldNames ? '' : 'sourceFileDescriptors', $pb.PbFieldType.PM, subBuilder: $0.FileDescriptorProto.create); @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') @@ -428,8 +423,8 @@ class CodeGeneratorResponse extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'google.protobuf.compiler'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'error') - ..a<$fixnum.Int64>(2, _omitFieldNames ? '' : 'supportedFeatures', - $pb.PbFieldType.OU6, + ..a<$fixnum.Int64>( + 2, _omitFieldNames ? '' : 'supportedFeatures', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..a<$core.int>( 3, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.O3) diff --git a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart index 651b2c0cb..fe6bf4716 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/descriptor.pb.dart @@ -147,13 +147,12 @@ class FileDescriptorProto extends $pb.GeneratedMessage { subBuilder: FileOptions.create) ..aOM(9, _omitFieldNames ? '' : 'sourceCodeInfo', subBuilder: SourceCodeInfo.create) - ..p<$core.int>(10, _omitFieldNames ? '' : 'publicDependency', - $pb.PbFieldType.P3) + ..p<$core.int>( + 10, _omitFieldNames ? '' : 'publicDependency', $pb.PbFieldType.P3) ..p<$core.int>( 11, _omitFieldNames ? '' : 'weakDependency', $pb.PbFieldType.P3) ..aOS(12, _omitFieldNames ? '' : 'syntax') - ..e( - 14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e(14, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -312,8 +311,7 @@ class DescriptorProto_ExtensionRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: ExtensionRangeOptions.create); @@ -401,8 +399,7 @@ class DescriptorProto_ReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @@ -635,8 +632,7 @@ class ExtensionRangeOptions_Declaration extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOS(2, _omitFieldNames ? '' : 'fullName') ..aOS(3, _omitFieldNames ? '' : 'type') ..aOB(5, _omitFieldNames ? '' : 'reserved') @@ -766,8 +762,8 @@ class ExtensionRangeOptions extends $pb.GeneratedMessage { enumValues: ExtensionRangeOptions_VerificationState.values) ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -876,8 +872,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') ..aOS(2, _omitFieldNames ? '' : 'extendee') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..e( 4, _omitFieldNames ? '' : 'label', $pb.PbFieldType.OE, defaultOrMaker: FieldDescriptorProto_Label.LABEL_OPTIONAL, @@ -892,8 +887,7 @@ class FieldDescriptorProto extends $pb.GeneratedMessage { ..aOS(7, _omitFieldNames ? '' : 'defaultValue') ..aOM(8, _omitFieldNames ? '' : 'options', subBuilder: FieldOptions.create) - ..a<$core.int>( - 9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) + ..a<$core.int>(9, _omitFieldNames ? '' : 'oneofIndex', $pb.PbFieldType.O3) ..aOS(10, _omitFieldNames ? '' : 'jsonName') ..aOB(17, _omitFieldNames ? '' : 'proto3Optional'); @@ -1166,8 +1160,7 @@ class EnumDescriptorProto_EnumReservedRange extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..a<$core.int>( - 1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) + ..a<$core.int>(1, _omitFieldNames ? '' : 'start', $pb.PbFieldType.O3) ..a<$core.int>(2, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..hasRequiredFields = false; @@ -1362,8 +1355,7 @@ class EnumValueDescriptorProto extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(1, _omitFieldNames ? '' : 'name') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'number', $pb.PbFieldType.O3) ..aOM(3, _omitFieldNames ? '' : 'options', subBuilder: EnumValueOptions.create); @@ -1725,8 +1717,8 @@ class FileOptions extends $pb.GeneratedMessage { ..aOS(45, _omitFieldNames ? '' : 'rubyPackage') ..aOM(50, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2059,8 +2051,8 @@ class MessageOptions extends $pb.GeneratedMessage { ..aOB(11, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(12, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2237,8 +2229,7 @@ class FieldOptions_EditionDefault extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOS(2, _omitFieldNames ? '' : 'value') - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2319,19 +2310,18 @@ class FieldOptions_FeatureSupport extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e(1, _omitFieldNames ? '' : 'editionIntroduced', - $pb.PbFieldType.OE, + ..e( + 1, _omitFieldNames ? '' : 'editionIntroduced', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e(2, _omitFieldNames ? '' : 'editionDeprecated', - $pb.PbFieldType.OE, + ..e( + 2, _omitFieldNames ? '' : 'editionDeprecated', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) ..aOS(3, _omitFieldNames ? '' : 'deprecationWarning') - ..e( - 4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, + ..e(4, _omitFieldNames ? '' : 'editionRemoved', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -2485,16 +2475,16 @@ class FieldOptions extends $pb.GeneratedMessage { valueOf: FieldOptions_OptionTargetType.valueOf, enumValues: FieldOptions_OptionTargetType.values, defaultEnumValue: FieldOptions_OptionTargetType.TARGET_TYPE_UNKNOWN) - ..pc(20, - _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, + ..pc( + 20, _omitFieldNames ? '' : 'editionDefaults', $pb.PbFieldType.PM, subBuilder: FieldOptions_EditionDefault.create) ..aOM(21, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) ..aOM( 22, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2723,8 +2713,8 @@ class OneofOptions extends $pb.GeneratedMessage { createEmptyInstance: create) ..aOM(1, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2809,8 +2799,8 @@ class EnumOptions extends $pb.GeneratedMessage { ..aOB(6, _omitFieldNames ? '' : 'deprecatedLegacyJsonFieldConflicts') ..aOM(7, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -2937,8 +2927,8 @@ class EnumValueOptions extends $pb.GeneratedMessage { ..aOM( 4, _omitFieldNames ? '' : 'featureSupport', subBuilder: FieldOptions_FeatureSupport.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3051,8 +3041,8 @@ class ServiceOptions extends $pb.GeneratedMessage { ..aOB(33, _omitFieldNames ? '' : 'deprecated') ..aOM(34, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3141,15 +3131,15 @@ class MethodOptions extends $pb.GeneratedMessage { const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) ..aOB(33, _omitFieldNames ? '' : 'deprecated') - ..e(34, - _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, + ..e( + 34, _omitFieldNames ? '' : 'idempotencyLevel', $pb.PbFieldType.OE, defaultOrMaker: MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN, valueOf: MethodOptions_IdempotencyLevel.valueOf, enumValues: MethodOptions_IdempotencyLevel.values) ..aOM(35, _omitFieldNames ? '' : 'features', subBuilder: FeatureSet.create) - ..pc(999, _omitFieldNames ? '' : 'uninterpretedOption', - $pb.PbFieldType.PM, + ..pc( + 999, _omitFieldNames ? '' : 'uninterpretedOption', $pb.PbFieldType.PM, subBuilder: UninterpretedOption.create) ..hasExtensions = true; @@ -3340,8 +3330,8 @@ class UninterpretedOption extends $pb.GeneratedMessage { 2, _omitFieldNames ? '' : 'name', $pb.PbFieldType.PM, subBuilder: UninterpretedOption_NamePart.create) ..aOS(3, _omitFieldNames ? '' : 'identifierValue') - ..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'positiveIntValue', - $pb.PbFieldType.OU6, + ..a<$fixnum.Int64>( + 4, _omitFieldNames ? '' : 'positiveIntValue', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aInt64(5, _omitFieldNames ? '' : 'negativeIntValue') ..a<$core.double>( @@ -3534,9 +3524,7 @@ class FeatureSet extends $pb.GeneratedMessage { valueOf: FeatureSet_EnumType.valueOf, enumValues: FeatureSet_EnumType.values) ..e( - 3, - _omitFieldNames ? '' : 'repeatedFieldEncoding', - $pb.PbFieldType.OE, + 3, _omitFieldNames ? '' : 'repeatedFieldEncoding', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_RepeatedFieldEncoding.REPEATED_FIELD_ENCODING_UNKNOWN, valueOf: FeatureSet_RepeatedFieldEncoding.valueOf, @@ -3556,16 +3544,14 @@ class FeatureSet extends $pb.GeneratedMessage { defaultOrMaker: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN, valueOf: FeatureSet_JsonFormat.valueOf, enumValues: FeatureSet_JsonFormat.values) - ..e(7, - _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, + ..e( + 7, _omitFieldNames ? '' : 'enforceNamingStyle', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN, valueOf: FeatureSet_EnforceNamingStyle.valueOf, enumValues: FeatureSet_EnforceNamingStyle.values) ..e( - 8, - _omitFieldNames ? '' : 'defaultSymbolVisibility', - $pb.PbFieldType.OE, + 8, _omitFieldNames ? '' : 'defaultSymbolVisibility', $pb.PbFieldType.OE, defaultOrMaker: FeatureSet_VisibilityFeature_DefaultSymbolVisibility .DEFAULT_SYMBOL_VISIBILITY_UNKNOWN, valueOf: FeatureSet_VisibilityFeature_DefaultSymbolVisibility.valueOf, @@ -3703,8 +3689,7 @@ class FeatureSetDefaults_FeatureSetEditionDefault extends $pb.GeneratedMessage { package: const $pb.PackageName(_omitMessageNames ? '' : 'google.protobuf'), createEmptyInstance: create) - ..e( - 3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, + ..e(3, _omitFieldNames ? '' : 'edition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) @@ -3808,13 +3793,11 @@ class FeatureSetDefaults extends $pb.GeneratedMessage { ..pc( 1, _omitFieldNames ? '' : 'defaults', $pb.PbFieldType.PM, subBuilder: FeatureSetDefaults_FeatureSetEditionDefault.create) - ..e( - 4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, + ..e(4, _omitFieldNames ? '' : 'minimumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values) - ..e( - 5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, + ..e(5, _omitFieldNames ? '' : 'maximumEdition', $pb.PbFieldType.OE, defaultOrMaker: Edition.EDITION_UNKNOWN, valueOf: Edition.valueOf, enumValues: Edition.values); @@ -4163,8 +4146,7 @@ class GeneratedCodeInfo_Annotation extends $pb.GeneratedMessage { createEmptyInstance: create) ..p<$core.int>(1, _omitFieldNames ? '' : 'path', $pb.PbFieldType.K3) ..aOS(2, _omitFieldNames ? '' : 'sourceFile') - ..a<$core.int>( - 3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'begin', $pb.PbFieldType.O3) ..a<$core.int>(4, _omitFieldNames ? '' : 'end', $pb.PbFieldType.O3) ..e( 5, _omitFieldNames ? '' : 'semantic', $pb.PbFieldType.OE, diff --git a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart index d58a9e1b8..5cba2308c 100644 --- a/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart +++ b/protoc_plugin/lib/src/gen/google/protobuf/duration.pb.dart @@ -105,8 +105,7 @@ class Duration extends $pb.GeneratedMessage with $mixin.DurationMixin { toProto3Json: $mixin.DurationMixin.toProto3JsonHelper, fromProto3Json: $mixin.DurationMixin.fromProto3JsonHelper) ..aInt64(1, _omitFieldNames ? '' : 'seconds') - ..a<$core.int>( - 2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) + ..a<$core.int>(2, _omitFieldNames ? '' : 'nanos', $pb.PbFieldType.O3) ..hasRequiredFields = false; @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.') diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index d0464a069..af3ec5921 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -291,11 +291,9 @@ class ProtobufField { } else if (makeDefault == null) { switch (type) { case '$coreImportPrefix.String': - if (typeConstant == - '$protobufImportPrefix.PbFieldType.OS') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OS') { invocation = 'aOS'; - } else if (typeConstant == - '$protobufImportPrefix.PbFieldType.QS') { + } else if (typeConstant == '$protobufImportPrefix.PbFieldType.QS') { invocation = 'aQS'; } else { invocation = 'a<$type>'; @@ -303,8 +301,7 @@ class ProtobufField { } break; case '$coreImportPrefix.bool': - if (typeConstant == - '$protobufImportPrefix.PbFieldType.OB') { + if (typeConstant == '$protobufImportPrefix.PbFieldType.OB') { invocation = 'aOB'; } else { invocation = 'a<$type>'; From 6763a791e0ba395d3a98e00ed583879e4ecce297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 22 Jul 2025 11:55:53 +0100 Subject: [PATCH 19/22] Use the old library with Wasm --- protobuf/lib/src/protobuf/json/json.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf/lib/src/protobuf/json/json.dart b/protobuf/lib/src/protobuf/json/json.dart index f9bc916e7..5c675916b 100644 --- a/protobuf/lib/src/protobuf/json/json.dart +++ b/protobuf/lib/src/protobuf/json/json.dart @@ -10,7 +10,7 @@ import '../consts.dart'; import '../internal.dart'; import '../utils.dart'; -export 'json_vm.dart' if (dart.library.js_interop) 'json_web.dart'; +export 'json_vm.dart' if (dart.library.html) 'json_web.dart'; Map writeToJsonMap(FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { From d7f09dc107aa3736d99b4b5449374c6ef7ef7789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Wed, 23 Jul 2025 11:18:18 +0100 Subject: [PATCH 20/22] Update CHANGELOG --- protobuf/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md index a987ef80d..209c21b96 100644 --- a/protobuf/CHANGELOG.md +++ b/protobuf/CHANGELOG.md @@ -8,8 +8,12 @@ * Some of the private `PbFieldType` members are made public, to allow using them in internal libraries. This type is for internal use only. ([#1027]) +* Improve performance of `GeneratedMessage` members: `writeToJsonMap`, + `writeToJson`, `mergeFromJson`, `mergeFromJsonMap`. ([#1028]) + [#1026]: https://github.com/google/protobuf.dart/pull/1026 [#1027]: https://github.com/google/protobuf.dart/pull/1027 +[#1028]: https://github.com/google/protobuf.dart/pull/1028 ## 4.1.1 From 7df422f21b2e283715e562023818e3011386f436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 28 Jul 2025 10:13:23 +0100 Subject: [PATCH 21/22] Address some of the comments --- protobuf/lib/src/protobuf/json/json.dart | 3 +++ protobuf/lib/src/protobuf/json/json_vm.dart | 2 +- protobuf/lib/src/protobuf/json/json_web.dart | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/protobuf/lib/src/protobuf/json/json.dart b/protobuf/lib/src/protobuf/json/json.dart index 5c675916b..05d1ac11e 100644 --- a/protobuf/lib/src/protobuf/json/json.dart +++ b/protobuf/lib/src/protobuf/json/json.dart @@ -10,6 +10,9 @@ import '../consts.dart'; import '../internal.dart'; import '../utils.dart'; +// Use json_vm.dart with VM and dart2wasm, json_web.dart with dart2js. +// json_web.dart uses JS interop for parsing, and JS interop is too slow on +// Wasm. VM's patch performs better in Wasm. export 'json_vm.dart' if (dart.library.html) 'json_web.dart'; Map writeToJsonMap(FieldSet fs) { diff --git a/protobuf/lib/src/protobuf/json/json_vm.dart b/protobuf/lib/src/protobuf/json/json_vm.dart index 8f09e7f7d..831756abd 100644 --- a/protobuf/lib/src/protobuf/json/json_vm.dart +++ b/protobuf/lib/src/protobuf/json/json_vm.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2025, 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. diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index 6b8e1e80f..a36315992 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2025, 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. From 22968eca177c3081738574f58bc3f766f5a36e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Mon, 28 Jul 2025 11:16:26 +0100 Subject: [PATCH 22/22] Make members private --- protobuf/lib/src/protobuf/json/json_web.dart | 78 +++++++++++--------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index a36315992..b0a8e2ec7 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -13,36 +13,40 @@ import '../internal.dart'; import '../utils.dart'; @JS('JSON') -extension type JSON._(JSObject _) implements JSObject { - external static JSString stringify(JSObject value); - external static JSAny? parse(JSString text); +extension type _JSON._(JSObject _) implements JSObject { + @JS('JSON.stringify') + external static JSString _stringify(JSObject value); + + @JS('JSON.parse') + external static JSAny? _parse(JSString text); } @JS('Number') -extension type Number._(JSObject _) implements JSObject { - external static bool isInteger(JSAny value); +extension type _Number._(JSObject _) implements JSObject { + @JS('Number.isInteger') + external static bool _isInteger(JSAny value); } @JS('Object.keys') -external JSArray objectKeys(JSObject obj); +external JSArray _objectKeys(JSObject obj); @JS('Object.prototype') -external JSObject get objectPrototype; +external JSObject get _objectPrototype; @JS('Object.getPrototypeOf') -external JSObject getPrototypeOf(JSAny obj); +external JSObject _getPrototypeOf(JSAny obj); extension on JSAny { /// Returns this typed as [T] while omitting the `as` cast. For use after an /// `isA` check. @pragma('dart2js:as:trust') @pragma('dart2js:prefer-inline') - T as() => this as T; + T _as() => this as T; } String writeToJsonString(FieldSet fs) { final rawJs = _writeToRawJs(fs); - return JSON.stringify(rawJs).toDart; + return _JSON._stringify(rawJs).toDart; } JSObject _writeToRawJs(FieldSet fs) { @@ -184,14 +188,14 @@ void mergeFromJsonString( ) { final JSAny? parsed; try { - parsed = JSON.parse(json.toJS); + parsed = _JSON._parse(json.toJS); } catch (e) { throw FormatException(e.toString()); } if (parsed == null || !parsed.isA()) { throw ArgumentError.value(json, 'json', 'Does not parse to a JSON object.'); } - _mergeFromRawJsMap(fs, parsed.as(), registry); + _mergeFromRawJsMap(fs, parsed._as(), registry); } void _mergeFromRawJsMap( @@ -202,7 +206,7 @@ void _mergeFromRawJsMap( fs.ensureWritable(); final meta = fs.meta; - final keys = objectKeys(json); + final keys = _objectKeys(json); final length = keys.length; for (var i = 0; i < length; i++) { final jsKey = keys[i]; @@ -353,16 +357,16 @@ Object? _convertRawJsValue( switch (PbFieldType.baseType(fieldType)) { case PbFieldType.BOOL_BIT: if (value.isA()) { - return value.as().toDart; + return value._as().toDart; } else if (value.isA()) { - final dartStr = value.as().toDart; + final dartStr = value._as().toDart; if (dartStr == 'true') { return true; } else if (dartStr == 'false') { return false; } } else if (value.isA()) { - final dartNum = value.as().toDartDouble; + final dartNum = value._as().toDartDouble; if (dartNum == 1) { return true; } else if (dartNum == 0) { @@ -372,58 +376,58 @@ Object? _convertRawJsValue( expectedType = 'bool (true, false, "true", "false", 1, 0)'; case PbFieldType.BYTES_BIT: if (value.isA()) { - return base64Decode(value.as().toDart); + return base64Decode(value._as().toDart); } expectedType = 'Base64 String'; case PbFieldType.STRING_BIT: if (value.isA()) { - return value.as().toDart; + return value._as().toDart; } expectedType = 'String'; case PbFieldType.FLOAT_BIT: case PbFieldType.DOUBLE_BIT: // Allow quoted values, although we don't emit them. if (value.isA()) { - final jsNum = value.as(); - return Number.isInteger(jsNum) ? jsNum.toDartInt : jsNum.toDartDouble; + final jsNum = value._as(); + return _Number._isInteger(jsNum) ? jsNum.toDartInt : jsNum.toDartDouble; } else if (value.isA()) { - return double.parse(value.as().toDart); + return double.parse(value._as().toDart); } expectedType = 'num or stringified num'; case PbFieldType.ENUM_BIT: // Allow quoted values, although we don't emit them. if (value.isA()) { - value = int.parse(value.as().toDart).toJS; + value = int.parse(value._as().toDart).toJS; } - if (Number.isInteger(value)) { + if (_Number._isInteger(value)) { // The following call will return null if the enum value is unknown. // In that case, we want the caller to ignore this value, so we return // null from this method as well. return meta.decodeEnum( tagNumber, registry, - value.as().toDartInt, + value._as().toDartInt, ); } expectedType = 'int or stringified int'; case PbFieldType.INT32_BIT: case PbFieldType.SINT32_BIT: case PbFieldType.SFIXED32_BIT: - if (Number.isInteger(value)) { - return value.as().toDartInt; + if (_Number._isInteger(value)) { + return value._as().toDartInt; } if (value.isA()) { - return int.parse(value.as().toDart); + return int.parse(value._as().toDart); } expectedType = 'int or stringified int'; case PbFieldType.UINT32_BIT: case PbFieldType.FIXED32_BIT: int? validatedValue; - if (Number.isInteger(value)) { - validatedValue = value.as().toDartInt; + if (_Number._isInteger(value)) { + validatedValue = value._as().toDartInt; } if (value.isA()) { - validatedValue = int.parse(value.as().toDart); + validatedValue = int.parse(value._as().toDart); } if (validatedValue != null && validatedValue < 0) { validatedValue += 2 * (1 << 31); @@ -435,18 +439,22 @@ Object? _convertRawJsValue( case PbFieldType.UINT64_BIT: case PbFieldType.FIXED64_BIT: case PbFieldType.SFIXED64_BIT: - if (Number.isInteger(value)) { - return Int64(value.as().toDartInt); + if (_Number._isInteger(value)) { + return Int64(value._as().toDartInt); } if (value.isA()) { - return Int64.parseInt(value.as().toDart); + return Int64.parseInt(value._as().toDart); } expectedType = 'int or stringified int'; case PbFieldType.GROUP_BIT: case PbFieldType.MESSAGE_BIT: - if (getPrototypeOf(value).strictEquals(objectPrototype).toDart) { + if (_getPrototypeOf(value).strictEquals(_objectPrototype).toDart) { final subMessage = meta.makeEmptyMessage(tagNumber, registry); - _mergeFromRawJsMap(subMessage.fieldSet, value.as(), registry); + _mergeFromRawJsMap( + subMessage.fieldSet, + value._as(), + registry, + ); return subMessage; } expectedType = 'nested message or group';