Make `MapFieldInfo` key and value types non-nullable (#600)
diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index 736058d..890daaf 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart
@@ -66,8 +66,8 @@ void addMapField<K, V>( int tagNumber, String name, - int? keyFieldType, - int? valueFieldType, + int keyFieldType, + int valueFieldType, BuilderInfo mapEntryBuilderInfo, CreateBuilderFunc? valueCreator, {ProtobufEnum? defaultEnumValue, @@ -221,8 +221,8 @@ // Map field. void m<K, V>(int tagNumber, String name, {String? entryClassName, - int? keyFieldType, - int? valueFieldType, + required int keyFieldType, + required int valueFieldType, CreateBuilderFunc? valueCreator, ValueOfFunc? valueOf, List<ProtobufEnum>? enumValues,
diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index 8c3fac3..196b1fd 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart
@@ -148,7 +148,7 @@ } else if (field is MapFieldInfo) { final messageMap = message._fieldSet._values[field.index!]; if (messageMap == null) continue; - if (_isGroupOrMessage(field.valueFieldType!)) { + if (_isGroupOrMessage(field.valueFieldType)) { for (var key in messageMap.keys) { final GeneratedMessage value = messageMap[key]; final reparsedValue = _reparseMessage(value, extensionRegistry);
diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 7a1591b..637ed96 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart
@@ -229,13 +229,13 @@ /// integer type or `string`, and the type cannot be `repeated`. /// /// The `int` value is interpreted the same way as [FieldInfo.type]. - final int? keyFieldType; + final int keyFieldType; /// Value type of the map. Per proto2 and proto3 specs, this can be any type /// other than `map`, and the type cannot be `repeated`. /// /// The `int` value is interpreted the same way as [FieldInfo.type]. - final int? valueFieldType; + final int valueFieldType; /// Creates a new empty instance of the value type. ///
diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index 2316d24..5044e86 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart
@@ -806,7 +806,7 @@ if (fi!.isMapField) { var f = fi as MapFieldInfo<dynamic, dynamic>; - mustClone = _isGroupOrMessage(f.valueFieldType!); + mustClone = _isGroupOrMessage(f.valueFieldType); var map = f._ensureMapField(meta, this) as PbMap<dynamic, dynamic>; if (mustClone) { for (MapEntry entry in fieldValue.entries) {
diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index c2c7368..f42d12e 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart
@@ -45,9 +45,9 @@ List _writeMap(dynamic fieldValue, MapFieldInfo fi) => List.from(fieldValue.entries.map((MapEntry e) => { - '${PbMap._keyFieldNumber}': convertToMap(e.key, fi.keyFieldType!), + '${PbMap._keyFieldNumber}': convertToMap(e.key, fi.keyFieldType), '${PbMap._valueFieldNumber}': - convertToMap(e.value, fi.valueFieldType!) + convertToMap(e.value, fi.valueFieldType) })); var result = <String, dynamic>{}; @@ -131,14 +131,14 @@ entryFieldSet, jsonEntry['${PbMap._keyFieldNumber}'], PbMap._keyFieldNumber, - fi.keyFieldType!, + fi.keyFieldType, registry); var convertedValue = _convertJsonValue( entryMeta, entryFieldSet, jsonEntry['${PbMap._valueFieldNumber}'], PbMap._valueFieldNumber, - fi.valueFieldType!, + 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
diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 7449856..712f812 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart
@@ -9,13 +9,13 @@ /// integer type or `string`, and the type cannot be `repeated`. /// /// The `int` value is interpreted the same way as [FieldInfo.type]. - final int? keyFieldType; + final int keyFieldType; /// Value type of the map. Per proto2 and proto3 specs, this can be any type /// other than `map`, and the type cannot be `repeated`. /// /// The `int` value is interpreted the same way as [FieldInfo.type]. - final int? valueFieldType; + final int valueFieldType; static const int _keyFieldNumber = 1; static const int _valueFieldNumber = 2; @@ -119,7 +119,7 @@ PbMap freeze() { _isReadonly = true; - if (_isGroupOrMessage(valueFieldType!)) { + if (_isGroupOrMessage(valueFieldType)) { for (var subMessage in values as Iterable<GeneratedMessage>) { subMessage.freeze(); }
diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index 6d35db9..ade908b 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart
@@ -96,7 +96,7 @@ if (fieldInfo.isMapField) { jsonValue = (value as PbMap).map((key, entryValue) { var mapEntryInfo = fieldInfo as MapFieldInfo; - return MapEntry(convertToMapKey(key, mapEntryInfo.keyFieldType!), + return MapEntry(convertToMapKey(key, mapEntryInfo.keyFieldType), valueToProto3Json(entryValue, mapEntryInfo.valueFieldType)); }); } else if (fieldInfo.isRepeated) { @@ -366,7 +366,7 @@ throw context.parseException('Expected a String key', subKey); } context.addMapIndex(subKey); - fieldValues[decodeMapKey(subKey, mapFieldInfo.keyFieldType!)] = + fieldValues[decodeMapKey(subKey, mapFieldInfo.keyFieldType)] = convertProto3JsonValue( subValue, mapFieldInfo.valueFieldInfo); context.popIndex();