diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index c0db66caaf6..b6e036a0612 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.2.12 + +* Updates serialization to use lists instead of maps to improve performance. + ## 4.2.11 * [swift] Fixes compressed list data types. diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index f893f5733cc..565c0ba973d 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -108,7 +108,7 @@ void _writeCodecSource(Indent indent, Api api, Root root) { indent.write('case ${customClass.enumeration}:'); indent.writeScoped('', '', () { indent.writeln( - 'return flutter::CustomEncodableValue(${customClass.name}(std::get(ReadValue(stream))));'); + 'return flutter::CustomEncodableValue(${customClass.name}(std::get(ReadValue(stream))));'); }); } indent.write('default:'); @@ -131,7 +131,7 @@ void _writeCodecSource(Indent indent, Api api, Root root) { indent.scoped('{', '}', () { indent.writeln('stream->WriteByte(${customClass.enumeration});'); indent.writeln( - 'WriteValue(std::any_cast<${customClass.name}>(*custom_value).ToEncodableMap(), stream);'); + 'WriteValue(flutter::EncodableValue(std::any_cast<${customClass.name}>(*custom_value).ToEncodableList()), stream);'); indent.writeln('return;'); }); } @@ -207,7 +207,7 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, indent.scoped('{', '};', () { indent.scoped(' public:', '', () { indent.writeln('${klass.name}();'); - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); final HostDatatype baseDatatype = getFieldHostDatatype( @@ -232,8 +232,8 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, }); indent.scoped(' private:', '', () { - indent.writeln('${klass.name}(flutter::EncodableMap map);'); - indent.writeln('flutter::EncodableMap ToEncodableMap() const;'); + indent.writeln('${klass.name}(const flutter::EncodableList& list);'); + indent.writeln('flutter::EncodableList ToEncodableList() const;'); for (final Class friend in root.classes) { if (friend != klass && friend.fields.any( @@ -251,7 +251,7 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, indent.writeln('friend class $testFriend;'); } - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, root.classes, @@ -280,7 +280,7 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { indent.addln(''); // Getters and setters. - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype(field, root.classes, root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); final String instanceVariableName = _makeInstanceVariableName(field); @@ -317,10 +317,11 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { } // Serialization. - indent.write('flutter::EncodableMap ${klass.name}::ToEncodableMap() const '); + indent + .write('flutter::EncodableList ${klass.name}::ToEncodableList() const '); indent.scoped('{', '}', () { - indent.scoped('return flutter::EncodableMap{', '};', () { - for (final NamedType field in klass.fields) { + indent.scoped('return flutter::EncodableList{', '};', () { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, root.classes, @@ -329,12 +330,12 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { final String instanceVariable = _makeInstanceVariableName(field); - final String encodableKey = 'flutter::EncodableValue("${field.name}")'; String encodableValue = ''; if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { final String operator = field.type.isNullable ? '->' : '.'; - encodableValue = '$instanceVariable${operator}ToEncodableMap()'; + encodableValue = + 'flutter::EncodableValue($instanceVariable${operator}ToEncodableList())'; } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { final String nonNullValue = @@ -351,7 +352,7 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { '$instanceVariable ? $encodableValue : flutter::EncodableValue()'; } - indent.writeln('{$encodableKey, $encodableValue},'); + indent.writeln('$encodableValue,'); } }); }); @@ -362,16 +363,17 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { indent.addln(''); // Deserialization. - indent.write('${klass.name}::${klass.name}(flutter::EncodableMap map) '); + indent.write( + '${klass.name}::${klass.name}(const flutter::EncodableList& list) '); indent.scoped('{', '}', () { - for (final NamedType field in klass.fields) { + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { final String instanceVariableName = _makeInstanceVariableName(field); final String pointerFieldName = '${_pointerPrefix}_${_makeVariableName(field)}'; final String encodableFieldName = '${_encodablePrefix}_${_makeVariableName(field)}'; - indent.writeln( - 'auto& $encodableFieldName = map.at(flutter::EncodableValue("${field.name}"));'); + indent.writeln('auto& $encodableFieldName = list[$index];'); if (rootEnumNameSet.contains(field.type.baseName)) { indent.writeln( 'if (const int32_t* $pointerFieldName = std::get_if(&$encodableFieldName))\t$instanceVariableName = (${field.type.baseName})*$pointerFieldName;'); @@ -392,7 +394,7 @@ else if (const int64_t* ${pointerFieldName}_64 = std::get_if(&$encodabl .map((Class x) => x.name) .contains(field.type.baseName)) { indent.write( - 'if (const flutter::EncodableMap* $pointerFieldName = std::get_if(&$encodableFieldName)) '); + 'if (const flutter::EncodableList* $pointerFieldName = std::get_if(&$encodableFieldName)) '); indent.scoped('{', '}', () { indent.writeln( '$instanceVariableName = ${hostDatatype.datatype}(*$pointerFieldName);'); @@ -405,7 +407,7 @@ else if (const int64_t* ${pointerFieldName}_64 = std::get_if(&$encodabl }); } } - } + }); }); indent.addln(''); } @@ -471,9 +473,9 @@ void _writeHostApiHeader(Indent indent, Api api, Root root) { indent.writeln( 'static void SetUp(flutter::BinaryMessenger* binary_messenger, ${api.name}* api);'); indent.writeln( - 'static flutter::EncodableMap WrapError(std::string_view error_message);'); + 'static flutter::EncodableList WrapError(std::string_view error_message);'); indent.writeln( - 'static flutter::EncodableMap WrapError(const FlutterError& error);'); + 'static flutter::EncodableList WrapError(const FlutterError& error);'); }); indent.scoped(' protected:', '', () { indent.writeln('${api.name}() = default;'); @@ -514,7 +516,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.write( 'channel->SetMessageHandler([api](const flutter::EncodableValue& message, const flutter::MessageReply& reply) '); indent.scoped('{', '});', () { - indent.writeln('flutter::EncodableMap wrapped;'); + indent.writeln('flutter::EncodableList wrapped;'); indent.write('try '); indent.scoped('{', '}', () { final List methodArgument = []; @@ -588,8 +590,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.write('if ($encodableArgName.IsNull()) '); indent.scoped('{', '}', () { indent.writeln( - 'wrapped.emplace(flutter::EncodableValue("${Keys.error}"), WrapError("$argName unexpectedly null."));'); - indent.writeln('reply(wrapped);'); + 'reply(WrapError("$argName unexpectedly null."));'); indent.writeln('return;'); }); } @@ -605,14 +606,10 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { final String errorGetter; final String prefix = (reply != '') ? '\t' : ''; - const String resultKey = - 'flutter::EncodableValue("${Keys.result}")'; - const String errorKey = - 'flutter::EncodableValue("${Keys.error}")'; const String nullValue = 'flutter::EncodableValue()'; if (returnType.isVoid) { elseBody = - '$prefix\twrapped.emplace($resultKey, $nullValue);${indent.newline}'; + '$prefix\twrapped.push_back($nullValue);${indent.newline}'; ifCondition = 'output.has_value()'; errorGetter = 'value'; } else { @@ -631,24 +628,23 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { elseBody = ''' $prefix\tauto output_optional = $extractedValue; $prefix\tif (output_optional) { -$prefix\t\twrapped.emplace($resultKey, $wrapperType(std::move(output_optional).value())); +$prefix\t\twrapped.push_back($wrapperType(std::move(output_optional).value())); $prefix\t} else { -$prefix\t\twrapped.emplace($resultKey, $nullValue); +$prefix\t\twrapped.push_back($nullValue); $prefix\t}${indent.newline}'''; } else { elseBody = - '$prefix\twrapped.emplace($resultKey, $wrapperType($extractedValue));${indent.newline}'; + '$prefix\twrapped.push_back($wrapperType($extractedValue));${indent.newline}'; } ifCondition = 'output.has_error()'; errorGetter = 'error'; } return '${prefix}if ($ifCondition) {${indent.newline}' - '$prefix\twrapped.emplace($errorKey, WrapError(output.$errorGetter()));${indent.newline}' - '$prefix$reply' + '$prefix\twrapped = WrapError(output.$errorGetter());${indent.newline}' '$prefix} else {${indent.newline}' '$elseBody' - '$prefix$reply' - '$prefix}'; + '$prefix}' + '$prefix$reply'; } final HostDatatype returnType = getHostDatatype( @@ -675,8 +671,7 @@ $prefix\t}${indent.newline}'''; }); indent.write('catch (const std::exception& exception) '); indent.scoped('{', '}', () { - indent.writeln( - 'wrapped.emplace(flutter::EncodableValue("${Keys.error}"), WrapError(exception.what()));'); + indent.writeln('wrapped = WrapError(exception.what());'); if (method.isAsynchronous) { indent.writeln('reply(wrapped);'); } @@ -821,7 +816,7 @@ else if (const int64_t* ${pointerVariable}_64 = std::get_if(&args)) \t$output = *${pointerVariable}_64;'''); } else if (!isBuiltin) { indent.write( - 'if (const flutter::EncodableMap* $pointerVariable = std::get_if(&args)) '); + 'if (const flutter::EncodableList* $pointerVariable = std::get_if(&args)) '); indent.scoped('{', '}', () { indent.writeln('$output = $returnTypeName(*$pointerVariable);'); }); @@ -1064,12 +1059,10 @@ void generateCppHeader( indent, anEnum.documentationComments, _docCommentSpec); indent.write('enum class ${anEnum.name} '); indent.scoped('{', '};', () { - int index = 0; - for (final String member in anEnum.members) { + enumerate(anEnum.members, (int index, final String member) { indent.writeln( '$member = $index${index == anEnum.members.length - 1 ? '' : ','}'); - index++; - } + }); }); } @@ -1150,18 +1143,18 @@ void generateCppSource(CppOptions options, Root root, StringSink sink) { indent.addln(''); indent.format(''' -flutter::EncodableMap ${api.name}::WrapError(std::string_view error_message) { -\treturn flutter::EncodableMap({ -\t\t{flutter::EncodableValue("${Keys.errorMessage}"), flutter::EncodableValue(std::string(error_message))}, -\t\t{flutter::EncodableValue("${Keys.errorCode}"), flutter::EncodableValue("Error")}, -\t\t{flutter::EncodableValue("${Keys.errorDetails}"), flutter::EncodableValue()} +flutter::EncodableList ${api.name}::WrapError(std::string_view error_message) { +\treturn flutter::EncodableList({ +\t\tflutter::EncodableValue(std::string(error_message)), +\t\tflutter::EncodableValue("Error"), +\t\tflutter::EncodableValue() \t}); } -flutter::EncodableMap ${api.name}::WrapError(const FlutterError& error) { -\treturn flutter::EncodableMap({ -\t\t{flutter::EncodableValue("${Keys.errorMessage}"), flutter::EncodableValue(error.message())}, -\t\t{flutter::EncodableValue("${Keys.errorCode}"), flutter::EncodableValue(error.code())}, -\t\t{flutter::EncodableValue("${Keys.errorDetails}"), error.details()} +flutter::EncodableList ${api.name}::WrapError(const FlutterError& error) { +\treturn flutter::EncodableList({ +\t\tflutter::EncodableValue(error.message()), +\t\tflutter::EncodableValue(error.code()), +\t\terror.details() \t}); }'''); indent.addln(''); diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index f87297a91de..3edbe686777 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -73,22 +73,27 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) { assert(getCodecClasses(api, root).isNotEmpty); final Iterable codecClasses = getCodecClasses(api, root); indent.write('class $codecName extends $_standardMessageCodec'); - indent.scoped('{', '}', () { + indent.scoped(' {', '}', () { indent.writeln('const $codecName();'); indent.writeln('@override'); indent.write('void writeValue(WriteBuffer buffer, Object? value) '); indent.scoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.write('if (value is ${customClass.name}) '); + enumerate(codecClasses, (int index, final EnumeratedClass customClass) { + final String ifValue = 'if (value is ${customClass.name}) '; + if (index == 0) { + indent.write(''); + } + indent.add(ifValue); indent.scoped('{', '} else ', () { indent.writeln('buffer.putUint8(${customClass.enumeration});'); indent.writeln('writeValue(buffer, value.encode());'); - }); - } + }, addTrailingNewline: false); + }); indent.scoped('{', '}', () { indent.writeln('super.writeValue(buffer, value);'); }); }); + indent.writeln(''); indent.writeln('@override'); indent.write('Object? readValueOfType(int type, ReadBuffer buffer) '); indent.scoped('{', '}', () { @@ -101,8 +106,8 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) { 'return ${customClass.name}.decode(readValue(buffer)!);'); }); } - indent.write('default:'); - indent.writeScoped('', '', () { + indent.writeln('default:'); + indent.scoped('', '', () { indent.writeln('return super.readValueOfType(type, buffer);'); }); }); @@ -157,6 +162,14 @@ String _getMethodArgumentsSignature( /// static const MessageCodec codec = FooCodec(); /// Future add(int x, int y) async {...} /// } +/// +/// Messages will be sent and received in a list. +/// +/// If the message recieved was succesful, +/// the result will be contained at the 0'th index. +/// +/// If the message was a failure, the list will contain 3 items: +/// a code, a message, and details in that order. void _writeHostApi(DartOptions opt, Indent indent, Api api, Root root) { assert(api.location == ApiLocation.host); String codecName = _standardMessageCodec; @@ -173,7 +186,8 @@ void _writeHostApi(DartOptions opt, Indent indent, Api api, Root root) { /// Constructor for [${api.name}]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. -${api.name}({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; +${api.name}({BinaryMessenger? binaryMessenger}) +\t\t: _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; '''); @@ -212,38 +226,37 @@ final BinaryMessenger? _binaryMessenger; indent.writeln( 'final BasicMessageChannel channel = BasicMessageChannel('); indent.nest(2, () { - indent.writeln( - "'$channelName', codec, binaryMessenger: _binaryMessenger);", - ); + indent.writeln("'$channelName', codec,"); + indent.writeln('binaryMessenger: _binaryMessenger);'); }); final String returnType = _makeGenericTypeArguments(func.returnType); final String castCall = _makeGenericCastCall(func.returnType); - const String accessor = "replyMap['${Keys.result}']"; + const String accessor = 'replyList[0]'; final String nullHandler = func.returnType.isNullable ? (castCall.isEmpty ? '' : '?') : '!'; final String returnStatement = func.returnType.isVoid ? 'return;' : 'return ($accessor as $returnType?)$nullHandler$castCall;'; indent.format(''' -final Map? replyMap =\n\t\tawait channel.send($sendArgument) as Map?; -if (replyMap == null) { +final List? replyList = +\t\tawait channel.send($sendArgument) as List?; +if (replyList == null) { \tthrow PlatformException( \t\tcode: 'channel-error', \t\tmessage: 'Unable to establish connection on channel.', \t); -} else if (replyMap['error'] != null) { -\tfinal Map error = (replyMap['${Keys.error}'] as Map?)!; +} else if (replyList.length > 1) { \tthrow PlatformException( -\t\tcode: (error['${Keys.errorCode}'] as String?)!, -\t\tmessage: error['${Keys.errorMessage}'] as String?, -\t\tdetails: error['${Keys.errorDetails}'], +\t\tcode: replyList[0]! as String, +\t\tmessage: replyList[1] as String?, +\t\tdetails: replyList[2], \t);'''); // On iOS we can return nil from functions to accommodate error // handling. Returning a nil value and not returning an error is an // exception. if (!func.returnType.isNullable && !func.returnType.isVoid) { indent.format(''' -} else if (replyMap['${Keys.result}'] == null) { +} else if (replyList[0] == null) { \tthrow PlatformException( \t\tcode: 'null-error', \t\tmessage: 'Host platform returned null value for non-null return value.', @@ -283,6 +296,7 @@ void _writeFlutterApi( codecName = _getCodecName(api); _writeCodec(indent, codecName, api, root); } + indent.addln(''); addDocumentationComments(indent, api.documentationComments, _docCommentSpec); indent.write('abstract class ${api.name} '); @@ -302,6 +316,7 @@ void _writeFlutterApi( _getArgumentName, ); indent.writeln('$returnType ${func.name}($argSignature);'); + indent.writeln(''); } indent.write( 'static void setup(${api.name}? api, {BinaryMessenger? binaryMessenger}) '); @@ -316,8 +331,9 @@ void _writeFlutterApi( ? makeChannelName(api, func) : channelNameFunc(func); indent.nest(2, () { + indent.writeln("'$channelName', codec,"); indent.writeln( - "'$channelName', codec, binaryMessenger: binaryMessenger);", + 'binaryMessenger: binaryMessenger);', ); }); final String messageHandlerSetter = @@ -336,7 +352,7 @@ void _writeFlutterApi( _addGenericTypesNullable(func.returnType); final bool isAsync = func.isAsynchronous; final String emptyReturnStatement = isMockHandler - ? 'return {};' + ? 'return [];' : func.returnType.isVoid ? 'return;' : 'return null;'; @@ -345,9 +361,8 @@ void _writeFlutterApi( indent.writeln('// ignore message'); call = 'api.${func.name}()'; } else { - indent.writeln( - "assert(message != null, 'Argument for $channelName was null.');", - ); + indent.writeln('assert(message != null,'); + indent.writeln("'Argument for $channelName was null.');"); const String argsArray = 'args'; indent.writeln( 'final List $argsArray = (message as List?)!;'); @@ -395,7 +410,7 @@ void _writeFlutterApi( } const String returnExpression = 'output'; final String returnStatement = isMockHandler - ? "return {'${Keys.result}': $returnExpression};" + ? 'return [$returnExpression];' : 'return $returnExpression;'; indent.writeln(returnStatement); } @@ -489,7 +504,7 @@ void generateDart(DartOptions opt, Root root, StringSink sink) { void writeConstructor() { indent.write(klass.name); indent.scoped('({', '});', () { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final String required = field.type.isNullable ? '' : 'required '; indent.writeln('${required}this.${field.name},'); } @@ -499,37 +514,38 @@ void generateDart(DartOptions opt, Root root, StringSink sink) { void writeEncode() { indent.write('Object encode() '); indent.scoped('{', '}', () { - indent.writeln( - 'final Map pigeonMap = {};', + indent.write( + 'return ', ); - for (final NamedType field in klass.fields) { - indent.write("pigeonMap['${field.name}'] = "); - final String conditional = field.type.isNullable ? '?' : ''; - if (customClassNames.contains(field.type.baseName)) { - indent.addln( - '${field.name}$conditional.encode();', - ); - } else if (customEnumNames.contains(field.type.baseName)) { - indent.addln( - '${field.name}$conditional.index;', - ); - } else { - indent.addln('${field.name};'); + indent.scoped('[', '];', () { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { + final String conditional = field.type.isNullable ? '?' : ''; + if (customClassNames.contains(field.type.baseName)) { + indent.writeln( + '${field.name}$conditional.encode(),', + ); + } else if (customEnumNames.contains(field.type.baseName)) { + indent.writeln( + '${field.name}$conditional.index,', + ); + } else { + indent.writeln('${field.name},'); + } } - } - indent.writeln('return pigeonMap;'); + }); }); } void writeDecode() { - void writeValueDecode(NamedType field) { + void writeValueDecode(NamedType field, int index) { + final String resultAt = 'result[$index]'; if (customClassNames.contains(field.type.baseName)) { final String nonNullValue = - "${field.type.baseName}.decode(pigeonMap['${field.name}']!)"; + '${field.type.baseName}.decode($resultAt! as List)'; indent.format( field.type.isNullable ? ''' -pigeonMap['${field.name}'] != null +$resultAt != null \t\t? $nonNullValue \t\t: null''' : nonNullValue, @@ -537,11 +553,11 @@ pigeonMap['${field.name}'] != null trailingNewline: false); } else if (customEnumNames.contains(field.type.baseName)) { final String nonNullValue = - "${field.type.baseName}.values[pigeonMap['${field.name}']! as int]"; + '${field.type.baseName}.values[$resultAt! as int]'; indent.format( field.type.isNullable ? ''' -pigeonMap['${field.name}'] != null +$resultAt != null \t\t? $nonNullValue \t\t: null''' : nonNullValue, @@ -552,37 +568,35 @@ pigeonMap['${field.name}'] != null final String castCall = _makeGenericCastCall(field.type); final String castCallPrefix = field.type.isNullable ? '?' : '!'; indent.add( - "(pigeonMap['${field.name}'] as $genericType?)$castCallPrefix$castCall", + '($resultAt as $genericType?)$castCallPrefix$castCall', ); } else { final String genericdType = _addGenericTypesNullable(field.type); if (field.type.isNullable) { indent.add( - "pigeonMap['${field.name}'] as $genericdType", + '$resultAt as $genericdType', ); } else { indent.add( - "pigeonMap['${field.name}']! as $genericdType", + '$resultAt! as $genericdType', ); } } } indent.write( - 'static ${klass.name} decode(Object message) ', + 'static ${klass.name} decode(Object result) ', ); indent.scoped('{', '}', () { - indent.writeln( - 'final Map pigeonMap = message as Map;', - ); + indent.writeln('result as List;'); indent.write('return ${klass.name}'); indent.scoped('(', ');', () { - for (int index = 0; index < klass.fields.length; index += 1) { - final NamedType field = klass.fields[index]; + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { indent.write('${field.name}: '); - writeValueDecode(field); + writeValueDecode(field, index); indent.addln(','); - } + }); }); }); } @@ -594,14 +608,12 @@ pigeonMap['${field.name}'] != null indent.scoped('{', '}', () { writeConstructor(); indent.addln(''); - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); final String datatype = _addGenericTypesNullable(field.type); indent.writeln('$datatype ${field.name};'); - } - if (klass.fields.isNotEmpty) { indent.writeln(''); } writeEncode(); diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 526afd7366a..9ef102a8f69 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -9,7 +9,7 @@ import 'dart:mirrors'; import 'ast.dart'; /// The current version of pigeon. This must match the version in pubspec.yaml. -const String pigeonVersion = '4.2.11'; +const String pigeonVersion = '4.2.12'; /// Read all the content from [stdin] to a String. String readStdin() { @@ -491,3 +491,9 @@ void addDocumentationComments( ); } } + +/// Returns an ordered list of fields to provide consistent serialisation order. +Iterable getFieldsInSerializationOrder(Class klass) { + // This returns the fields in the order they are declared in the pigeon file. + return klass.fields; +} diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 880f7610948..4292e9cb0c5 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -115,7 +115,7 @@ void _writeCodec(Indent indent, Api api, Root root) { indent.write('case (byte)${customClass.enumeration}: '); indent.writeScoped('', '', () { indent.writeln( - 'return ${customClass.name}.fromMap((Map) readValue(buffer));'); + 'return ${customClass.name}.fromList((ArrayList) readValue(buffer));'); }); } indent.write('default:'); @@ -133,7 +133,7 @@ void _writeCodec(Indent indent, Api api, Root root) { indent.scoped('{', '} else ', () { indent.writeln('stream.write(${customClass.enumeration});'); indent.writeln( - 'writeValue(stream, ((${customClass.name}) value).toMap());'); + 'writeValue(stream, ((${customClass.name}) value).toList());'); }); } indent.scoped('{', '}', () { @@ -217,7 +217,7 @@ void _writeHostApi(Indent indent, Api api, Root root) { final String returnType = method.returnType.isVoid ? 'Void' : _javaTypeForDartType(method.returnType); - indent.writeln('Map wrapped = new HashMap<>();'); + indent.writeln('ArrayList wrapped = new ArrayList<>();'); indent.write('try '); indent.scoped('{', '}', () { final List methodArgument = []; @@ -260,12 +260,12 @@ void _writeHostApi(Indent indent, Api api, Root root) { indent.format(''' Result<$returnType> $resultName = new Result<$returnType>() { \tpublic void success($returnType result) { -\t\twrapped.put("${Keys.result}", $resultValue); +\t\twrapped.add(0, $resultValue); \t\treply.reply(wrapped); \t} \tpublic void error(Throwable error) { -\t\twrapped.put("${Keys.error}", wrapError(error)); -\t\treply.reply(wrapped); +\t\tArrayList wrappedError = wrapError(error); +\t\treply.reply(wrappedError); \t} }; '''); @@ -277,18 +277,20 @@ Result<$returnType> $resultName = new Result<$returnType>() { indent.writeln('$call;'); } else if (method.returnType.isVoid) { indent.writeln('$call;'); - indent.writeln('wrapped.put("${Keys.result}", null);'); + indent.writeln('wrapped.add(0, null);'); } else { indent.writeln('$returnType output = $call;'); - indent.writeln('wrapped.put("${Keys.result}", output);'); + indent.writeln('wrapped.add(0, output);'); } }); indent.write('catch (Error | RuntimeException exception) '); indent.scoped('{', '}', () { - indent - .writeln('wrapped.put("${Keys.error}", wrapError(exception));'); + indent.writeln( + 'ArrayList wrappedError = wrapError(exception);'); if (method.isAsynchronous) { - indent.writeln('reply.reply(wrapped);'); + indent.writeln('reply.reply(wrappedError);'); + } else { + indent.writeln('wrapped = wrappedError;'); } }); if (!method.isAsynchronous) { @@ -513,7 +515,7 @@ String _castObject( return '($varName == null) ? null : (($varName instanceof Integer) ? (Integer)$varName : (${hostDatatype.datatype})$varName)'; } else if (!hostDatatype.isBuiltin && classes.map((Class x) => x.name).contains(field.type.baseName)) { - return '($varName == null) ? null : ${hostDatatype.datatype}.fromMap((Map)$varName)'; + return '($varName == null) ? null : ${hostDatatype.datatype}.fromList((ArrayList)$varName)'; } else { return '(${hostDatatype.datatype})$varName'; } @@ -567,17 +569,11 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { indent.write('public enum ${anEnum.name} '); indent.scoped('{', '}', () { - int index = 0; - for (final String member in anEnum.members) { + enumerate(anEnum.members, (int index, final String member) { indent.writeln( '${camelToSnake(member)}($index)${index == anEnum.members.length - 1 ? ';' : ','}'); - index++; - } + }); indent.writeln(''); - // We use explicit indexing here as use of the ordinal() method is - // discouraged. The toMap and fromMap API matches class API to allow - // the same code to work with enums and classes, but this - // can also be done directly in the host and flutter APIs. indent.writeln('private final int index;'); indent.write('private ${anEnum.name}(final int index) '); indent.scoped('{', '}', () { @@ -615,11 +611,12 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { }); } - void writeToMap() { - indent.write('@NonNull Map toMap() '); + void writeToList() { + indent.write('@NonNull ArrayList toList() '); indent.scoped('{', '}', () { - indent.writeln('Map toMapResult = new HashMap<>();'); - for (final NamedType field in klass.fields) { + indent.writeln( + 'ArrayList toListResult = new ArrayList(${klass.fields.length});'); + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, root.classes, @@ -629,29 +626,30 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { final String fieldName = field.name; if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { - toWriteValue = '($fieldName == null) ? null : $fieldName.toMap()'; + toWriteValue = '($fieldName == null) ? null : $fieldName.toList()'; } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { toWriteValue = '$fieldName == null ? null : $fieldName.index'; } else { toWriteValue = field.name; } - indent.writeln('toMapResult.put("${field.name}", $toWriteValue);'); + indent.writeln('toListResult.add($toWriteValue);'); } - indent.writeln('return toMapResult;'); + indent.writeln('return toListResult;'); }); } - void writeFromMap() { + void writeFromList() { indent.write( - 'static @NonNull ${klass.name} fromMap(@NonNull Map map) '); + 'static @NonNull ${klass.name} fromList(@NonNull ArrayList list) '); indent.scoped('{', '}', () { const String result = 'pigeonResult'; indent.writeln('${klass.name} $result = new ${klass.name}();'); - for (final NamedType field in klass.fields) { + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { final String fieldVariable = field.name; final String setter = _makeSetter(field); - indent.writeln('Object $fieldVariable = map.get("${field.name}");'); + indent.writeln('Object $fieldVariable = list.get($index);'); if (rootEnumNameSet.contains(field.type.baseName)) { indent.writeln( '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName)});'); @@ -659,7 +657,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { indent.writeln( '$result.$setter(${_castObject(field, root.classes, root.enums, fieldVariable)});'); } - } + }); indent.writeln('return $result;'); }); } @@ -667,7 +665,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { void writeBuilder() { indent.write('public static final class Builder '); indent.scoped('{', '}', () { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, root.classes, @@ -688,7 +686,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { indent.scoped('{', '}', () { const String returnVal = 'pigeonReturn'; indent.writeln('${klass.name} $returnVal = new ${klass.name}();'); - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { indent.writeln('$returnVal.${_makeSetter(field)}(${field.name});'); } indent.writeln('return $returnVal;'); @@ -705,12 +703,12 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { indent.write('public static class ${klass.name} '); indent.scoped('{', '}', () { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { writeField(field); indent.addln(''); } - if (klass.fields + if (getFieldsInSerializationOrder(klass) .map((NamedType e) => !e.type.isNullable) .any((bool e) => e)) { indent.writeln( @@ -719,8 +717,8 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { } writeBuilder(); - writeToMap(); - writeFromMap(); + writeToList(); + writeFromList(); }); } @@ -742,12 +740,12 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { void writeWrapError() { indent.format(''' -@NonNull private static Map wrapError(@NonNull Throwable exception) { -\tMap errorMap = new HashMap<>(); -\terrorMap.put("${Keys.errorMessage}", exception.toString()); -\terrorMap.put("${Keys.errorCode}", exception.getClass().getSimpleName()); -\terrorMap.put("${Keys.errorDetails}", "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); -\treturn errorMap; +@NonNull private static ArrayList wrapError(@NonNull Throwable exception) { +\tArrayList errorList = new ArrayList<>(3); +\terrorList.add(exception.toString()); +\terrorList.add(exception.getClass().getSimpleName()); +\terrorList.add("Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); +\treturn errorList; }'''); } @@ -760,7 +758,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) { writeImports(); indent.addln(''); indent.writeln( - '${_docCommentPrefix}Generated class from Pigeon.$_docCommentSuffix'); + '$_docCommentPrefix Generated class from Pigeon.$_docCommentSuffix'); indent.writeln( '@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})'); if (options.useGeneratedAnnotation ?? false) { diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index d4ed272d07f..c32cb04819a 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -85,10 +85,9 @@ void _writeCodec(Indent indent, Api api, Root root) { for (final EnumeratedClass customClass in codecClasses) { indent.write('${customClass.enumeration}.toByte() -> '); indent.scoped('{', '}', () { - indent.write( - 'return (readValue(buffer) as? Map)?.let '); + indent.write('return (readValue(buffer) as? List)?.let '); indent.scoped('{', '}', () { - indent.writeln('${customClass.name}.fromMap(it)'); + indent.writeln('${customClass.name}.fromList(it)'); }); }); } @@ -105,7 +104,7 @@ void _writeCodec(Indent indent, Api api, Root root) { indent.write('is ${customClass.name} -> '); indent.scoped('{', '}', () { indent.writeln('stream.write(${customClass.enumeration})'); - indent.writeln('writeValue(stream, value.toMap())'); + indent.writeln('writeValue(stream, value.toList())'); }); } indent.writeln('else -> super.writeValue(stream, value)'); @@ -214,8 +213,7 @@ void _writeHostApi(Indent indent, Api api, Root root) { indent.write('channel.setMessageHandler '); indent.scoped('{ $messageVarName, reply ->', '}', () { - indent.writeln('val wrapped = hashMapOf()'); - + indent.writeln('var wrapped = listOf()'); indent.write('try '); indent.scoped('{', '}', () { final List methodArgument = []; @@ -240,15 +238,14 @@ void _writeHostApi(Indent indent, Api api, Root root) { }); } else if (method.returnType.isVoid) { indent.writeln(call); - indent.writeln('wrapped["${Keys.result}"] = null'); + indent.writeln('wrapped = listOf(null)'); } else { - indent.writeln('wrapped["${Keys.result}"] = $call'); + indent.writeln('wrapped = listOf($call)'); } }, addTrailingNewline: false); indent.add(' catch (exception: Error) '); indent.scoped('{', '}', () { - indent.writeln( - 'wrapped["${Keys.error}"] = wrapError(exception)'); + indent.writeln('wrapped = wrapError(exception)'); if (method.isAsynchronous) { indent.writeln('reply.reply(wrapped)'); } @@ -474,20 +471,14 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { indent, anEnum.documentationComments, _docCommentSpec); indent.write('enum class ${anEnum.name}(val raw: Int) '); indent.scoped('{', '}', () { - // We use explicit indexing here as use of the ordinal() method is - // discouraged. The toMap and fromMap API matches class API to allow - // the same code to work with enums and classes, but this - // can also be done directly in the host and flutter APIs. - int index = 0; - for (final String member in anEnum.members) { + enumerate(anEnum.members, (int index, final String member) { indent.write('${member.toUpperCase()}($index)'); if (index != anEnum.members.length - 1) { indent.addln(','); } else { indent.addln(';'); } - index++; - } + }); indent.writeln(''); indent.write('companion object '); @@ -510,48 +501,41 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { indent.add(defaultNil); } - void writeToMap() { - indent.write('fun toMap(): Map '); + void writeToList() { + indent.write('fun toList(): List '); indent.scoped('{', '}', () { - indent.writeln('val map = mutableMapOf()'); - - for (final NamedType field in klass.fields) { - final HostDatatype hostDatatype = getHostDatatype(field); - String toWriteValue = ''; - final String fieldName = field.name; - final String prefix = field.type.isNullable ? 'it' : fieldName; - if (!hostDatatype.isBuiltin && - rootClassNameSet.contains(field.type.baseName)) { - toWriteValue = '$prefix.toMap()'; - } else if (!hostDatatype.isBuiltin && - rootEnumNameSet.contains(field.type.baseName)) { - toWriteValue = '$prefix.raw'; - } else { - toWriteValue = prefix; - } - - if (field.type.isNullable) { - indent.writeln( - '$fieldName?.let { map["${field.name}"] = $toWriteValue }'); - } else { - indent.writeln('map["${field.name}"] = $toWriteValue'); + indent.write('return listOf'); + indent.scoped('(', ')', () { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { + final HostDatatype hostDatatype = getHostDatatype(field); + String toWriteValue = ''; + final String fieldName = field.name; + if (!hostDatatype.isBuiltin && + rootClassNameSet.contains(field.type.baseName)) { + toWriteValue = '$fieldName?.toList()'; + } else if (!hostDatatype.isBuiltin && + rootEnumNameSet.contains(field.type.baseName)) { + toWriteValue = '$fieldName?.raw'; + } else { + toWriteValue = fieldName; + } + indent.writeln('$toWriteValue,'); } - } - - indent.writeln('return map'); + }); }); } - void writeFromMap() { + void writeFromList() { final String className = klass.name; indent.write('companion object '); indent.scoped('{', '}', () { indent.writeln('@Suppress("UNCHECKED_CAST")'); - indent.write('fun fromMap(map: Map): $className '); + indent.write('fun fromList(list: List): $className '); indent.scoped('{', '}', () { - for (final NamedType field in klass.fields) { + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { final HostDatatype hostDatatype = getHostDatatype(field); // The StandardMessageCodec can give us [Integer, Long] for @@ -559,50 +543,51 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { // longs in Pigeon with Kotlin. final bool isInt = field.type.baseName == 'int'; - final String mapValue = 'map["${field.name}"]'; + final String listValue = 'list[$index]'; final String fieldType = _kotlinTypeForDartType(field.type); if (field.type.isNullable) { if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { indent.write('val ${field.name}: $fieldType? = '); - indent.add('($mapValue as? Map)?.let '); + indent.add('($listValue as? List)?.let '); indent.scoped('{', '}', () { - indent.writeln('$fieldType.fromMap(it)'); + indent.writeln('$fieldType.fromList(it)'); }); } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { indent.write('val ${field.name}: $fieldType? = '); - indent.add('($mapValue as? Int)?.let '); + indent.add('($listValue as? Int)?.let '); indent.scoped('{', '}', () { indent.writeln('$fieldType.ofRaw(it)'); }); } else if (isInt) { - indent.write('val ${field.name} = $mapValue'); + indent.write('val ${field.name} = $listValue'); indent.addln( '.let { if (it is Int) it.toLong() else it as? Long }'); } else { - indent.writeln('val ${field.name} = $mapValue as? $fieldType'); + indent.writeln('val ${field.name} = $listValue as? $fieldType'); } } else { if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { indent.writeln( - 'val ${field.name} = $fieldType.fromMap($mapValue as Map)'); + 'val ${field.name} = $fieldType.fromList($listValue as List)'); } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { indent.write( - 'val ${field.name} = $fieldType.ofRaw($mapValue as Int)!!'); + 'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!'); } else { - indent.writeln('val ${field.name} = $mapValue as $fieldType'); + indent.writeln('val ${field.name} = $listValue as $fieldType'); } } - } + }); indent.writeln(''); indent.write('return $className('); - for (final NamedType field in klass.fields) { - final String comma = klass.fields.last == field ? '' : ', '; + for (final NamedType field in getFieldsInSerializationOrder(klass)) { + final String comma = + getFieldsInSerializationOrder(klass).last == field ? '' : ', '; indent.add('${field.name}$comma'); } indent.addln(')'); @@ -619,9 +604,9 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { indent.write('data class ${klass.name} '); indent.scoped('(', '', () { - for (final NamedType element in klass.fields) { + for (final NamedType element in getFieldsInSerializationOrder(klass)) { writeField(element); - if (klass.fields.last != element) { + if (getFieldsInSerializationOrder(klass).last != element) { indent.addln(','); } else { indent.addln(''); @@ -630,8 +615,8 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { }); indent.scoped(') {', '}', () { - writeFromMap(); - writeToMap(); + writeFromList(); + writeToList(); }); } @@ -644,26 +629,21 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) { } void writeWrapResult() { - indent.write('private fun wrapResult(result: Any?): Map '); + indent.write('private fun wrapResult(result: Any?): List '); indent.scoped('{', '}', () { - indent.writeln('return hashMapOf("result" to result)'); + indent.writeln('return listOf(result)'); }); } void writeWrapError() { - indent.write( - 'private fun wrapError(exception: Throwable): Map '); + indent.write('private fun wrapError(exception: Throwable): List '); indent.scoped('{', '}', () { indent.write('return '); - indent.scoped('hashMapOf(', ')', () { - indent.write('"error" to '); - indent.scoped('hashMapOf(', ')', () { - indent.writeln( - '"${Keys.errorCode}" to exception.javaClass.simpleName,'); - indent.writeln('"${Keys.errorMessage}" to exception.toString(),'); - indent.writeln( - '"${Keys.errorDetails}" to "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)'); - }); + indent.scoped('listOf(', ')', () { + indent.writeln('exception.javaClass.simpleName,'); + indent.writeln('exception.toString(),'); + indent.writeln( + '"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)'); }); }); } diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index bc6077add9f..90c41c00777 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -168,7 +168,7 @@ void _writeInitializerDeclaration(Indent indent, Class klass, indent.write('+ (instancetype)makeWith'); bool isFirst = true; indent.nest(2, () { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final String label = isFirst ? _capitalize(field.name) : field.name; final void Function(String) printer = isFirst ? indent.add @@ -206,8 +206,8 @@ void _writeClassDeclarations( indent, klass.documentationComments, _docCommentSpec); indent.writeln('@interface ${_className(prefix, klass.name)} : NSObject'); - if (klass.fields.isNotEmpty) { - if (klass.fields + if (getFieldsInSerializationOrder(klass).isNotEmpty) { + if (getFieldsInSerializationOrder(klass) .map((NamedType e) => !e.type.isNullable) .any((bool e) => e)) { indent.writeln( @@ -217,7 +217,7 @@ void _writeClassDeclarations( _writeInitializerDeclaration(indent, klass, classes, enums, prefix); indent.addln(';'); } - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( field, classes, @@ -281,7 +281,7 @@ void _writeCodec( indent.write('case ${customClass.enumeration}: '); indent.writeScoped('', '', () { indent.writeln( - 'return [${_className(options.prefix, customClass.name)} fromMap:[self readValue]];'); + 'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];'); }); } indent.write('default:'); @@ -302,7 +302,7 @@ void _writeCodec( 'if ([value isKindOfClass:[${_className(options.prefix, customClass.name)} class]]) '); indent.scoped('{', '} else ', () { indent.writeln('[self writeByte:${customClass.enumeration}];'); - indent.writeln('[self writeValue:[value toMap]];'); + indent.writeln('[self writeValue:[value toList]];'); }); } indent.scoped('{', '}', () { @@ -561,13 +561,11 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) { indent.write('typedef NS_ENUM(NSUInteger, $enumName) '); indent.scoped('{', '};', () { - int index = 0; - for (final String member in anEnum.members) { + enumerate(anEnum.members, (int index, final String member) { // Capitalized first letter to ensure Swift compatibility indent.writeln( '$enumName${member[0].toUpperCase()}${member.substring(1)} = $index,'); - index++; - } + }); }); } @@ -608,23 +606,23 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) { indent.writeln('NS_ASSUME_NONNULL_END'); } -String _dictGetter( - List classNames, String dict, NamedType field, String? prefix) { +String _listGetter(List classNames, String list, NamedType field, + int index, String? prefix) { if (classNames.contains(field.type.baseName)) { String className = field.type.baseName; if (prefix != null) { className = '$prefix$className'; } - return '[$className nullableFromMap:GetNullableObject($dict, @"${field.name}")]'; + return '[$className nullableFromList:(GetNullableObjectAtIndex($list, $index))]'; } else { - return 'GetNullableObject($dict, @"${field.name}")'; + return 'GetNullableObjectAtIndex($list, $index)'; } } -String _dictValue( +String _arrayValue( List classNames, List enumNames, NamedType field) { if (classNames.contains(field.type.baseName)) { - return '(self.${field.name} ? [self.${field.name} toMap] : [NSNull null])'; + return '(self.${field.name} ? [self.${field.name} toList] : [NSNull null])'; } else if (enumNames.contains(field.type.baseName)) { return '@(self.${field.name})'; } else { @@ -849,7 +847,7 @@ void _writeFlutterApiSource( indent.writeln('messageChannelWithName:@"${makeChannelName(api, func)}"'); indent.writeln('binaryMessenger:self.binaryMessenger'); indent.write('codec:${_getCodecGetterName(options.prefix, api.name)}()'); - indent.write('];'); + indent.addln('];'); indent.dec(); indent.dec(); indent.write('[channel sendMessage:$sendArgument reply:^(id reply) '); @@ -902,19 +900,11 @@ void generateObjcSource(ObjcOptions options, Root root, StringSink sink) { void writeHelperFunctions() { indent.format(''' -static NSDictionary *wrapResult(id result, FlutterError *error) { -\tNSDictionary *errorDict = (NSDictionary *)[NSNull null]; +static NSArray *wrapResult(id result, FlutterError *error) { \tif (error) { -\t\terrorDict = @{ -\t\t\t\t@"${Keys.errorCode}": (error.code ?: [NSNull null]), -\t\t\t\t@"${Keys.errorMessage}": (error.message ?: [NSNull null]), -\t\t\t\t@"${Keys.errorDetails}": (error.details ?: [NSNull null]), -\t\t\t\t}; +\t\treturn @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] ]; \t} -\treturn @{ -\t\t\t@"${Keys.result}": (result ?: [NSNull null]), -\t\t\t@"${Keys.error}": errorDict, -\t\t\t}; +\treturn @[ result ?: [NSNull null] ]; }'''); indent.format(''' static id GetNullableObject(NSDictionary* dict, id key) { @@ -931,10 +921,10 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { void writeDataClassExtension(Class klass) { final String className = _className(options.prefix, klass.name); indent.writeln('@interface $className ()'); - indent.writeln('+ ($className *)fromMap:(NSDictionary *)dict;'); - indent.writeln( - '+ (nullable $className *)nullableFromMap:(NSDictionary *)dict;'); - indent.writeln('- (NSDictionary *)toMap;'); + indent.writeln('+ ($className *)fromList:(NSArray *)list;'); + indent + .writeln('+ (nullable $className *)nullableFromList:(NSArray *)list;'); + indent.writeln('- (NSArray *)toList;'); indent.writeln('@end'); } @@ -946,45 +936,46 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { indent.writeScoped(' {', '}', () { const String result = 'pigeonResult'; indent.writeln('$className* $result = [[$className alloc] init];'); - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { indent.writeln('$result.${field.name} = ${field.name};'); } indent.writeln('return $result;'); }); } - void writeFromMap() { - indent.write('+ ($className *)fromMap:(NSDictionary *)dict '); + void writeFromList() { + indent.write('+ ($className *)fromList:(NSArray *)list '); indent.scoped('{', '}', () { const String resultName = 'pigeonResult'; indent.writeln('$className *$resultName = [[$className alloc] init];'); - for (final NamedType field in klass.fields) { + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { if (enumNames.contains(field.type.baseName)) { indent.writeln( - '$resultName.${field.name} = [${_dictGetter(classNames, 'dict', field, options.prefix)} integerValue];'); + '$resultName.${field.name} = [${_listGetter(classNames, 'list', field, index, options.prefix)} integerValue];'); } else { indent.writeln( - '$resultName.${field.name} = ${_dictGetter(classNames, 'dict', field, options.prefix)};'); + '$resultName.${field.name} = ${_listGetter(classNames, 'list', field, index, options.prefix)};'); if (!field.type.isNullable) { indent .writeln('NSAssert($resultName.${field.name} != nil, @"");'); } } - } + }); indent.writeln('return $resultName;'); }); + indent.writeln( - '+ (nullable $className *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [$className fromMap:dict] : nil; }'); + '+ (nullable $className *)nullableFromList:(NSArray *)list { return (list) ? [$className fromList:list] : nil; }'); } - void writeToMap() { - indent.write('- (NSDictionary *)toMap '); + void writeToList() { + indent.write('- (NSArray *)toList '); indent.scoped('{', '}', () { indent.write('return'); - indent.scoped(' @{', '};', () { + indent.scoped(' @[', '];', () { for (final NamedType field in klass.fields) { - indent.writeln( - '@"${field.name}" : ${_dictValue(classNames, enumNames, field)},'); + indent.writeln('${_arrayValue(classNames, enumNames, field)},'); } }); }); @@ -992,8 +983,8 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { indent.writeln('@implementation $className'); writeInitializer(); - writeFromMap(); - writeToMap(); + writeFromList(); + writeToList(); indent.writeln('@end'); } diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 0b055ca520a..46203f67987 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -246,29 +246,28 @@ class PigeonOptions { objcHeaderOut: map['objcHeaderOut'] as String?, objcSourceOut: map['objcSourceOut'] as String?, objcOptions: map.containsKey('objcOptions') - ? ObjcOptions.fromMap((map['objcOptions'] as Map?)!) + ? ObjcOptions.fromMap(map['objcOptions']! as Map) : null, javaOut: map['javaOut'] as String?, javaOptions: map.containsKey('javaOptions') - ? JavaOptions.fromMap((map['javaOptions'] as Map?)!) + ? JavaOptions.fromMap(map['javaOptions']! as Map) : null, swiftOut: map['swiftOut'] as String?, swiftOptions: map.containsKey('swiftOptions') - ? SwiftOptions.fromMap((map['swiftOptions'] as Map?)!) + ? SwiftOptions.fromList(map['swiftOptions']! as Map) : null, kotlinOut: map['kotlinOut'] as String?, kotlinOptions: map.containsKey('kotlinOptions') - ? KotlinOptions.fromMap( - (map['kotlinOptions'] as Map?)!) + ? KotlinOptions.fromMap(map['kotlinOptions']! as Map) : null, cppHeaderOut: map['experimental_cppHeaderOut'] as String?, cppSourceOut: map['experimental_cppSourceOut'] as String?, cppOptions: map.containsKey('experimental_cppOptions') ? CppOptions.fromMap( - (map['experimental_cppOptions'] as Map?)!) + map['experimental_cppOptions']! as Map) : null, dartOptions: map.containsKey('dartOptions') - ? DartOptions.fromMap((map['dartOptions'] as Map?)!) + ? DartOptions.fromMap(map['dartOptions']! as Map) : null, copyrightHeader: map['copyrightHeader'] as String?, oneLanguage: map['oneLanguage'] as bool?, @@ -633,7 +632,7 @@ List _validateAst(Root root, String source) { root.classes.map((Class x) => x.name).toList(); final Iterable customEnums = root.enums.map((Enum x) => x.name); for (final Class klass in root.classes) { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { if (field.type.typeArguments != null) { for (final TypeDeclaration typeArgument in field.type.typeArguments) { if (!typeArgument.isNullable) { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 0b1442f7466..6ee58f5c52f 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -24,15 +24,15 @@ class SwiftOptions { final Iterable? copyrightHeader; /// Creates a [SwiftOptions] from a Map representation where: - /// `x = SwiftOptions.fromMap(x.toMap())`. - static SwiftOptions fromMap(Map map) { + /// `x = SwiftOptions.fromList(x.toMap())`. + static SwiftOptions fromList(Map map) { return SwiftOptions( copyrightHeader: map['copyrightHeader'] as Iterable?, ); } /// Converts a [SwiftOptions] to a Map representation where: - /// `x = SwiftOptions.fromMap(x.toMap())`. + /// `x = SwiftOptions.fromList(x.toMap())`. Map toMap() { final Map result = { if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, @@ -43,7 +43,7 @@ class SwiftOptions { /// Overrides any non-null parameters from [options] into this to make a new /// [SwiftOptions]. SwiftOptions merge(SwiftOptions options) { - return SwiftOptions.fromMap(mergeMaps(toMap(), options.toMap())); + return SwiftOptions.fromList(mergeMaps(toMap(), options.toMap())); } } @@ -75,7 +75,7 @@ void _writeCodec(Indent indent, Api api, Root root) { indent.write('case ${customClass.enumeration}:'); indent.scoped('', '', () { indent.write( - 'return ${customClass.name}.fromMap(self.readValue() as! [String: Any])'); + 'return ${customClass.name}.fromList(self.readValue() as! [Any])'); }); } indent.write('default:'); @@ -98,7 +98,7 @@ void _writeCodec(Indent indent, Api api, Root root) { indent.add('if let value = value as? ${customClass.name} '); indent.scoped('{', '} else ', () { indent.writeln('super.writeByte(${customClass.enumeration})'); - indent.writeln('super.writeValue(value.toMap())'); + indent.writeln('super.writeValue(value.toList())'); }, addTrailingNewline: false); } indent.scoped('{', '}', () { @@ -145,7 +145,7 @@ void _writeHostApi(Indent indent, Api api, Root root) { final String apiName = api.name; const List generatedComments = [ - 'Generated protocol from Pigeon that represents a handler of messages from Flutter.' + ' Generated protocol from Pigeon that represents a handler of messages from Flutter.' ]; addDocumentationComments(indent, api.documentationComments, _docCommentSpec, generatorComments: generatedComments); @@ -282,7 +282,7 @@ String _camelCase(String text) { void _writeFlutterApi(Indent indent, Api api, Root root) { assert(api.location == ApiLocation.flutter); const List generatedComments = [ - 'Generated class from Pigeon that represents Flutter messages that can be called from Swift.' + ' Generated class from Pigeon that represents Flutter messages that can be called from Swift.' ]; addDocumentationComments(indent, api.documentationComments, _docCommentSpec, generatorComments: generatedComments); @@ -470,15 +470,9 @@ import FlutterMacOS indent.write('enum ${anEnum.name}: Int '); indent.scoped('{', '}', () { - // We use explicit indexing here as use of the ordinal() method is - // discouraged. The toMap and fromMap API matches class API to allow - // the same code to work with enums and classes, but this - // can also be done directly in the host and flutter APIs. - int index = 0; - for (final String member in anEnum.members) { + enumerate(anEnum.members, (int index, final String member) { indent.writeln('case ${_camelCase(member)} = $index'); - index++; - } + }); }); } @@ -493,19 +487,19 @@ import FlutterMacOS indent.addln(defaultNil); } - void writeToMap() { - indent.write('func toMap() -> [String: Any?] '); + void writeToList() { + indent.write('func toList() -> [Any?] '); indent.scoped('{', '}', () { indent.write('return '); indent.scoped('[', ']', () { - for (final NamedType field in klass.fields) { + for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getHostDatatype(field); String toWriteValue = ''; final String fieldName = field.name; final String nullsafe = field.type.isNullable ? '?' : ''; if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { - toWriteValue = '$fieldName$nullsafe.toMap()'; + toWriteValue = '$fieldName$nullsafe.toList()'; } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { toWriteValue = '$fieldName$nullsafe.rawValue'; @@ -513,67 +507,66 @@ import FlutterMacOS toWriteValue = field.name; } - final String comma = klass.fields.last == field ? '' : ','; - - indent.writeln('"${field.name}": $toWriteValue$comma'); + indent.writeln('$toWriteValue,'); } }); }); } - void writeFromMap() { + void writeFromList() { final String className = klass.name; - indent - .write('static func fromMap(_ map: [String: Any?]) -> $className? '); + indent.write('static func fromList(_ list: [Any?]) -> $className? '); indent.scoped('{', '}', () { - for (final NamedType field in klass.fields) { + enumerate(getFieldsInSerializationOrder(klass), + (int index, final NamedType field) { final HostDatatype hostDatatype = getHostDatatype(field); - final String mapValue = 'map["${field.name}"]'; + final String listValue = 'list[$index]'; final String fieldType = _swiftTypeForDartType(field.type); if (field.type.isNullable) { if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { indent.writeln('var ${field.name}: $fieldType? = nil'); - indent.write( - 'if let ${field.name}Map = $mapValue as? [String: Any?] '); + indent.write('if let ${field.name}List = $listValue as? [Any?] '); indent.scoped('{', '}', () { indent.writeln( - '${field.name} = $fieldType.fromMap(${field.name}Map)'); + '${field.name} = $fieldType.fromList(${field.name}List)'); }); } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { indent.writeln('var ${field.name}: $fieldType? = nil'); - indent.write('if let ${field.name}RawValue = $mapValue as? Int '); + indent + .write('if let ${field.name}RawValue = $listValue as? Int '); indent.scoped('{', '}', () { indent.writeln( '${field.name} = $fieldType(rawValue: ${field.name}RawValue)'); }); } else { - indent.writeln('let ${field.name} = $mapValue as? $fieldType '); + indent.writeln('let ${field.name} = $listValue as? $fieldType '); } } else { if (!hostDatatype.isBuiltin && rootClassNameSet.contains(field.type.baseName)) { indent.writeln( - 'let ${field.name} = $fieldType.fromMap($mapValue as! [String: Any?])!'); + 'let ${field.name} = $fieldType.fromList($listValue as! [Any?])!'); } else if (!hostDatatype.isBuiltin && rootEnumNameSet.contains(field.type.baseName)) { indent.writeln( - 'let ${field.name} = $fieldType(rawValue: $mapValue as! Int)!'); + 'let ${field.name} = $fieldType(rawValue: $listValue as! Int)!'); } else { - indent.writeln('let ${field.name} = $mapValue as! $fieldType'); + indent.writeln('let ${field.name} = $listValue as! $fieldType'); } } - } + }); indent.writeln(''); indent.write('return '); indent.scoped('$className(', ')', () { - for (final NamedType field in klass.fields) { - final String comma = klass.fields.last == field ? '' : ','; + for (final NamedType field in getFieldsInSerializationOrder(klass)) { + final String comma = + getFieldsInSerializationOrder(klass).last == field ? '' : ','; indent.writeln('${field.name}: ${field.name}$comma'); } }); @@ -581,7 +574,7 @@ import FlutterMacOS } const List generatedComments = [ - 'Generated class from Pigeon that represents data sent in messages.' + ' Generated class from Pigeon that represents data sent in messages.' ]; addDocumentationComments( indent, klass.documentationComments, _docCommentSpec, @@ -589,11 +582,11 @@ import FlutterMacOS indent.write('struct ${klass.name} '); indent.scoped('{', '}', () { - klass.fields.forEach(writeField); + getFieldsInSerializationOrder(klass).forEach(writeField); indent.writeln(''); - writeFromMap(); - writeToMap(); + writeFromList(); + writeToList(); }); } @@ -606,24 +599,20 @@ import FlutterMacOS } void writeWrapResult() { - indent.write('private func wrapResult(_ result: Any?) -> [String: Any?] '); + indent.write('private func wrapResult(_ result: Any?) -> [Any?] '); indent.scoped('{', '}', () { - indent.writeln('return ["result": result]'); + indent.writeln('return [result]'); }); } void writeWrapError() { - indent.write( - 'private func wrapError(_ error: FlutterError) -> [String: Any?] '); + indent.write('private func wrapError(_ error: FlutterError) -> [Any?] '); indent.scoped('{', '}', () { indent.write('return '); indent.scoped('[', ']', () { - indent.write('"error": '); - indent.scoped('[', ']', () { - indent.writeln('"${Keys.errorCode}": error.code,'); - indent.writeln('"${Keys.errorMessage}": error.message,'); - indent.writeln('"${Keys.errorDetails}": error.details'); - }); + indent.writeln('error.code,'); + indent.writeln('error.message,'); + indent.writeln('error.details'); }); }); } diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 3e86aca2e5b..f64aa5dc142 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.0.2), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -11,12 +11,22 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +/// This comment is to test enum documentation comments. +/// +/// This comment also tests multiple line comments. +/// +/// //////////////////////// +/// This comment also tests comments that start with '/' +/// //////////////////////// enum MessageRequestState { pending, success, failure, } +/// This comment is to test class documentation comments. +/// +/// This comment also tests multiple line comments. class MessageSearchRequest { MessageSearchRequest({ this.query, @@ -24,28 +34,34 @@ class MessageSearchRequest { this.aBool, }); + /// This comment is to test field documentation comments. String? query; + + /// This comment is to test field documentation comments. int? anInt; + + /// This comment is to test field documentation comments. bool? aBool; Object encode() { - final Map pigeonMap = {}; - pigeonMap['query'] = query; - pigeonMap['anInt'] = anInt; - pigeonMap['aBool'] = aBool; - return pigeonMap; + return [ + query, + anInt, + aBool, + ]; } - static MessageSearchRequest decode(Object message) { - final Map pigeonMap = message as Map; + static MessageSearchRequest decode(Object result) { + result as List; return MessageSearchRequest( - query: pigeonMap['query'] as String?, - anInt: pigeonMap['anInt'] as int?, - aBool: pigeonMap['aBool'] as bool?, + query: result[0] as String?, + anInt: result[1] as int?, + aBool: result[2] as bool?, ); } } +/// This comment is to test class documentation comments. class MessageSearchReply { MessageSearchReply({ this.result, @@ -53,48 +69,57 @@ class MessageSearchReply { this.state, }); + /// This comment is to test field documentation comments. + /// + /// This comment also tests multiple line comments. String? result; + + /// This comment is to test field documentation comments. String? error; + + /// This comment is to test field documentation comments. MessageRequestState? state; Object encode() { - final Map pigeonMap = {}; - pigeonMap['result'] = result; - pigeonMap['error'] = error; - pigeonMap['state'] = state?.index; - return pigeonMap; + return [ + result, + error, + state?.index, + ]; } - static MessageSearchReply decode(Object message) { - final Map pigeonMap = message as Map; + static MessageSearchReply decode(Object result) { + result as List; return MessageSearchReply( - result: pigeonMap['result'] as String?, - error: pigeonMap['error'] as String?, - state: pigeonMap['state'] != null - ? MessageRequestState.values[pigeonMap['state']! as int] + result: result[0] as String?, + error: result[1] as String?, + state: result[2] != null + ? MessageRequestState.values[result[2]! as int] : null, ); } } +/// This comment is to test class documentation comments. class MessageNested { MessageNested({ this.request, }); + /// This comment is to test field documentation comments. MessageSearchRequest? request; Object encode() { - final Map pigeonMap = {}; - pigeonMap['request'] = request?.encode(); - return pigeonMap; + return [ + request?.encode(), + ]; } - static MessageNested decode(Object message) { - final Map pigeonMap = message as Map; + static MessageNested decode(Object result) { + result as List; return MessageNested( - request: pigeonMap['request'] != null - ? MessageSearchRequest.decode(pigeonMap['request']!) + request: result[0] != null + ? MessageSearchRequest.decode(result[0]! as List) : null, ); } @@ -130,67 +155,68 @@ class _MessageApiCodec extends StandardMessageCodec { } } +/// This comment is to test api documentation comments. +/// +/// This comment also tests multiple line comments. class MessageApi { /// Constructor for [MessageApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. MessageApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _MessageApiCodec(); + /// This comment is to test documentation comments. + /// + /// This comment also tests multiple line comments. Future initialize() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.MessageApi.initialize', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; } } + /// This comment is to test method documentation comments. Future search(MessageSearchRequest arg_request) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.MessageApi.search', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_request]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_request]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as MessageSearchReply?)!; + return (replyList[0] as MessageSearchReply?)!; } } } @@ -231,43 +257,44 @@ class _MessageNestedApiCodec extends StandardMessageCodec { } } +/// This comment is to test api documentation comments. class MessageNestedApi { /// Constructor for [MessageNestedApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. MessageNestedApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _MessageNestedApiCodec(); + /// This comment is to test method documentation comments. + /// + /// This comment also tests multiple line comments. Future search(MessageNested arg_nested) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.MessageNestedApi.search', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_nested]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_nested]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as MessageSearchReply?)!; + return (replyList[0] as MessageSearchReply?)!; } } } @@ -302,10 +329,13 @@ class _MessageFlutterSearchApiCodec extends StandardMessageCodec { } } +/// This comment is to test api documentation comments. abstract class MessageFlutterSearchApi { static const MessageCodec codec = _MessageFlutterSearchApiCodec(); + /// This comment is to test method documentation comments. MessageSearchReply search(MessageSearchRequest request); + static void setup(MessageFlutterSearchApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index b8adae42c4d..d0ecdc5d205 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.0.2), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports @@ -44,11 +44,20 @@ class _TestHostApiCodec extends StandardMessageCodec { } } +/// This comment is to test api documentation comments. +/// +/// This comment also tests multiple line comments. abstract class TestHostApi { static const MessageCodec codec = _TestHostApiCodec(); + /// This comment is to test documentation comments. + /// + /// This comment also tests multiple line comments. void initialize(); + + /// This comment is to test method documentation comments. MessageSearchReply search(MessageSearchRequest request); + static void setup(TestHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( @@ -60,7 +69,7 @@ abstract class TestHostApi { channel.setMockMessageHandler((Object? message) async { // ignore message api.initialize(); - return {}; + return []; }); } } @@ -80,7 +89,7 @@ abstract class TestHostApi { assert(arg_request != null, 'Argument for dev.flutter.pigeon.MessageApi.search was null, expected non-null MessageSearchRequest.'); final MessageSearchReply output = api.search(arg_request!); - return {'result': output}; + return [output]; }); } } @@ -123,10 +132,15 @@ class _TestNestedApiCodec extends StandardMessageCodec { } } +/// This comment is to test api documentation comments. abstract class TestNestedApi { static const MessageCodec codec = _TestNestedApiCodec(); + /// This comment is to test method documentation comments. + /// + /// This comment also tests multiple line comments. MessageSearchReply search(MessageNested nested); + static void setup(TestNestedApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( @@ -143,7 +157,7 @@ abstract class TestNestedApi { assert(arg_nested != null, 'Argument for dev.flutter.pigeon.MessageNestedApi.search was null, expected non-null MessageNested.'); final MessageSearchReply output = api.search(arg_nested!); - return {'result': output}; + return [output]; }); } } diff --git a/packages/pigeon/mock_handler_tester/test/widget_test.dart b/packages/pigeon/mock_handler_tester/test/widget_test.dart index 4ffded10d4d..0973bfe778d 100644 --- a/packages/pigeon/mock_handler_tester/test/widget_test.dart +++ b/packages/pigeon/mock_handler_tester/test/widget_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io'; - import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -85,7 +83,7 @@ void main() { await const BasicMessageChannel( 'dev.flutter.pigeon.MessageApi.search', StandardMessageCodec(), - ).send([null]) as Map?; + ).send([null]) as List?; expect(true, isFalse); // should not reach here } catch (error) { expect(error, isAssertionError); @@ -98,7 +96,5 @@ void main() { } expect(mock.log, ['initialize']); }, - // TODO(ianh): skip can be removed after first stable release in 2021 - skip: Platform.environment['CHANNEL'] == 'stable', ); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index e4aea7c3007..61324c1fc8a 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Map; import org.junit.Test; public class AllDatatypesTest { @@ -147,10 +146,12 @@ public void hasValues() { public void integerToLong() { AllNullableTypes everything = new AllNullableTypes(); everything.setANullableInt(123L); - Map map = everything.toMap(); - assertTrue(map.containsKey("aNullableInt")); - map.put("aNullableInt", 123); - AllNullableTypes readEverything = AllNullableTypes.fromMap(map); + ArrayList list = everything.toList(); + assertNotNull(list); + assertNull(list.get(0)); + assertNotNull(list.get(1)); + list.set(1, 123); + AllNullableTypes readEverything = AllNullableTypes.fromList(list); assertEquals(readEverything.getANullableInt(), everything.getANullableInt()); } } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AsyncTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AsyncTest.java index 7877e02207c..786aef3bf9b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AsyncTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AsyncTest.java @@ -11,7 +11,7 @@ import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MessageCodec; import java.nio.ByteBuffer; -import java.util.Map; +import java.util.ArrayList; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -60,8 +60,8 @@ public void asyncSuccess() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("result")); + ArrayList wrapped = (ArrayList) codec.decodeMessage(bytes); + assertTrue(wrapped.size() == 1); didCall[0] = true; }); assertTrue(didCall[0]); @@ -87,10 +87,9 @@ public void asyncError() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("error")); - assertEquals( - "java.lang.Exception: error", ((Map) wrapped.get("error")).get("message")); + ArrayList wrapped = (ArrayList) codec.decodeMessage(bytes); + assertTrue(wrapped.size() > 1); + assertEquals("java.lang.Exception: error", (String) wrapped.get(0)); didCall[0] = true; }); assertTrue(didCall[0]); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/EnumTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/EnumTest.java index 617e04fa06c..37c14be1f99 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/EnumTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/EnumTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.*; -import java.util.Map; +import java.util.ArrayList; import org.junit.Test; public class EnumTest { @@ -14,8 +14,8 @@ public class EnumTest { public void nullValue() { Enum.DataWithEnum value = new Enum.DataWithEnum(); value.setState(null); - Map map = value.toMap(); - Enum.DataWithEnum readValue = Enum.DataWithEnum.fromMap(map); + ArrayList list = value.toList(); + Enum.DataWithEnum readValue = Enum.DataWithEnum.fromList(list); assertEquals(value.getState(), readValue.getState()); } } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/ListTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/ListTest.java index 510534a2f29..a1345a00a1b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/ListTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/ListTest.java @@ -28,8 +28,7 @@ public void listInList() { ByteBuffer message = invocation.getArgument(1); BinaryMessenger.BinaryReply reply = invocation.getArgument(2); message.position(0); - ArrayList args = - (ArrayList) EchoApi.getCodec().decodeMessage(message); + ArrayList args = (ArrayList) EchoApi.getCodec().decodeMessage(message); ByteBuffer replyData = EchoApi.getCodec().encodeMessage(args.get(0)); replyData.position(0); reply.reply(replyData); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java index de47463fb21..d581c2d8bc2 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java @@ -7,9 +7,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import org.junit.Test; public class NullFieldsTest { @@ -63,38 +62,39 @@ public void builderReplyWithNulls() { @Test public void requestFromMapWithValues() { - HashMap map = new HashMap<>(); - map.put("query", "hello"); - map.put("identifier", 1L); - - NullFields.NullFieldsSearchRequest request = NullFields.NullFieldsSearchRequest.fromMap(map); + ArrayList list = new ArrayList(); + list.add("hello"); + list.add(1L); + NullFields.NullFieldsSearchRequest request = NullFields.NullFieldsSearchRequest.fromList(list); assertEquals(request.getQuery(), "hello"); } @Test public void requestFromMapWithNulls() { - HashMap map = new HashMap<>(); - map.put("query", null); - map.put("identifier", 1L); + ArrayList list = new ArrayList(); + list.add(null); + list.add(1L); - NullFields.NullFieldsSearchRequest request = NullFields.NullFieldsSearchRequest.fromMap(map); + NullFields.NullFieldsSearchRequest request = NullFields.NullFieldsSearchRequest.fromList(list); assertNull(request.getQuery()); } @Test public void replyFromMapWithValues() { - HashMap requestMap = new HashMap<>(); - requestMap.put("query", "hello"); - requestMap.put("identifier", 1L); - - HashMap map = new HashMap<>(); - map.put("result", "result"); - map.put("error", "error"); - map.put("indices", Arrays.asList(1L, 2L, 3L)); - map.put("request", requestMap); - map.put("type", NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); - - NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromMap(map); + ArrayList requestList = new ArrayList(); + + requestList.add("hello"); + requestList.add(1L); + + ArrayList list = new ArrayList(); + + list.add("result"); + list.add("error"); + list.add(Arrays.asList(1L, 2L, 3L)); + list.add(requestList); + list.add(NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); + + NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromList(list); assertEquals(reply.getResult(), "result"); assertEquals(reply.getError(), "error"); assertEquals(reply.getIndices(), Arrays.asList(1L, 2L, 3L)); @@ -104,14 +104,15 @@ public void replyFromMapWithValues() { @Test public void replyFromMapWithNulls() { - HashMap map = new HashMap<>(); - map.put("result", null); - map.put("error", null); - map.put("indices", null); - map.put("request", null); - map.put("type", null); - - NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromMap(map); + ArrayList list = new ArrayList(); + + list.add(null); + list.add(null); + list.add(null); + list.add(null); + list.add(null); + + NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromList(list); assertNull(reply.getResult()); assertNull(reply.getError()); assertNull(reply.getIndices()); @@ -127,8 +128,8 @@ public void requestToMapWithValues() { .setIdentifier(1L) .build(); - Map map = request.toMap(); - assertEquals(map.get("query"), "hello"); + ArrayList list = request.toList(); + assertEquals(list.get(0), "hello"); } @Test @@ -136,8 +137,8 @@ public void requestToMapWithNulls() { NullFields.NullFieldsSearchRequest request = new NullFields.NullFieldsSearchRequest.Builder().setQuery(null).setIdentifier(1L).build(); - Map map = request.toMap(); - assertNull(map.get("query")); + ArrayList list = request.toList(); + assertNull(list.get(0)); } @Test @@ -155,12 +156,12 @@ public void replyToMapWithValues() { .setType(NullFields.NullFieldsSearchReplyType.SUCCESS) .build(); - Map map = reply.toMap(); - assertEquals(map.get("result"), "result"); - assertEquals(map.get("error"), "error"); - assertEquals(map.get("indices"), Arrays.asList(1L, 2L, 3L)); - assertEquals(map.get("request"), reply.getRequest().toMap()); - assertEquals(map.get("type"), NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); + ArrayList list = reply.toList(); + assertEquals(list.get(0), "result"); + assertEquals(list.get(1), "error"); + assertEquals(list.get(2), Arrays.asList(1L, 2L, 3L)); + assertEquals(list.get(3), reply.getRequest().toList()); + assertEquals(list.get(4), NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); } @Test @@ -174,11 +175,12 @@ public void replyToMapWithNulls() { .setType(null) .build(); - Map map = reply.toMap(); - assertNull(map.get("result")); - assertNull(map.get("error")); - assertNull(map.get("indices")); - assertNull(map.get("request")); - assertNull(map.get("type")); + ArrayList list = reply.toList(); + + assertNull(list.get(0)); + assertNull(list.get(1)); + assertNull(list.get(2)); + assertNull(list.get(3)); + assertNull(list.get(4)); } } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullableReturnsTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullableReturnsTest.java index 0b3beecfe4a..041a83baebf 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullableReturnsTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullableReturnsTest.java @@ -11,7 +11,6 @@ import io.flutter.plugin.common.MessageCodec; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Map; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -40,8 +39,8 @@ public void nullArgHostApi() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("result")); + ArrayList wrapped = (ArrayList) codec.decodeMessage(bytes); + assertTrue(wrapped.size() == 1); }); } @@ -53,8 +52,8 @@ public void nullArgFlutterApi() { ByteBuffer message = invocation.getArgument(1); BinaryMessenger.BinaryReply reply = invocation.getArgument(2); message.position(0); - ArrayList args = - (ArrayList) + ArrayList args = + (ArrayList) NullableReturns.NullableArgFlutterApi.getCodec().decodeMessage(message); assertNull(args.get(0)); ByteBuffer replyData = diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PigeonTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PigeonTest.java index c50bd515556..a8a88b190eb 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PigeonTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PigeonTest.java @@ -12,31 +12,30 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; -import java.util.Map; import org.junit.Test; import org.mockito.ArgumentCaptor; public class PigeonTest { @Test - public void toMapAndBack() { + public void toListAndBack() { Pigeon.AndroidSetRequest request = new Pigeon.AndroidSetRequest(); request.setValue(1234l); request.setState(Pigeon.AndroidLoadingState.COMPLETE); - Map map = request.toMap(); - Pigeon.AndroidSetRequest readRequest = Pigeon.AndroidSetRequest.fromMap(map); + ArrayList list = request.toList(); + Pigeon.AndroidSetRequest readRequest = Pigeon.AndroidSetRequest.fromList(list); assertEquals(request.getValue(), readRequest.getValue()); assertEquals(request.getState(), readRequest.getState()); } @Test - public void toMapAndBackNested() { + public void toListAndBackNested() { Pigeon.AndroidNestedRequest nested = new Pigeon.AndroidNestedRequest(); Pigeon.AndroidSetRequest request = new Pigeon.AndroidSetRequest(); request.setValue(1234l); request.setState(Pigeon.AndroidLoadingState.COMPLETE); nested.setRequest(request); - Map map = nested.toMap(); - Pigeon.AndroidNestedRequest readNested = Pigeon.AndroidNestedRequest.fromMap(map); + ArrayList list = nested.toList(); + Pigeon.AndroidNestedRequest readNested = Pigeon.AndroidNestedRequest.fromList(list); assertEquals(nested.getRequest().getValue(), readNested.getRequest().getValue()); assertEquals(nested.getRequest().getState(), readNested.getRequest().getState()); } @@ -70,11 +69,10 @@ public void errorMessage() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("error")); - Map error = (Map) wrapped.get("error"); - assertTrue(error.containsKey("details")); - String details = (String) error.get("details"); + ArrayList error = (ArrayList) codec.decodeMessage(bytes); + assertNotNull(error.get(0)); + assertNotNull(error.get(1)); + String details = (String) error.get(2); assertTrue(details.contains("Cause:")); assertTrue(details.contains("Stacktrace:")); }); @@ -101,9 +99,9 @@ public void callsVoidMethod() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("result")); - assertNull(wrapped.get("result")); + ArrayList wrapped = (ArrayList) codec.decodeMessage(bytes); + assertTrue(wrapped.size() == 1); + assertNull(wrapped.get(0)); }); ArgumentCaptor receivedRequest = ArgumentCaptor.forClass(Pigeon.AndroidSetRequest.class); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PrimitiveTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PrimitiveTest.java index 9599513eacf..772b86993e6 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PrimitiveTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/PrimitiveTest.java @@ -28,8 +28,7 @@ private static BinaryMessenger makeMockBinaryMessenger() { ByteBuffer message = invocation.getArgument(1); BinaryMessenger.BinaryReply reply = invocation.getArgument(2); message.position(0); - ArrayList args = - (ArrayList) PrimitiveFlutterApi.getCodec().decodeMessage(message); + ArrayList args = (ArrayList) PrimitiveFlutterApi.getCodec().decodeMessage(message); Object arg = args.get(0); if (arg instanceof Long) { Long longArg = (Long) arg; @@ -88,7 +87,8 @@ public void primitiveIntHostApi() { verify(binaryMessenger) .setMessageHandler(eq("dev.flutter.pigeon.PrimitiveHostApi.anInt"), handler.capture()); MessageCodec codec = PrimitiveHostApi.getCodec(); - ByteBuffer message = codec.encodeMessage(new ArrayList(Arrays.asList((Integer) 1))); + @SuppressWarnings("unchecked") + ByteBuffer message = codec.encodeMessage(new ArrayList(Arrays.asList((Integer) 1))); message.rewind(); handler .getValue() @@ -97,9 +97,9 @@ public void primitiveIntHostApi() { (bytes) -> { bytes.rewind(); @SuppressWarnings("unchecked") - Map wrapped = (Map) codec.decodeMessage(bytes); - assertTrue(wrapped.containsKey("result")); - assertEquals(1L, ((Long) wrapped.get("result")).longValue()); + ArrayList wrapped = (ArrayList) codec.decodeMessage(bytes); + assertTrue(wrapped.size() > 0); + assertEquals(1L, ((Long) wrapped.get(0)).longValue()); }); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AsyncHandlersTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AsyncHandlersTest.m index 7831c71833a..223857dfd71 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AsyncHandlersTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AsyncHandlersTest.m @@ -15,8 +15,8 @@ /////////////////////////////////////////////////////////////////////////////////////////// @interface Value () -+ (Value *)fromMap:(NSDictionary *)dict; -- (NSDictionary *)toMap; ++ (Value *)fromList:(NSArray *)list; +- (NSArray *)toList; @end /////////////////////////////////////////////////////////////////////////////////////////// @@ -79,9 +79,8 @@ - (void)testAsyncFlutter2HostVoidVoid { XCTestExpectation *expectation = [self expectationWithDescription:@"voidvoid callback"]; binaryMessenger.handlers[channelName](nil, ^(NSData *data) { - NSDictionary *outputMap = [binaryMessenger.codec decode:data]; - XCTAssertEqualObjects(outputMap[@"result"], [NSNull null]); - XCTAssertEqualObjects(outputMap[@"error"], [NSNull null]); + NSArray *outputList = [binaryMessenger.codec decode:data]; + XCTAssertEqualObjects(outputList[0], [NSNull null]); [expectation fulfill]; }); [self waitForExpectationsWithTimeout:1.0 handler:nil]; @@ -98,9 +97,9 @@ - (void)testAsyncFlutter2HostVoidVoidError { XCTestExpectation *expectation = [self expectationWithDescription:@"voidvoid callback"]; binaryMessenger.handlers[channelName](nil, ^(NSData *data) { - NSDictionary *outputMap = [binaryMessenger.codec decode:data]; - XCTAssertNotNil(outputMap[@"error"]); - XCTAssertEqualObjects(outputMap[@"error"][@"code"], mockApi2Host.voidVoidError.code); + NSArray *outputList = [binaryMessenger.codec decode:data]; + XCTAssertNotNil(outputList); + XCTAssertEqualObjects(outputList[0], mockApi2Host.voidVoidError.code); [expectation fulfill]; }); [self waitForExpectationsWithTimeout:1.0 handler:nil]; @@ -120,8 +119,8 @@ - (void)testAsyncFlutter2Host { NSData *inputEncoded = [binaryMessenger.codec encode:@[ input ]]; XCTestExpectation *expectation = [self expectationWithDescription:@"calculate callback"]; binaryMessenger.handlers[channelName](inputEncoded, ^(NSData *data) { - NSDictionary *outputMap = [binaryMessenger.codec decode:data]; - Value *output = outputMap[@"result"]; + NSArray *outputList = [binaryMessenger.codec decode:data]; + Value *output = outputList[0]; XCTAssertEqual(output.number.intValue, 2); [expectation fulfill]; }); @@ -138,11 +137,13 @@ - (void)testAsyncFlutter2HostError { Value *input = [[Value alloc] init]; input.number = @(1); - NSData *inputEncoded = [binaryMessenger.codec encode:@[ [input toMap] ]]; + NSData *inputEncoded = [binaryMessenger.codec encode:@[ [input toList] ]]; XCTestExpectation *expectation = [self expectationWithDescription:@"calculate callback"]; binaryMessenger.handlers[channelName](inputEncoded, ^(NSData *data) { - NSDictionary *outputMap = [binaryMessenger.codec decode:data]; - XCTAssertNotNil(outputMap[@"error"]); + NSArray *outputList = [binaryMessenger.codec decode:data]; + XCTAssertNotNil(outputList); + XCTAssertEqualObjects(outputList[0], @"hey"); + XCTAssertEqualObjects(outputList[1], @"ho"); [expectation fulfill]; }); [self waitForExpectationsWithTimeout:1.0 handler:nil]; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m index b7bddee83c8..fe05d5bc0d8 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m @@ -15,14 +15,14 @@ /////////////////////////////////////////////////////////////////////////////////////////// @interface NullFieldsSearchRequest () -+ (NullFieldsSearchRequest *)fromMap:(NSDictionary *)dict; -- (NSDictionary *)toMap; ++ (NullFieldsSearchRequest *)fromList:(NSArray *)list; +- (NSArray *)toList; @end /////////////////////////////////////////////////////////////////////////////////////////// @interface NullFieldsSearchReply () -+ (NullFieldsSearchReply *)fromMap:(NSDictionary *)dict; -- (NSDictionary *)toMap; ++ (NullFieldsSearchReply *)fromList:(NSArray *)list; +- (NSArray *)toList; @end /////////////////////////////////////////////////////////////////////////////////////////// @@ -69,38 +69,38 @@ - (void)testMakeReplyWithNulls { XCTAssertEqual(NullFieldsSearchReplyTypeSuccess, reply.type); } -- (void)testRequestFromMapWithValues { - NSDictionary *map = @{ - @"query" : @"hello", - @"identifier" : @1, - }; - NullFieldsSearchRequest *request = [NullFieldsSearchRequest fromMap:map]; +- (void)testRequestFromListWithValues { + NSArray *list = @[ + @"hello", + @1, + ]; + NullFieldsSearchRequest *request = [NullFieldsSearchRequest fromList:list]; XCTAssertEqualObjects(@"hello", request.query); } -- (void)testRequestFromMapWithNulls { - NSDictionary *map = @{ - @"query" : [NSNull null], - @"identifier" : @1, - }; - NullFieldsSearchRequest *request = [NullFieldsSearchRequest fromMap:map]; +- (void)testRequestFromListWithNulls { + NSArray *list = @[ + [NSNull null], + @1, + ]; + NullFieldsSearchRequest *request = [NullFieldsSearchRequest fromList:list]; XCTAssertNil(request.query); } -- (void)testReplyFromMapWithValues { - NSDictionary *map = @{ - @"result" : @"result", - @"error" : @"error", - @"indices" : @[ @1, @2, @3 ], - @"request" : @{ - @"query" : @"hello", - @"identifier" : @1, - }, - @"type" : @0, - }; +- (void)testReplyFromListWithValues { + NSArray *list = @[ + @"result", + @"error", + @[ @1, @2, @3 ], + @[ + @"hello", + @1, + ], + @0, + ]; NSArray *indices = @[ @1, @2, @3 ]; - NullFieldsSearchReply *reply = [NullFieldsSearchReply fromMap:map]; + NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:list]; XCTAssertEqualObjects(@"result", reply.result); XCTAssertEqualObjects(@"error", reply.error); XCTAssertEqualObjects(indices, reply.indices); @@ -108,15 +108,15 @@ - (void)testReplyFromMapWithValues { XCTAssertEqual(NullFieldsSearchReplyTypeSuccess, reply.type); } -- (void)testReplyFromMapWithNulls { - NSDictionary *map = @{ - @"result" : [NSNull null], - @"error" : [NSNull null], - @"indices" : [NSNull null], - @"request" : [NSNull null], - @"type" : [NSNull null], - }; - NullFieldsSearchReply *reply = [NullFieldsSearchReply fromMap:map]; +- (void)testReplyFromListWithNulls { + NSArray *list = @[ + [NSNull null], + [NSNull null], + [NSNull null], + [NSNull null], + [NSNull null], + ]; + NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:list]; XCTAssertNil(reply.result); XCTAssertNil(reply.error); XCTAssertNil(reply.indices); @@ -124,46 +124,46 @@ - (void)testReplyFromMapWithNulls { XCTAssertEqual(NullFieldsSearchReplyTypeSuccess, reply.type); } -- (void)testRequestToMapWithValuess { +- (void)testRequestToListWithValuess { NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:@"hello" identifier:@1]; - NSDictionary *dict = [request toMap]; - XCTAssertEqual(@"hello", dict[@"query"]); + NSArray *list = [request toList]; + XCTAssertEqual(@"hello", list[0]); } -- (void)testRequestToMapWithNulls { +- (void)testRequestToListWithNulls { NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:nil identifier:@1]; - NSDictionary *dict = [request toMap]; - XCTAssertEqual([NSNull null], dict[@"query"]); + NSArray *list = [request toList]; + XCTAssertEqual([NSNull null], list[0]); } -- (void)testReplyToMapWithValuess { +- (void)testReplyToListWithValuess { NullFieldsSearchReply *reply = [NullFieldsSearchReply makeWithResult:@"result" error:@"error" indices:@[ @1, @2, @3 ] request:[NullFieldsSearchRequest makeWithQuery:@"hello" identifier:@1] type:NullFieldsSearchReplyTypeSuccess]; - NSDictionary *dict = [reply toMap]; + NSArray *list = [reply toList]; NSArray *indices = @[ @1, @2, @3 ]; - XCTAssertEqualObjects(@"result", dict[@"result"]); - XCTAssertEqualObjects(@"error", dict[@"error"]); - XCTAssertEqualObjects(indices, dict[@"indices"]); - XCTAssertEqualObjects(@"hello", dict[@"request"][@"query"]); - XCTAssertEqualObjects(@0, dict[@"type"]); + XCTAssertEqualObjects(@"result", list[0]); + XCTAssertEqualObjects(@"error", list[1]); + XCTAssertEqualObjects(indices, list[2]); + XCTAssertEqualObjects(@"hello", list[3][0]); + XCTAssertEqualObjects(@0, list[4]); } -- (void)testReplyToMapWithNulls { +- (void)testReplyToListWithNulls { NullFieldsSearchReply *reply = [NullFieldsSearchReply makeWithResult:nil error:nil indices:nil request:nil type:NullFieldsSearchReplyTypeSuccess]; - NSDictionary *dict = [reply toMap]; - XCTAssertEqual([NSNull null], dict[@"result"]); - XCTAssertEqual([NSNull null], dict[@"error"]); - XCTAssertEqual([NSNull null], dict[@"indices"]); - XCTAssertEqual([NSNull null], dict[@"request"]); + NSArray *list = [reply toList]; + XCTAssertEqual([NSNull null], list[0]); + XCTAssertEqual([NSNull null], list[1]); + XCTAssertEqual([NSNull null], list[2]); + XCTAssertEqual([NSNull null], list[3]); } @end diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m index eef1730324b..130788fe2ba 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m @@ -11,8 +11,8 @@ #endif @interface ACMessageSearchReply () -+ (ACMessageSearchReply *)fromMap:(NSDictionary *)dict; -- (NSDictionary *)toMap; ++ (ACMessageSearchReply *)fromList:(NSArray *)list; +- (NSArray *)toList; @end @interface RunnerTests : XCTestCase @@ -24,24 +24,24 @@ @implementation RunnerTests - (void)testToMapAndBack { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.result = @"foobar"; - NSDictionary *dict = [reply toMap]; - ACMessageSearchReply *copy = [ACMessageSearchReply fromMap:dict]; + NSArray *list = [reply toList]; + ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertEqual(reply.result, copy.result); } - (void)testHandlesNull { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.result = nil; - NSDictionary *dict = [reply toMap]; - ACMessageSearchReply *copy = [ACMessageSearchReply fromMap:dict]; + NSArray *list = [reply toList]; + ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertNil(copy.result); } - (void)testHandlesNullFirst { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.error = @"foobar"; - NSDictionary *dict = [reply toMap]; - ACMessageSearchReply *copy = [ACMessageSearchReply fromMap:dict]; + NSArray *list = [reply toList]; + ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertEqual(reply.error, copy.error); } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart index c3f9fe3a122..9b07455774f 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.0.2), do not edit directly. +// Autogenerated from Pigeon (v4.2.9), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -29,57 +29,67 @@ class Everything { }); bool? aBool; + int? anInt; + double? aDouble; + String? aString; + Uint8List? aByteArray; + Int32List? a4ByteArray; + Int64List? a8ByteArray; + Float64List? aFloatArray; + List? aList; + Map? aMap; + List?>? nestedList; + Map? mapWithAnnotations; + Map? mapWithObject; Object encode() { - final Map pigeonMap = {}; - pigeonMap['aBool'] = aBool; - pigeonMap['anInt'] = anInt; - pigeonMap['aDouble'] = aDouble; - pigeonMap['aString'] = aString; - pigeonMap['aByteArray'] = aByteArray; - pigeonMap['a4ByteArray'] = a4ByteArray; - pigeonMap['a8ByteArray'] = a8ByteArray; - pigeonMap['aFloatArray'] = aFloatArray; - pigeonMap['aList'] = aList; - pigeonMap['aMap'] = aMap; - pigeonMap['nestedList'] = nestedList; - pigeonMap['mapWithAnnotations'] = mapWithAnnotations; - pigeonMap['mapWithObject'] = mapWithObject; - return pigeonMap; + final List pigeonList = []; + pigeonList.add(aBool); + pigeonList.add(anInt); + pigeonList.add(aDouble); + pigeonList.add(aString); + pigeonList.add(aByteArray); + pigeonList.add(a4ByteArray); + pigeonList.add(a8ByteArray); + pigeonList.add(aFloatArray); + pigeonList.add(aList); + pigeonList.add(aMap); + pigeonList.add(nestedList); + pigeonList.add(mapWithAnnotations); + pigeonList.add(mapWithObject); + return pigeonList; } - static Everything decode(Object message) { - final Map pigeonMap = message as Map; + static Everything decode(Object result) { + result as List; return Everything( - aBool: pigeonMap['aBool'] as bool?, - anInt: pigeonMap['anInt'] as int?, - aDouble: pigeonMap['aDouble'] as double?, - aString: pigeonMap['aString'] as String?, - aByteArray: pigeonMap['aByteArray'] as Uint8List?, - a4ByteArray: pigeonMap['a4ByteArray'] as Int32List?, - a8ByteArray: pigeonMap['a8ByteArray'] as Int64List?, - aFloatArray: pigeonMap['aFloatArray'] as Float64List?, - aList: pigeonMap['aList'] as List?, - aMap: pigeonMap['aMap'] as Map?, - nestedList: - (pigeonMap['nestedList'] as List?)?.cast?>(), + aBool: result[0] as bool?, + anInt: result[1] as int?, + aDouble: result[2] as double?, + aString: result[3] as String?, + aByteArray: result[4] as Uint8List?, + a4ByteArray: result[5] as Int32List?, + a8ByteArray: result[6] as Int64List?, + aFloatArray: result[7] as Float64List?, + aList: result[8] as List?, + aMap: result[9] as Map?, + nestedList: (result[10] as List?)?.cast?>(), mapWithAnnotations: - (pigeonMap['mapWithAnnotations'] as Map?) - ?.cast(), - mapWithObject: (pigeonMap['mapWithObject'] as Map?) - ?.cast(), + (result[11] as Map?)?.cast(), + mapWithObject: + (result[12] as Map?)?.cast(), ); } } @@ -100,7 +110,7 @@ class _HostEverythingCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return Everything.decode(readValue(buffer)!); + return Everything.decode(readValue(buffer)! as List); default: return super.readValueOfType(type, buffer); @@ -114,7 +124,6 @@ class HostEverything { /// BinaryMessenger will be used which routes to the host platform. HostEverything({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _HostEverythingCodec(); @@ -123,28 +132,25 @@ class HostEverything { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostEverything.giveMeEverything', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: (replyList[0] as String?)!, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Everything?)!; + return (replyList[0] as Everything?)!; } } @@ -152,28 +158,26 @@ class HostEverything { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostEverything.echo', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_everything]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: (replyList[0] as String?)!, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Everything?)!; + return (replyList[0] as Everything?)!; } } } @@ -194,7 +198,7 @@ class _FlutterEverythingCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return Everything.decode(readValue(buffer)!); + return Everything.decode(readValue(buffer)! as List); default: return super.readValueOfType(type, buffer); @@ -206,7 +210,9 @@ abstract class FlutterEverything { static const MessageCodec codec = _FlutterEverythingCodec(); Everything giveMeEverything(); + Everything echo(Everything everything); + static void setup(FlutterEverything? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index 048415138bc..4ff2bc07562 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.11), do not edit directly. +// Autogenerated from Pigeon (v4.2.12), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -33,47 +33,57 @@ class AllTypes { }); bool aBool; + int anInt; + double aDouble; + String aString; + Uint8List aByteArray; + Int32List a4ByteArray; + Int64List a8ByteArray; + Float64List aFloatArray; + List aList; + Map aMap; + AnEnum anEnum; Object encode() { - final Map pigeonMap = {}; - pigeonMap['aBool'] = aBool; - pigeonMap['anInt'] = anInt; - pigeonMap['aDouble'] = aDouble; - pigeonMap['aString'] = aString; - pigeonMap['aByteArray'] = aByteArray; - pigeonMap['a4ByteArray'] = a4ByteArray; - pigeonMap['a8ByteArray'] = a8ByteArray; - pigeonMap['aFloatArray'] = aFloatArray; - pigeonMap['aList'] = aList; - pigeonMap['aMap'] = aMap; - pigeonMap['anEnum'] = anEnum.index; - return pigeonMap; - } - - static AllTypes decode(Object message) { - final Map pigeonMap = message as Map; + return [ + aBool, + anInt, + aDouble, + aString, + aByteArray, + a4ByteArray, + a8ByteArray, + aFloatArray, + aList, + aMap, + anEnum.index, + ]; + } + + static AllTypes decode(Object result) { + result as List; return AllTypes( - aBool: pigeonMap['aBool']! as bool, - anInt: pigeonMap['anInt']! as int, - aDouble: pigeonMap['aDouble']! as double, - aString: pigeonMap['aString']! as String, - aByteArray: pigeonMap['aByteArray']! as Uint8List, - a4ByteArray: pigeonMap['a4ByteArray']! as Int32List, - a8ByteArray: pigeonMap['a8ByteArray']! as Int64List, - aFloatArray: pigeonMap['aFloatArray']! as Float64List, - aList: pigeonMap['aList']! as List, - aMap: pigeonMap['aMap']! as Map, - anEnum: AnEnum.values[pigeonMap['anEnum']! as int], + aBool: result[0]! as bool, + anInt: result[1]! as int, + aDouble: result[2]! as double, + aString: result[3]! as String, + aByteArray: result[4]! as Uint8List, + a4ByteArray: result[5]! as Int32List, + a8ByteArray: result[6]! as Int64List, + aFloatArray: result[7]! as Float64List, + aList: result[8]! as List, + aMap: result[9]! as Map, + anEnum: AnEnum.values[result[10]! as int], ); } } @@ -97,63 +107,72 @@ class AllNullableTypes { }); bool? aNullableBool; + int? aNullableInt; + double? aNullableDouble; + String? aNullableString; + Uint8List? aNullableByteArray; + Int32List? aNullable4ByteArray; + Int64List? aNullable8ByteArray; + Float64List? aNullableFloatArray; + List? aNullableList; + Map? aNullableMap; + List?>? nullableNestedList; + Map? nullableMapWithAnnotations; + Map? nullableMapWithObject; + AnEnum? aNullableEnum; Object encode() { - final Map pigeonMap = {}; - pigeonMap['aNullableBool'] = aNullableBool; - pigeonMap['aNullableInt'] = aNullableInt; - pigeonMap['aNullableDouble'] = aNullableDouble; - pigeonMap['aNullableString'] = aNullableString; - pigeonMap['aNullableByteArray'] = aNullableByteArray; - pigeonMap['aNullable4ByteArray'] = aNullable4ByteArray; - pigeonMap['aNullable8ByteArray'] = aNullable8ByteArray; - pigeonMap['aNullableFloatArray'] = aNullableFloatArray; - pigeonMap['aNullableList'] = aNullableList; - pigeonMap['aNullableMap'] = aNullableMap; - pigeonMap['nullableNestedList'] = nullableNestedList; - pigeonMap['nullableMapWithAnnotations'] = nullableMapWithAnnotations; - pigeonMap['nullableMapWithObject'] = nullableMapWithObject; - pigeonMap['aNullableEnum'] = aNullableEnum?.index; - return pigeonMap; - } - - static AllNullableTypes decode(Object message) { - final Map pigeonMap = message as Map; + return [ + aNullableBool, + aNullableInt, + aNullableDouble, + aNullableString, + aNullableByteArray, + aNullable4ByteArray, + aNullable8ByteArray, + aNullableFloatArray, + aNullableList, + aNullableMap, + nullableNestedList, + nullableMapWithAnnotations, + nullableMapWithObject, + aNullableEnum?.index, + ]; + } + + static AllNullableTypes decode(Object result) { + result as List; return AllNullableTypes( - aNullableBool: pigeonMap['aNullableBool'] as bool?, - aNullableInt: pigeonMap['aNullableInt'] as int?, - aNullableDouble: pigeonMap['aNullableDouble'] as double?, - aNullableString: pigeonMap['aNullableString'] as String?, - aNullableByteArray: pigeonMap['aNullableByteArray'] as Uint8List?, - aNullable4ByteArray: pigeonMap['aNullable4ByteArray'] as Int32List?, - aNullable8ByteArray: pigeonMap['aNullable8ByteArray'] as Int64List?, - aNullableFloatArray: pigeonMap['aNullableFloatArray'] as Float64List?, - aNullableList: pigeonMap['aNullableList'] as List?, - aNullableMap: pigeonMap['aNullableMap'] as Map?, - nullableNestedList: (pigeonMap['nullableNestedList'] as List?) - ?.cast?>(), + aNullableBool: result[0] as bool?, + aNullableInt: result[1] as int?, + aNullableDouble: result[2] as double?, + aNullableString: result[3] as String?, + aNullableByteArray: result[4] as Uint8List?, + aNullable4ByteArray: result[5] as Int32List?, + aNullable8ByteArray: result[6] as Int64List?, + aNullableFloatArray: result[7] as Float64List?, + aNullableList: result[8] as List?, + aNullableMap: result[9] as Map?, + nullableNestedList: (result[10] as List?)?.cast?>(), nullableMapWithAnnotations: - (pigeonMap['nullableMapWithAnnotations'] as Map?) - ?.cast(), + (result[11] as Map?)?.cast(), nullableMapWithObject: - (pigeonMap['nullableMapWithObject'] as Map?) - ?.cast(), - aNullableEnum: pigeonMap['aNullableEnum'] != null - ? AnEnum.values[pigeonMap['aNullableEnum']! as int] - : null, + (result[12] as Map?)?.cast(), + aNullableEnum: + result[13] != null ? AnEnum.values[result[13]! as int] : null, ); } } @@ -166,15 +185,15 @@ class AllNullableTypesWrapper { AllNullableTypes values; Object encode() { - final Map pigeonMap = {}; - pigeonMap['values'] = values.encode(); - return pigeonMap; + return [ + values.encode(), + ]; } - static AllNullableTypesWrapper decode(Object message) { - final Map pigeonMap = message as Map; + static AllNullableTypesWrapper decode(Object result) { + result as List; return AllNullableTypesWrapper( - values: AllNullableTypes.decode(pigeonMap['values']!), + values: AllNullableTypes.decode(result[0]! as List), ); } } @@ -239,20 +258,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.noop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -264,28 +280,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_everything]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllTypes?)!; + return (replyList[0] as AllTypes?)!; } } @@ -295,23 +309,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_everything]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as AllNullableTypes?); + return (replyList[0] as AllNullableTypes?); } } @@ -320,20 +332,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.throwError', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -345,28 +354,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_anInt]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_anInt]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } @@ -375,28 +382,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aDouble]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aDouble]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as double?)!; + return (replyList[0] as double?)!; } } @@ -405,28 +410,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoBool', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aBool]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aBool]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as bool?)!; + return (replyList[0] as bool?)!; } } @@ -435,28 +438,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } @@ -465,28 +466,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aUint8List]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aUint8List]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Uint8List?)!; + return (replyList[0] as Uint8List?)!; } } @@ -498,23 +497,21 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_wrapper]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_wrapper]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -526,28 +523,26 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_nullableString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_nullableString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllNullableTypesWrapper?)!; + return (replyList[0] as AllNullableTypesWrapper?)!; } } @@ -558,29 +553,27 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel.send( + final List? replyList = await channel.send( [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) - as Map?; - if (replyMap == null) { + as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllNullableTypes?)!; + return (replyList[0] as AllNullableTypes?)!; } } @@ -589,23 +582,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableInt]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableInt]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as int?); + return (replyList[0] as int?); } } @@ -614,23 +605,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableDouble]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableDouble]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as double?); + return (replyList[0] as double?); } } @@ -639,23 +628,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableBool]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableBool]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as bool?); + return (replyList[0] as bool?); } } @@ -664,23 +651,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -691,23 +676,21 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableUint8List]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableUint8List]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as Uint8List?); + return (replyList[0] as Uint8List?); } } @@ -717,20 +700,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -742,28 +722,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } @@ -771,20 +749,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -796,28 +771,26 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } } @@ -869,6 +842,7 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed string, to test serialization and deserialization. String echoString(String aString); + static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -963,20 +937,17 @@ class HostTrivialApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostTrivialApi.noop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index de6fed0cf2a..a3145679319 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -25,28 +25,26 @@ class MultipleArityHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.MultipleArityHostApi.subtract', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_x, arg_y]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_x, arg_y]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } } @@ -55,6 +53,7 @@ abstract class MultipleArityFlutterApi { static const MessageCodec codec = StandardMessageCodec(); int subtract(int x, int y); + static void setup(MultipleArityFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index 2c19540ef12..0dafa689085 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -24,15 +24,15 @@ class NonNullFieldSearchRequest { String query; Object encode() { - final Map pigeonMap = {}; - pigeonMap['query'] = query; - return pigeonMap; + return [ + query, + ]; } - static NonNullFieldSearchRequest decode(Object message) { - final Map pigeonMap = message as Map; + static NonNullFieldSearchRequest decode(Object result) { + result as List; return NonNullFieldSearchRequest( - query: pigeonMap['query']! as String, + query: result[0]! as String, ); } } @@ -44,20 +44,21 @@ class ExtraData { }); String detailA; + String detailB; Object encode() { - final Map pigeonMap = {}; - pigeonMap['detailA'] = detailA; - pigeonMap['detailB'] = detailB; - return pigeonMap; + return [ + detailA, + detailB, + ]; } - static ExtraData decode(Object message) { - final Map pigeonMap = message as Map; + static ExtraData decode(Object result) { + result as List; return ExtraData( - detailA: pigeonMap['detailA']! as String, - detailB: pigeonMap['detailB']! as String, + detailA: result[0]! as String, + detailB: result[1]! as String, ); } } @@ -72,29 +73,33 @@ class NonNullFieldSearchReply { }); String result; + String error; + List indices; + ExtraData extraData; + ReplyType type; Object encode() { - final Map pigeonMap = {}; - pigeonMap['result'] = result; - pigeonMap['error'] = error; - pigeonMap['indices'] = indices; - pigeonMap['extraData'] = extraData.encode(); - pigeonMap['type'] = type.index; - return pigeonMap; + return [ + result, + error, + indices, + extraData.encode(), + type.index, + ]; } - static NonNullFieldSearchReply decode(Object message) { - final Map pigeonMap = message as Map; + static NonNullFieldSearchReply decode(Object result) { + result as List; return NonNullFieldSearchReply( - result: pigeonMap['result']! as String, - error: pigeonMap['error']! as String, - indices: (pigeonMap['indices'] as List?)!.cast(), - extraData: ExtraData.decode(pigeonMap['extraData']!), - type: ReplyType.values[pigeonMap['type']! as int], + result: result[0]! as String, + error: result[1]! as String, + indices: (result[2] as List?)!.cast(), + extraData: ExtraData.decode(result[3]! as List), + type: ReplyType.values[result[4]! as int], ); } } @@ -150,28 +155,26 @@ class NonNullFieldHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NonNullFieldHostApi.search', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_nested]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_nested]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as NonNullFieldSearchReply?)!; + return (replyList[0] as NonNullFieldSearchReply?)!; } } } @@ -216,6 +219,7 @@ abstract class NonNullFieldFlutterApi { static const MessageCodec codec = _NonNullFieldFlutterApiCodec(); NonNullFieldSearchReply search(NonNullFieldSearchRequest request); + static void setup(NonNullFieldFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index 6e26deb57d2..94c9b86a8a5 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -23,20 +23,21 @@ class NullFieldsSearchRequest { }); String? query; + int identifier; Object encode() { - final Map pigeonMap = {}; - pigeonMap['query'] = query; - pigeonMap['identifier'] = identifier; - return pigeonMap; + return [ + query, + identifier, + ]; } - static NullFieldsSearchRequest decode(Object message) { - final Map pigeonMap = message as Map; + static NullFieldsSearchRequest decode(Object result) { + result as List; return NullFieldsSearchRequest( - query: pigeonMap['query'] as String?, - identifier: pigeonMap['identifier']! as int, + query: result[0] as String?, + identifier: result[1]! as int, ); } } @@ -51,32 +52,36 @@ class NullFieldsSearchReply { }); String? result; + String? error; + List? indices; + NullFieldsSearchRequest? request; + NullFieldsSearchReplyType? type; Object encode() { - final Map pigeonMap = {}; - pigeonMap['result'] = result; - pigeonMap['error'] = error; - pigeonMap['indices'] = indices; - pigeonMap['request'] = request?.encode(); - pigeonMap['type'] = type?.index; - return pigeonMap; + return [ + result, + error, + indices, + request?.encode(), + type?.index, + ]; } - static NullFieldsSearchReply decode(Object message) { - final Map pigeonMap = message as Map; + static NullFieldsSearchReply decode(Object result) { + result as List; return NullFieldsSearchReply( - result: pigeonMap['result'] as String?, - error: pigeonMap['error'] as String?, - indices: (pigeonMap['indices'] as List?)?.cast(), - request: pigeonMap['request'] != null - ? NullFieldsSearchRequest.decode(pigeonMap['request']!) + result: result[0] as String?, + error: result[1] as String?, + indices: (result[2] as List?)?.cast(), + request: result[3] != null + ? NullFieldsSearchRequest.decode(result[3]! as List) : null, - type: pigeonMap['type'] != null - ? NullFieldsSearchReplyType.values[pigeonMap['type']! as int] + type: result[4] != null + ? NullFieldsSearchReplyType.values[result[4]! as int] : null, ); } @@ -127,28 +132,26 @@ class NullFieldsHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NullFieldsHostApi.search', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_nested]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_nested]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as NullFieldsSearchReply?)!; + return (replyList[0] as NullFieldsSearchReply?)!; } } } @@ -187,6 +190,7 @@ abstract class NullFieldsFlutterApi { static const MessageCodec codec = _NullFieldsFlutterApiCodec(); NullFieldsSearchReply search(NullFieldsSearchRequest request); + static void setup(NullFieldsFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_safe_pigeon.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_safe_pigeon.dart index f643345c06b..f376a13a932 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_safe_pigeon.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_safe_pigeon.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -19,15 +19,15 @@ class FlutterSearchRequest { String? query; Object encode() { - final Map pigeonMap = {}; - pigeonMap['query'] = query; - return pigeonMap; + return [ + query, + ]; } - static FlutterSearchRequest decode(Object message) { - final Map pigeonMap = message as Map; + static FlutterSearchRequest decode(Object result) { + result as List; return FlutterSearchRequest( - query: pigeonMap['query'] as String?, + query: result[0] as String?, ); } } @@ -39,20 +39,21 @@ class FlutterSearchReply { }); String? result; + String? error; Object encode() { - final Map pigeonMap = {}; - pigeonMap['result'] = result; - pigeonMap['error'] = error; - return pigeonMap; + return [ + result, + error, + ]; } - static FlutterSearchReply decode(Object message) { - final Map pigeonMap = message as Map; + static FlutterSearchReply decode(Object result) { + result as List; return FlutterSearchReply( - result: pigeonMap['result'] as String?, - error: pigeonMap['error'] as String?, + result: result[0] as String?, + error: result[1] as String?, ); } } @@ -65,15 +66,15 @@ class FlutterSearchRequests { List? requests; Object encode() { - final Map pigeonMap = {}; - pigeonMap['requests'] = requests; - return pigeonMap; + return [ + requests, + ]; } - static FlutterSearchRequests decode(Object message) { - final Map pigeonMap = message as Map; + static FlutterSearchRequests decode(Object result) { + result as List; return FlutterSearchRequests( - requests: pigeonMap['requests'] as List?, + requests: result[0] as List?, ); } } @@ -86,15 +87,15 @@ class FlutterSearchReplies { List? replies; Object encode() { - final Map pigeonMap = {}; - pigeonMap['replies'] = replies; - return pigeonMap; + return [ + replies, + ]; } - static FlutterSearchReplies decode(Object message) { - final Map pigeonMap = message as Map; + static FlutterSearchReplies decode(Object result) { + result as List; return FlutterSearchReplies( - replies: pigeonMap['replies'] as List?, + replies: result[0] as List?, ); } } @@ -154,28 +155,26 @@ class Api { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.Api.search', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_request]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_request]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as FlutterSearchReply?)!; + return (replyList[0] as FlutterSearchReply?)!; } } @@ -184,28 +183,26 @@ class Api { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.Api.doSearches', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_request]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_request]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as FlutterSearchReplies?)!; + return (replyList[0] as FlutterSearchReplies?)!; } } @@ -213,28 +210,26 @@ class Api { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.Api.echo', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_requests]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_requests]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as FlutterSearchRequests?)!; + return (replyList[0] as FlutterSearchRequests?)!; } } @@ -242,28 +237,26 @@ class Api { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.Api.anInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 90bda832aab..e88028363d8 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -25,23 +25,20 @@ class NullableReturnHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NullableReturnHostApi.doit', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as int?); + return (replyList[0] as int?); } } } @@ -50,6 +47,7 @@ abstract class NullableReturnFlutterApi { static const MessageCodec codec = StandardMessageCodec(); int? doit(); + static void setup(NullableReturnFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -83,28 +81,26 @@ class NullableArgHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NullableArgHostApi.doit', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_x]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_x]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } } @@ -113,6 +109,7 @@ abstract class NullableArgFlutterApi { static const MessageCodec codec = StandardMessageCodec(); int doit(int? x); + static void setup(NullableArgFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -149,23 +146,20 @@ class NullableCollectionReturnHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NullableCollectionReturnHostApi.doit', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as List?)?.cast(); + return (replyList[0] as List?)?.cast(); } } } @@ -174,6 +168,7 @@ abstract class NullableCollectionReturnFlutterApi { static const MessageCodec codec = StandardMessageCodec(); List? doit(); + static void setup(NullableCollectionReturnFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -207,28 +202,26 @@ class NullableCollectionArgHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.NullableCollectionArgHostApi.doit', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_x]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_x]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as List?)!.cast(); + return (replyList[0] as List?)!.cast(); } } } @@ -237,6 +230,7 @@ abstract class NullableCollectionArgFlutterApi { static const MessageCodec codec = StandardMessageCodec(); List doit(List? x); + static void setup(NullableCollectionArgFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.dart index 02ad4282db6..178e3154578 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.7), do not edit directly. +// Autogenerated from Pigeon (v4.2.11), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -25,28 +25,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.anInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } @@ -54,28 +52,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aBool', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as bool?)!; + return (replyList[0] as bool?)!; } } @@ -83,28 +79,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } @@ -112,28 +106,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aDouble', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as double?)!; + return (replyList[0] as double?)!; } } @@ -141,28 +133,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aMap', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Map?)!; + return (replyList[0] as Map?)!; } } @@ -170,28 +160,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aList', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as List?)!; + return (replyList[0] as List?)!; } } @@ -199,28 +187,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.anInt32List', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Int32List?)!; + return (replyList[0] as Int32List?)!; } } @@ -228,28 +214,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aBoolList', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as List?)!.cast(); + return (replyList[0] as List?)!.cast(); } } @@ -257,29 +241,26 @@ class PrimitiveHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PrimitiveHostApi.aStringIntMap', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_value]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_value]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Map?)! - .cast(); + return (replyList[0] as Map?)!.cast(); } } } @@ -288,14 +269,23 @@ abstract class PrimitiveFlutterApi { static const MessageCodec codec = StandardMessageCodec(); int anInt(int value); + bool aBool(bool value); + String aString(String value); + double aDouble(double value); + Map aMap(Map value); + List aList(List value); + Int32List anInt32List(Int32List value); + List aBoolList(List value); + Map aStringIntMap(Map value); + static void setup(PrimitiveFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/multiple_arity_test.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/multiple_arity_test.dart index b0ea0b5dfae..95b38ea5947 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/multiple_arity_test.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/multiple_arity_test.dart @@ -21,8 +21,7 @@ void main() { final List args = input as List; final int x = (args[0] as int?)!; final int y = (args[1] as int?)!; - return MultipleArityHostApi.codec - .encodeMessage({'result': x - y}); + return MultipleArityHostApi.codec.encodeMessage([x - y]); }); final MultipleArityHostApi api = diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_fields_test.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_fields_test.dart index 7cb73be22cd..ec75a8ea169 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_fields_test.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_fields_test.dart @@ -44,36 +44,35 @@ void main() { test('test request decode with values', () { final NullFieldsSearchRequest request = - NullFieldsSearchRequest.decode({ - 'query': 'query', - 'identifier': 1, - }); + NullFieldsSearchRequest.decode([ + 'query', + 1, + ]); expect(request.query, 'query'); }); test('test request decode with null', () { final NullFieldsSearchRequest request = - NullFieldsSearchRequest.decode({ - 'query': null, - 'identifier': 1, - }); + NullFieldsSearchRequest.decode([ + null, + 1, + ]); expect(request.query, isNull); }); test('test reply decode with values', () { - final NullFieldsSearchReply reply = - NullFieldsSearchReply.decode({ - 'result': 'result', - 'error': 'error', - 'indices': [1, 2, 3], - 'request': { - 'query': 'query', - 'identifier': 1, - }, - 'type': NullFieldsSearchReplyType.success.index, - }); + final NullFieldsSearchReply reply = NullFieldsSearchReply.decode([ + 'result', + 'error', + [1, 2, 3], + [ + 'query', + 1, + ], + NullFieldsSearchReplyType.success.index, + ]); expect(reply.result, 'result'); expect(reply.error, 'error'); @@ -83,14 +82,13 @@ void main() { }); test('test reply decode with nulls', () { - final NullFieldsSearchReply reply = - NullFieldsSearchReply.decode({ - 'result': null, - 'error': null, - 'indices': null, - 'request': null, - 'type': null, - }); + final NullFieldsSearchReply reply = NullFieldsSearchReply.decode([ + null, + null, + null, + null, + null, + ]); expect(reply.result, isNull); expect(reply.error, isNull); @@ -103,20 +101,20 @@ void main() { final NullFieldsSearchRequest request = NullFieldsSearchRequest(query: 'query', identifier: 1); - expect(request.encode(), { - 'query': 'query', - 'identifier': 1, - }); + expect(request.encode(), [ + 'query', + 1, + ]); }); test('test request encode with null', () { final NullFieldsSearchRequest request = NullFieldsSearchRequest(identifier: 1); - expect(request.encode(), { - 'query': null, - 'identifier': 1, - }); + expect(request.encode(), [ + null, + 1, + ]); }); test('test reply encode with values', () { @@ -128,27 +126,27 @@ void main() { type: NullFieldsSearchReplyType.success, ); - expect(reply.encode(), { - 'result': 'result', - 'error': 'error', - 'indices': [1, 2, 3], - 'request': { - 'query': 'query', - 'identifier': 1, - }, - 'type': NullFieldsSearchReplyType.success.index, - }); + expect(reply.encode(), [ + 'result', + 'error', + [1, 2, 3], + [ + 'query', + 1, + ], + NullFieldsSearchReplyType.success.index, + ]); }); test('test reply encode with nulls', () { final NullFieldsSearchReply reply = NullFieldsSearchReply(); - expect(reply.encode(), { - 'result': null, - 'error': null, - 'indices': null, - 'request': null, - 'type': null, - }); + expect(reply.encode(), [ + null, + null, + null, + null, + null, + ]); }); } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_safe_test.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_safe_test.dart index 4d944a4cf95..317bea9394a 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_safe_test.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_safe_test.dart @@ -28,7 +28,7 @@ void main() { final FlutterSearchReply reply = FlutterSearchReply() ..result = 'foo' ..error = 'bar'; - final Object encoded = reply.encode(); + final List encoded = reply.encode() as List; final FlutterSearchReply decoded = FlutterSearchReply.decode(encoded); expect(reply.result, decoded.result); expect(reply.error, decoded.error); @@ -38,7 +38,7 @@ void main() { final FlutterSearchReply reply = FlutterSearchReply() ..result = 'foo' ..error = null; - final Object encoded = reply.encode(); + final List encoded = reply.encode() as List; final FlutterSearchReply decoded = FlutterSearchReply.decode(encoded); expect(reply.result, decoded.result); expect(reply.error, decoded.error); @@ -49,8 +49,7 @@ void main() { final FlutterSearchReply reply = FlutterSearchReply()..result = 'ho'; final BinaryMessenger mockMessenger = MockBinaryMessenger(); final Completer completer = Completer(); - completer - .complete(Api.codec.encodeMessage({'result': reply})); + completer.complete(Api.codec.encodeMessage([reply])); final Future sendResult = completer.future; when(mockMessenger.send('dev.flutter.pigeon.Api.search', any)) .thenAnswer((Invocation realInvocation) => sendResult); @@ -93,7 +92,7 @@ void main() { const String channel = 'dev.flutter.pigeon.Api.anInt'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage({'result': null}); + return Api.codec.encodeMessage([null]); }); final Api api = Api(binaryMessenger: mockMessenger); expect(() async => api.anInt(1), @@ -105,7 +104,7 @@ void main() { const String channel = 'dev.flutter.pigeon.NullableArgHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage({'result': 123}); + return Api.codec.encodeMessage([123]); }); final NullableArgHostApi api = NullableArgHostApi(binaryMessenger: mockMessenger); @@ -118,9 +117,9 @@ void main() { 'dev.flutter.pigeon.NullableCollectionArgHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return Api.codec.encodeMessage({ - 'result': ['123'] - }); + return Api.codec.encodeMessage([ + ['123'] + ]); }); final NullableCollectionArgHostApi api = NullableCollectionArgHostApi(binaryMessenger: mockMessenger); @@ -182,8 +181,7 @@ void main() { const String channel = 'dev.flutter.pigeon.NullableReturnHostApi.doit'; when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { - return NullableReturnHostApi.codec - .encodeMessage({'result': null}); + return NullableReturnHostApi.codec.encodeMessage([null]); }); final NullableReturnHostApi api = NullableReturnHostApi(binaryMessenger: mockMessenger); @@ -197,7 +195,7 @@ void main() { when(mockMessenger.send(channel, any)) .thenAnswer((Invocation realInvocation) async { return NullableCollectionReturnHostApi.codec - .encodeMessage({'result': null}); + .encodeMessage([null]); }); final NullableCollectionReturnHostApi api = NullableCollectionReturnHostApi(binaryMessenger: mockMessenger); diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/test_util.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/test_util.dart index ec695fc79a3..a776c00f9d9 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/test_util.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/test_util.dart @@ -15,6 +15,6 @@ void echoOneArgument( final Object input = codec.decodeMessage(realInvocation.positionalArguments[1])!; final List args = input as List; - return codec.encodeMessage({'result': args[0]!}); + return codec.encodeMessage([args[0]!]); }); } diff --git a/packages/pigeon/platform_tests/ios_unit_tests/ios/Flutter/AppFrameworkInfo.plist b/packages/pigeon/platform_tests/ios_unit_tests/ios/Flutter/AppFrameworkInfo.plist index f2872cf474e..4f8d4d2456f 100644 --- a/packages/pigeon/platform_tests/ios_unit_tests/ios/Flutter/AppFrameworkInfo.plist +++ b/packages/pigeon/platform_tests/ios_unit_tests/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/project.pbxproj b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/project.pbxproj index 8122323e7e2..aa01ef951f8 100644 --- a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -366,6 +366,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -380,6 +381,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -591,7 +593,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -670,7 +672,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -719,7 +721,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner/Info.plist b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner/Info.plist index db82370fd76..83d94353428 100644 --- a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner/Info.plist +++ b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner/Info.plist @@ -43,5 +43,7 @@ CADisableMinimumFrameDurationOnPhone + UIApplicationSupportsIndirectInputEvents + diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 048415138bc..4ff2bc07562 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v4.2.11), do not edit directly. +// Autogenerated from Pigeon (v4.2.12), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -33,47 +33,57 @@ class AllTypes { }); bool aBool; + int anInt; + double aDouble; + String aString; + Uint8List aByteArray; + Int32List a4ByteArray; + Int64List a8ByteArray; + Float64List aFloatArray; + List aList; + Map aMap; + AnEnum anEnum; Object encode() { - final Map pigeonMap = {}; - pigeonMap['aBool'] = aBool; - pigeonMap['anInt'] = anInt; - pigeonMap['aDouble'] = aDouble; - pigeonMap['aString'] = aString; - pigeonMap['aByteArray'] = aByteArray; - pigeonMap['a4ByteArray'] = a4ByteArray; - pigeonMap['a8ByteArray'] = a8ByteArray; - pigeonMap['aFloatArray'] = aFloatArray; - pigeonMap['aList'] = aList; - pigeonMap['aMap'] = aMap; - pigeonMap['anEnum'] = anEnum.index; - return pigeonMap; - } - - static AllTypes decode(Object message) { - final Map pigeonMap = message as Map; + return [ + aBool, + anInt, + aDouble, + aString, + aByteArray, + a4ByteArray, + a8ByteArray, + aFloatArray, + aList, + aMap, + anEnum.index, + ]; + } + + static AllTypes decode(Object result) { + result as List; return AllTypes( - aBool: pigeonMap['aBool']! as bool, - anInt: pigeonMap['anInt']! as int, - aDouble: pigeonMap['aDouble']! as double, - aString: pigeonMap['aString']! as String, - aByteArray: pigeonMap['aByteArray']! as Uint8List, - a4ByteArray: pigeonMap['a4ByteArray']! as Int32List, - a8ByteArray: pigeonMap['a8ByteArray']! as Int64List, - aFloatArray: pigeonMap['aFloatArray']! as Float64List, - aList: pigeonMap['aList']! as List, - aMap: pigeonMap['aMap']! as Map, - anEnum: AnEnum.values[pigeonMap['anEnum']! as int], + aBool: result[0]! as bool, + anInt: result[1]! as int, + aDouble: result[2]! as double, + aString: result[3]! as String, + aByteArray: result[4]! as Uint8List, + a4ByteArray: result[5]! as Int32List, + a8ByteArray: result[6]! as Int64List, + aFloatArray: result[7]! as Float64List, + aList: result[8]! as List, + aMap: result[9]! as Map, + anEnum: AnEnum.values[result[10]! as int], ); } } @@ -97,63 +107,72 @@ class AllNullableTypes { }); bool? aNullableBool; + int? aNullableInt; + double? aNullableDouble; + String? aNullableString; + Uint8List? aNullableByteArray; + Int32List? aNullable4ByteArray; + Int64List? aNullable8ByteArray; + Float64List? aNullableFloatArray; + List? aNullableList; + Map? aNullableMap; + List?>? nullableNestedList; + Map? nullableMapWithAnnotations; + Map? nullableMapWithObject; + AnEnum? aNullableEnum; Object encode() { - final Map pigeonMap = {}; - pigeonMap['aNullableBool'] = aNullableBool; - pigeonMap['aNullableInt'] = aNullableInt; - pigeonMap['aNullableDouble'] = aNullableDouble; - pigeonMap['aNullableString'] = aNullableString; - pigeonMap['aNullableByteArray'] = aNullableByteArray; - pigeonMap['aNullable4ByteArray'] = aNullable4ByteArray; - pigeonMap['aNullable8ByteArray'] = aNullable8ByteArray; - pigeonMap['aNullableFloatArray'] = aNullableFloatArray; - pigeonMap['aNullableList'] = aNullableList; - pigeonMap['aNullableMap'] = aNullableMap; - pigeonMap['nullableNestedList'] = nullableNestedList; - pigeonMap['nullableMapWithAnnotations'] = nullableMapWithAnnotations; - pigeonMap['nullableMapWithObject'] = nullableMapWithObject; - pigeonMap['aNullableEnum'] = aNullableEnum?.index; - return pigeonMap; - } - - static AllNullableTypes decode(Object message) { - final Map pigeonMap = message as Map; + return [ + aNullableBool, + aNullableInt, + aNullableDouble, + aNullableString, + aNullableByteArray, + aNullable4ByteArray, + aNullable8ByteArray, + aNullableFloatArray, + aNullableList, + aNullableMap, + nullableNestedList, + nullableMapWithAnnotations, + nullableMapWithObject, + aNullableEnum?.index, + ]; + } + + static AllNullableTypes decode(Object result) { + result as List; return AllNullableTypes( - aNullableBool: pigeonMap['aNullableBool'] as bool?, - aNullableInt: pigeonMap['aNullableInt'] as int?, - aNullableDouble: pigeonMap['aNullableDouble'] as double?, - aNullableString: pigeonMap['aNullableString'] as String?, - aNullableByteArray: pigeonMap['aNullableByteArray'] as Uint8List?, - aNullable4ByteArray: pigeonMap['aNullable4ByteArray'] as Int32List?, - aNullable8ByteArray: pigeonMap['aNullable8ByteArray'] as Int64List?, - aNullableFloatArray: pigeonMap['aNullableFloatArray'] as Float64List?, - aNullableList: pigeonMap['aNullableList'] as List?, - aNullableMap: pigeonMap['aNullableMap'] as Map?, - nullableNestedList: (pigeonMap['nullableNestedList'] as List?) - ?.cast?>(), + aNullableBool: result[0] as bool?, + aNullableInt: result[1] as int?, + aNullableDouble: result[2] as double?, + aNullableString: result[3] as String?, + aNullableByteArray: result[4] as Uint8List?, + aNullable4ByteArray: result[5] as Int32List?, + aNullable8ByteArray: result[6] as Int64List?, + aNullableFloatArray: result[7] as Float64List?, + aNullableList: result[8] as List?, + aNullableMap: result[9] as Map?, + nullableNestedList: (result[10] as List?)?.cast?>(), nullableMapWithAnnotations: - (pigeonMap['nullableMapWithAnnotations'] as Map?) - ?.cast(), + (result[11] as Map?)?.cast(), nullableMapWithObject: - (pigeonMap['nullableMapWithObject'] as Map?) - ?.cast(), - aNullableEnum: pigeonMap['aNullableEnum'] != null - ? AnEnum.values[pigeonMap['aNullableEnum']! as int] - : null, + (result[12] as Map?)?.cast(), + aNullableEnum: + result[13] != null ? AnEnum.values[result[13]! as int] : null, ); } } @@ -166,15 +185,15 @@ class AllNullableTypesWrapper { AllNullableTypes values; Object encode() { - final Map pigeonMap = {}; - pigeonMap['values'] = values.encode(); - return pigeonMap; + return [ + values.encode(), + ]; } - static AllNullableTypesWrapper decode(Object message) { - final Map pigeonMap = message as Map; + static AllNullableTypesWrapper decode(Object result) { + result as List; return AllNullableTypesWrapper( - values: AllNullableTypes.decode(pigeonMap['values']!), + values: AllNullableTypes.decode(result[0]! as List), ); } } @@ -239,20 +258,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.noop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -264,28 +280,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_everything]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllTypes?)!; + return (replyList[0] as AllTypes?)!; } } @@ -295,23 +309,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_everything]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_everything]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as AllNullableTypes?); + return (replyList[0] as AllNullableTypes?); } } @@ -320,20 +332,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.throwError', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -345,28 +354,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_anInt]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_anInt]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as int?)!; + return (replyList[0] as int?)!; } } @@ -375,28 +382,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aDouble]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aDouble]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as double?)!; + return (replyList[0] as double?)!; } } @@ -405,28 +410,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoBool', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aBool]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aBool]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as bool?)!; + return (replyList[0] as bool?)!; } } @@ -435,28 +438,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } @@ -465,28 +466,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aUint8List]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aUint8List]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as Uint8List?)!; + return (replyList[0] as Uint8List?)!; } } @@ -498,23 +497,21 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_wrapper]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_wrapper]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -526,28 +523,26 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_nullableString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_nullableString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllNullableTypesWrapper?)!; + return (replyList[0] as AllNullableTypesWrapper?)!; } } @@ -558,29 +553,27 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel.send( + final List? replyList = await channel.send( [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) - as Map?; - if (replyMap == null) { + as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as AllNullableTypes?)!; + return (replyList[0] as AllNullableTypes?)!; } } @@ -589,23 +582,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableInt]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableInt]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as int?); + return (replyList[0] as int?); } } @@ -614,23 +605,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableDouble]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableDouble]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as double?); + return (replyList[0] as double?); } } @@ -639,23 +628,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableBool]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableBool]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as bool?); + return (replyList[0] as bool?); } } @@ -664,23 +651,21 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } @@ -691,23 +676,21 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_aNullableUint8List]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aNullableUint8List]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as Uint8List?); + return (replyList[0] as Uint8List?); } } @@ -717,20 +700,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -742,28 +722,26 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } @@ -771,20 +749,17 @@ class HostIntegrationCoreApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -796,28 +771,26 @@ class HostIntegrationCoreApi { 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_aString]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_aString]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as String?)!; + return (replyList[0] as String?)!; } } } @@ -869,6 +842,7 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed string, to test serialization and deserialization. String echoString(String aString); + static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -963,20 +937,17 @@ class HostTrivialApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostTrivialApi.noop', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index ceba13b6718..9f42e1e43a9 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -101,11 +101,14 @@ internal class AllDatatypesTest: TestCase() { @Test fun testIntegerToLong() { val everything = AllNullableTypes(aNullableInt = 123L) - val map = everything.toMap() - assertTrue(map.containsKey("aNullableInt")) + val list = everything.toList() + assertNotNull(list) + assertNull(list.first()) + assertNotNull(list[1]) + assertTrue(list[1] == 123L) - val map2 = hashMapOf("aNullableInt" to 123) - val everything2 = AllNullableTypes.fromMap(map2) + val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null) + val everything2 = AllNullableTypes.fromList(list2) assertEquals(everything.aNullableInt, everything2.aNullableInt) } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt index 5a12c20267e..668e3d73660 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt @@ -70,10 +70,10 @@ internal class AsyncHandlersTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as MutableList? assertNotNull(wrapped) wrapped?.let { - assertEquals(output, wrapped["result"]) + assertEquals(output, wrapped.first()) } } @@ -104,7 +104,7 @@ internal class AsyncHandlersTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as MutableList? assertNull(wrapped) } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt index a0cf3f9aefa..205f90a10a0 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt @@ -36,11 +36,11 @@ internal class EnumTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertTrue(wrapped.containsKey("result")) - assertEquals(input, wrapped["result"]) + assertNotNull(wrapped[0]) + assertEquals(input, wrapped[0]) } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt index bbb1e6cae3b..55ff1638a89 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt @@ -36,10 +36,10 @@ class MultipleArityTests: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(inputX - inputY, wrapped["result"]) + assertEquals(inputX - inputY, wrapped[0]) } } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt index 7bb1474127b..14e09af8197 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt @@ -34,10 +34,10 @@ class NullableReturnsTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(output, wrapped["result"]) + assertEquals(output, wrapped[0]) } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt index c79adbea6e4..4deb3272c49 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt @@ -36,10 +36,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input.toLong(), wrapped["result"]) + assertEquals(input.toLong(), wrapped[0]) } } @@ -84,10 +84,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -132,10 +132,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -164,10 +164,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -212,10 +212,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -260,10 +260,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -308,10 +308,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertTrue(input.contentEquals(wrapped["result"] as IntArray)) + assertTrue(input.contentEquals(wrapped[0] as IntArray)) } } @@ -356,10 +356,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } @@ -404,10 +404,10 @@ class PrimitiveTest: TestCase() { handlerSlot.captured.onMessage(message) { it?.rewind() @Suppress("UNCHECKED_CAST") - val wrapped = codec.decodeMessage(it) as HashMap? + val wrapped = codec.decodeMessage(it) as List? assertNotNull(wrapped) wrapped?.let { - assertEquals(input, wrapped["result"]) + assertEquals(input, wrapped[0]) } } diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift index 817e04eb95f..a5a4ae7639a 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import XCTest @testable import test_plugin @@ -43,9 +42,8 @@ class AsyncHandlersTest: XCTestCase { let expectation = XCTestExpectation(description: "voidvoid callback") binaryMessenger.handlers[channelName]?(nil) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertEqual(outputMap?["result"] as! NSNull, NSNull()) - XCTAssertNil(outputMap?["error"]) + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertEqual(outputList?.first as! NSNull, NSNull()) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -64,8 +62,8 @@ class AsyncHandlersTest: XCTestCase { let expectation = XCTestExpectation(description: "calculate callback") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - let output = outputMap?["result"] as? Value + let outputList = binaryMessenger.codec.decode(data) as? [Any] + let output = outputList?.first as? Value XCTAssertEqual(output?.number, 2) expectation.fulfill() } diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift index cc789c63e2b..0247f888ae1 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift @@ -30,12 +30,12 @@ class EnumTests: XCTestCase { let expectation = XCTestExpectation(description: "echo") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] + let outputMap = binaryMessenger.codec.decode(data) as? [Any] XCTAssertNotNil(outputMap) - - let output = outputMap?["result"] as? DataWithEnum + + let output = outputMap?.first as? DataWithEnum XCTAssertEqual(output, input) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputMap?.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift index adf3182274b..6aead9f5489 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift @@ -26,12 +26,12 @@ class MultipleArityTests: XCTestCase { let expectation = XCTestExpectation(description: "subtraction") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? Int32 + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList![0] as? Int32 XCTAssertEqual(3, output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList?.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift index 7740ada3b96..2734f3c359e 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift @@ -32,12 +32,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "anInt") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? Int32 + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList!.first as? Int32 XCTAssertEqual(1, output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList!.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -66,12 +66,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "aBool") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? Bool + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList!.first as? Bool XCTAssertEqual(true, output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList!.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -100,12 +100,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "aDouble") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? Double + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList!.first as? Double XCTAssertEqual(1.0, output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList!.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -135,12 +135,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "aString") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? String + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList!.first as? String XCTAssertEqual("hello", output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList!.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -170,12 +170,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "aList") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) - - let output = outputMap!["result"] as? [Int] + let outputList = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertNotNil(outputList) + + let output = outputList!.first as? [Int] XCTAssertEqual([1, 2, 3], output) - XCTAssertNil(outputMap?["error"]) + XCTAssertTrue(outputList!.count == 1) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) @@ -205,12 +205,12 @@ class PrimitiveTests: XCTestCase { let expectation = XCTestExpectation(description: "aMap") binaryMessenger.handlers[channelName]?(inputEncoded) { data in - let outputMap = binaryMessenger.codec.decode(data) as? [String: Any] - XCTAssertNotNil(outputMap) + let output = binaryMessenger.codec.decode(data) as? [Any] + XCTAssertTrue(output?.count == 1) - let output = outputMap!["result"] as? [String: Int] - XCTAssertEqual(["hello": 1, "world": 2], output) - XCTAssertNil(outputMap?["error"]) + let outputMap = output?.first as? [String: Int] + XCTAssertNotNil(outputMap) + XCTAssertEqual(["hello": 1, "world": 2], outputMap) expectation.fulfill() } wait(for: [expectation], timeout: 1.0) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/RunnerTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/RunnerTests.swift index ed59c9ce33b..4cbd6b0d1f2 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/RunnerTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/RunnerTests.swift @@ -6,25 +6,25 @@ import XCTest @testable import test_plugin class RunnerTests: XCTestCase { - - func testToMapAndBack() throws { + + func testToListAndBack() throws { let reply = MessageSearchReply(result: "foobar") - let dict = reply.toMap() - let copy = MessageSearchReply.fromMap(dict) + let dict = reply.toList() + let copy = MessageSearchReply.fromList(dict) XCTAssertEqual(reply.result, copy?.result) } func testHandlesNull() throws { let reply = MessageSearchReply() - let dict = reply.toMap() - let copy = MessageSearchReply.fromMap(dict) + let dict = reply.toList() + let copy = MessageSearchReply.fromList(dict) XCTAssertNil(copy?.result) } func testHandlesNullFirst() throws { let reply = MessageSearchReply(error: "foobar") - let dict = reply.toMap() - let copy = MessageSearchReply.fromMap(dict) + let dict = reply.toList() + let copy = MessageSearchReply.fromList(dict) XCTAssertEqual(reply.error, copy?.error) } } diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/multiple_arity_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/multiple_arity_test.cpp index 7577afd9824..fc48a81f2f9 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/multiple_arity_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/multiple_arity_test.cpp @@ -25,7 +25,7 @@ class TestHostApi : public MultipleArityHostApi { }; const EncodableValue& GetResult(const EncodableValue& pigeon_response) { - return std::get(pigeon_response).at(EncodableValue("result")); + return std::get(pigeon_response)[0]; } } // namespace diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp index 22a42e7bad2..3e6a5426392 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp @@ -15,20 +15,21 @@ using flutter::EncodableList; using flutter::EncodableMap; using flutter::EncodableValue; -// EXPECTs that 'map' contains 'key', and then returns a pointer to its value. -// -// This gives useful test failure messages instead of silent crashes when the -// value isn't present, or has the wrong type. +/// EXPECTs that 'list' contains 'index', and then returns a pointer to its +/// value. +/// +/// This gives useful test failure messages instead of silent crashes when the +/// value isn't present, or has the wrong type. template -const T* ExpectAndGet(const EncodableMap& map, const std::string& key) { - auto it = map.find(EncodableValue(key)); - EXPECT_TRUE(it != map.end()) << "Could not find value for '" << key << '"'; - if (it == map.end()) { +const T* ExpectAndGetIndex(const EncodableList& list, const int i) { + EXPECT_LT(i, list.size()) + << "Index " << i << " is out of bounds; size is " << list.size(); + if (i >= list.size()) { return nullptr; } - const T* value_ptr = std::get_if(&(it->second)); + const T* value_ptr = std::get_if(&(list[i])); EXPECT_NE(value_ptr, nullptr) - << "Value for '" << key << "' has incorrect type"; + << "Value for index " << i << " has incorrect type"; return value_ptr; } @@ -36,22 +37,22 @@ const T* ExpectAndGet(const EncodableMap& map, const std::string& key) { class NullFieldsTest : public ::testing::Test { protected: - // Wrapper for access to private NullFieldsSearchRequest map constructor. - NullFieldsSearchRequest RequestFromMap(const EncodableMap& map) { - return NullFieldsSearchRequest(map); + // Wrapper for access to private NullFieldsSearchRequest list constructor. + NullFieldsSearchRequest RequestFromList(const EncodableList& list) { + return NullFieldsSearchRequest(list); } - // Wrapper for access to private NullFieldsSearchRequest map constructor. - NullFieldsSearchReply ReplyFromMap(const EncodableMap& map) { - return NullFieldsSearchReply(map); + // Wrapper for access to private NullFieldsSearchRequest list constructor. + NullFieldsSearchReply ReplyFromList(const EncodableList& list) { + return NullFieldsSearchReply(list); } - // Wrapper for access to private NullFieldsSearchRequest::ToEncodableMap. - EncodableMap MapFromRequest(const NullFieldsSearchRequest& request) { - return request.ToEncodableMap(); + // Wrapper for access to private NullFieldsSearchRequest::ToEncodableList. + EncodableList ListFromRequest(const NullFieldsSearchRequest& request) { + return request.ToEncodableList(); } - // Wrapper for access to private NullFieldsSearchRequest map constructor. - EncodableMap MapFromReply(const NullFieldsSearchReply& reply) { - return reply.ToEncodableMap(); + // Wrapper for access to private NullFieldsSearchRequest list constructor. + EncodableList ListFromReply(const NullFieldsSearchReply& reply) { + return reply.ToEncodableList(); } }; @@ -89,45 +90,44 @@ TEST(NullFields, BuildReplyWithNulls) { EXPECT_EQ(reply.type(), nullptr); } -TEST_F(NullFieldsTest, RequestFromMapWithValues) { - EncodableMap map{ - {EncodableValue("query"), EncodableValue("hello")}, - {EncodableValue("identifier"), EncodableValue(1)}, +TEST_F(NullFieldsTest, RequestFromListWithValues) { + EncodableList list{ + EncodableValue("hello"), + EncodableValue(1), }; - NullFieldsSearchRequest request = RequestFromMap(map); + NullFieldsSearchRequest request = RequestFromList(list); EXPECT_EQ(*request.query(), "hello"); EXPECT_EQ(request.identifier(), 1); } -TEST_F(NullFieldsTest, RequestFromMapWithNulls) { - EncodableMap map{ - {EncodableValue("query"), EncodableValue()}, - {EncodableValue("identifier"), EncodableValue(1)}, +TEST_F(NullFieldsTest, RequestFromListWithNulls) { + EncodableList list{ + EncodableValue(), + EncodableValue(1), }; - NullFieldsSearchRequest request = RequestFromMap(map); + NullFieldsSearchRequest request = RequestFromList(list); EXPECT_EQ(request.query(), nullptr); EXPECT_EQ(request.identifier(), 1); } -TEST_F(NullFieldsTest, ReplyFromMapWithValues) { - EncodableMap map{ - {EncodableValue("result"), EncodableValue("result")}, - {EncodableValue("error"), EncodableValue("error")}, - {EncodableValue("indices"), EncodableValue(EncodableList{ - EncodableValue(1), - EncodableValue(2), - EncodableValue(3), - })}, - {EncodableValue("request"), - EncodableValue(EncodableMap{ - {EncodableValue("query"), EncodableValue("hello")}, - {EncodableValue("identifier"), EncodableValue(1)}, - })}, - {EncodableValue("type"), EncodableValue(0)}, +TEST_F(NullFieldsTest, ReplyFromListWithValues) { + EncodableList list{ + EncodableValue("result"), + EncodableValue("error"), + EncodableValue(EncodableList{ + EncodableValue(1), + EncodableValue(2), + EncodableValue(3), + }), + EncodableValue(EncodableList{ + EncodableValue("hello"), + EncodableValue(1), + }), + EncodableValue(0), }; - NullFieldsSearchReply reply = ReplyFromMap(map); + NullFieldsSearchReply reply = ReplyFromList(list); EXPECT_EQ(*reply.result(), "result"); EXPECT_EQ(*reply.error(), "error"); @@ -137,15 +137,12 @@ TEST_F(NullFieldsTest, ReplyFromMapWithValues) { EXPECT_EQ(*reply.type(), NullFieldsSearchReplyType::success); } -TEST_F(NullFieldsTest, ReplyFromMapWithNulls) { - EncodableMap map{ - {EncodableValue("result"), EncodableValue()}, - {EncodableValue("error"), EncodableValue()}, - {EncodableValue("indices"), EncodableValue()}, - {EncodableValue("request"), EncodableValue()}, - {EncodableValue("type"), EncodableValue()}, +TEST_F(NullFieldsTest, ReplyFromListWithNulls) { + EncodableList list{ + EncodableValue(), EncodableValue(), EncodableValue(), + EncodableValue(), EncodableValue(), }; - NullFieldsSearchReply reply = ReplyFromMap(map); + NullFieldsSearchReply reply = ReplyFromList(list); EXPECT_EQ(reply.result(), nullptr); EXPECT_EQ(reply.error(), nullptr); @@ -154,16 +151,17 @@ TEST_F(NullFieldsTest, ReplyFromMapWithNulls) { EXPECT_EQ(reply.type(), nullptr); } -TEST_F(NullFieldsTest, RequestToMapWithValues) { +TEST_F(NullFieldsTest, RequestToListWithValues) { NullFieldsSearchRequest request; request.set_query("hello"); request.set_identifier(1); - EncodableMap map = MapFromRequest(request); + EncodableList list = ListFromRequest(request); - EXPECT_EQ(map.size(), 2); - EXPECT_EQ(*ExpectAndGet(map, "query"), "hello"); - EXPECT_EQ(*ExpectAndGet(map, "identifier"), 1); + EXPECT_EQ(list.size(), 2); + + EXPECT_EQ(*ExpectAndGetIndex(list, 0), "hello"); + EXPECT_EQ(*ExpectAndGetIndex(list, 1), 1); } TEST_F(NullFieldsTest, RequestToMapWithNulls) { @@ -171,16 +169,17 @@ TEST_F(NullFieldsTest, RequestToMapWithNulls) { // TODO(gaaclarke): This needs a way to be enforced. request.set_identifier(1); - EncodableMap map = MapFromRequest(request); + EncodableList list = ListFromRequest(request); - EXPECT_EQ(map.size(), 2); - EXPECT_TRUE(map[EncodableValue("hello")].IsNull()); - EXPECT_EQ(*ExpectAndGet(map, "identifier"), 1); + EXPECT_EQ(list.size(), 2); + EXPECT_TRUE(list[0].IsNull()); + EXPECT_EQ(*ExpectAndGetIndex(list, 1), 1); } TEST_F(NullFieldsTest, ReplyToMapWithValues) { NullFieldsSearchRequest request; request.set_query("hello"); + request.set_identifier(1); NullFieldsSearchReply reply; reply.set_result("result"); @@ -189,32 +188,32 @@ TEST_F(NullFieldsTest, ReplyToMapWithValues) { reply.set_request(request); reply.set_type(NullFieldsSearchReplyType::success); - EncodableMap map = MapFromReply(reply); + const EncodableList list = ListFromReply(reply); - EXPECT_EQ(map.size(), 5); - EXPECT_EQ(*ExpectAndGet(map, "result"), "result"); - EXPECT_EQ(*ExpectAndGet(map, "error"), "error"); - const EncodableList& indices = *ExpectAndGet(map, "indices"); + EXPECT_EQ(list.size(), 5); + EXPECT_EQ(*ExpectAndGetIndex(list, 0), "result"); + EXPECT_EQ(*ExpectAndGetIndex(list, 1), "error"); + const EncodableList& indices = *ExpectAndGetIndex(list, 2); EXPECT_EQ(indices.size(), 3); EXPECT_EQ(indices[0].LongValue(), 1L); EXPECT_EQ(indices[1].LongValue(), 2L); EXPECT_EQ(indices[2].LongValue(), 3L); - const EncodableMap& request_map = *ExpectAndGet(map, "request"); - EXPECT_EQ(*ExpectAndGet(request_map, "query"), "hello"); - EXPECT_EQ(*ExpectAndGet(map, "type"), 0); + const EncodableList& request_list = + *ExpectAndGetIndex(list, 3); + EXPECT_EQ(*ExpectAndGetIndex(request_list, 0), "hello"); + EXPECT_EQ(*ExpectAndGetIndex(request_list, 1), 1); } -TEST_F(NullFieldsTest, ReplyToMapWithNulls) { +TEST_F(NullFieldsTest, ReplyToListWithNulls) { NullFieldsSearchReply reply; - EncodableMap map = MapFromReply(reply); + const EncodableList list = ListFromReply(reply); - EXPECT_EQ(map.size(), 5); - EXPECT_TRUE(map[EncodableValue("result")].IsNull()); - EXPECT_TRUE(map[EncodableValue("error")].IsNull()); - EXPECT_TRUE(map[EncodableValue("indices")].IsNull()); - EXPECT_TRUE(map[EncodableValue("request")].IsNull()); - EXPECT_TRUE(map[EncodableValue("type")].IsNull()); + const int field_count = 5; + EXPECT_EQ(list.size(), field_count); + for (int i = 0; i < field_count; ++i) { + EXPECT_TRUE(list[i].IsNull()); + } } } // namespace null_fields_pigeontest diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/nullable_returns_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/nullable_returns_test.cpp index 356ff44866c..821df755ff5 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/nullable_returns_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/nullable_returns_test.cpp @@ -42,7 +42,7 @@ class TestNullableReturnHostApi : public NullableReturnHostApi { }; const EncodableValue& GetResult(const EncodableValue& pigeon_response) { - return std::get(pigeon_response).at(EncodableValue("result")); + return std::get(pigeon_response)[0]; } } // namespace diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/primitive_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/primitive_test.cpp index 782575ac384..518c5398be8 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/primitive_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/primitive_test.cpp @@ -50,7 +50,7 @@ class TestHostApi : public PrimitiveHostApi { }; const EncodableValue& GetResult(const EncodableValue& pigeon_response) { - return std::get(pigeon_response).at(EncodableValue("result")); + return std::get(pigeon_response)[0]; } } // namespace diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 24bc2af506a..cb8f5f40c48 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 4.2.11 # This must match the version in lib/generator_tools.dart +version: 4.2.12 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index d4816c8929b..4d7c21800d8 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -457,14 +457,13 @@ void main() { // Serialization handles optionals. expect( code, - contains('{flutter::EncodableValue("nullableBool"), ' - 'nullable_bool_ ? flutter::EncodableValue(*nullable_bool_) ' - ': flutter::EncodableValue()}')); + contains('nullable_bool_ ? flutter::EncodableValue(*nullable_bool_) ' + ': flutter::EncodableValue()')); expect( code, - contains('{flutter::EncodableValue("nullableNested"), ' - 'nullable_nested_ ? nullable_nested_->ToEncodableMap() ' - ': flutter::EncodableValue()}')); + contains( + 'nullable_nested_ ? flutter::EncodableValue(nullable_nested_->ToEncodableList()) ' + ': flutter::EncodableValue()')); } }); @@ -560,14 +559,8 @@ void main() { expect(code, contains('non_nullable_string_ = value_arg;')); expect(code, contains('non_nullable_nested_ = value_arg;')); // Serialization uses the value directly. - expect( - code, - contains('{flutter::EncodableValue("nonNullableBool"), ' - 'flutter::EncodableValue(non_nullable_bool_)}')); - expect( - code, - contains('{flutter::EncodableValue("nonNullableNested"), ' - 'non_nullable_nested_.ToEncodableMap()}')); + expect(code, contains('flutter::EncodableValue(non_nullable_bool_)')); + expect(code, contains('non_nullable_nested_.ToEncodableList()')); } }); diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index da1875e4b80..f56fe0aa21a 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -187,13 +187,13 @@ void main() { expect( code, contains( - "pigeonMap['nested'] = nested?.encode()", + 'nested?.encode(),', ), ); expect( code.replaceAll('\n', ' ').replaceAll(' ', ''), contains( - "nested: pigeonMap['nested'] != null ? Input.decode(pigeonMap['nested']!) : null", + 'nested: result[0] != null ? Input.decode(result[0]! as List) : null', ), ); }); @@ -229,13 +229,13 @@ void main() { expect( code, contains( - "pigeonMap['nested'] = nested.encode()", + 'nested.encode(),', ), ); expect( code.replaceAll('\n', ' ').replaceAll(' ', ''), contains( - "nested: Input.decode(pigeonMap['nested']!)", + 'nested: Input.decode(result[0]! as List)', ), ); }); @@ -417,8 +417,8 @@ void main() { final StringBuffer sink = StringBuffer(); generateDart(const DartOptions(), root, sink); final String code = sink.toString(); - expect(code, contains("pigeonMap['enum1'] = enum1?.index;")); - expect(code, contains("? Enum.values[pigeonMap['enum1']! as int]")); + expect(code, contains('enum1?.index,')); + expect(code, contains('? Enum.values[result[0]! as int]')); expect(code, contains('EnumClass doSomething(EnumClass arg0);')); }); @@ -484,8 +484,8 @@ void main() { final StringBuffer sink = StringBuffer(); generateDart(const DartOptions(), root, sink); final String code = sink.toString(); - expect(code, contains("pigeonMap['enum1'] = enum1.index;")); - expect(code, contains("enum1: Enum.values[pigeonMap['enum1']! as int]")); + expect(code, contains('enum1.index,')); + expect(code, contains('enum1: Enum.values[result[0]! as int]')); }); test('host void argument', () { @@ -574,7 +574,7 @@ void main() { expect(mainCode, isNot(contains('abstract class ApiMock'))); expect(mainCode, isNot(contains('.ApiMock.doSomething'))); expect(mainCode, isNot(contains("'${Keys.result}': output"))); - expect(mainCode, isNot(contains('return {};'))); + expect(mainCode, isNot(contains('return [];'))); generateTestDart( const DartOptions(), root, @@ -587,8 +587,8 @@ void main() { expect(testCode, isNot(contains('class Api {'))); expect(testCode, contains('abstract class ApiMock')); expect(testCode, isNot(contains('.ApiMock.doSomething'))); - expect(testCode, contains("'${Keys.result}': output")); - expect(testCode, contains('return {};')); + expect(testCode, contains('output')); + expect(testCode, contains('return [];')); }); test('gen one async Flutter Api', () { @@ -896,10 +896,8 @@ void main() { generateDart(const DartOptions(), root, sink); final String code = sink.toString(); expect(code, contains('Future> doit(')); - expect( - code, - contains( - "return (replyMap['result'] as List?)!.cast();")); + expect(code, + contains('return (replyList[0] as List?)!.cast();')); }); test('flutter generics argument non void return', () { @@ -960,7 +958,7 @@ void main() { generateDart(const DartOptions(), root, sink); final String code = sink.toString(); expect(code, contains('Future doit()')); - expect(code, contains("return (replyMap['result'] as int?);")); + expect(code, contains('return (replyList[0] as int?);')); }); test('return nullable collection host', () { @@ -985,10 +983,8 @@ void main() { generateDart(const DartOptions(), root, sink); final String code = sink.toString(); expect(code, contains('Future?> doit()')); - expect( - code, - contains( - "return (replyMap['result'] as List?)?.cast();")); + expect(code, + contains('return (replyList[0] as List?)?.cast();')); }); test('return nullable async host', () { @@ -1012,7 +1008,7 @@ void main() { generateDart(const DartOptions(), root, sink); final String code = sink.toString(); expect(code, contains('Future doit()')); - expect(code, contains("return (replyMap['result'] as int?);")); + expect(code, contains('return (replyList[0] as int?);')); }); test('return nullable flutter', () { diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index c621006f35f..b9b5214d519 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -36,7 +36,7 @@ void main() { expect( code, contains( - '@NonNull private static Map wrapError(@NonNull Throwable exception)')); + '@NonNull private static ArrayList wrapError(@NonNull Throwable exception)')); }); test('gen one enum', () { @@ -89,7 +89,7 @@ void main() { generateJava(javaOptions, root, sink); final String code = sink.toString(); expect(code, contains('package com.google.foobar;')); - expect(code, contains('Map toMap()')); + expect(code, contains('ArrayList toList()')); }); test('gen one host api', () { @@ -453,10 +453,11 @@ void main() { expect(code, contains('public static class Outer')); expect(code, contains('public static class Nested')); expect(code, contains('private @Nullable Nested nested;')); - expect(code, - contains('(nested == null) ? null : Nested.fromMap((Map)nested)')); - expect(code, - contains('put("nested", (nested == null) ? null : nested.toMap());')); + expect( + code, + contains( + '(nested == null) ? null : Nested.fromList((ArrayList)nested)')); + expect(code, contains('add((nested == null) ? null : nested.toList());')); }); test('gen one async Host Api', () { @@ -591,10 +592,8 @@ void main() { expect(code, contains('private Enum1(final int index) {')); expect(code, contains(' this.index = index;')); - expect( - code, - contains( - 'toMapResult.put("enum1", enum1 == null ? null : enum1.index);')); + expect(code, + contains('toListResult.add(enum1 == null ? null : enum1.index);')); expect( code, contains( diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 9a347d7e36b..4ed3a6cf1f5 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -31,8 +31,8 @@ void main() { final String code = sink.toString(); expect(code, contains('data class Foobar (')); expect(code, contains('val field1: Long? = null')); - expect(code, contains('fun fromMap(map: Map): Foobar')); - expect(code, contains('fun toMap(): Map')); + expect(code, contains('fun fromList(list: List): Foobar')); + expect(code, contains('fun toList(): List')); }); test('gen one enum', () { @@ -129,13 +129,13 @@ void main() { expect(code, contains(''' if (api != null) { channel.setMessageHandler { message, reply -> - val wrapped = hashMapOf() + var wrapped = listOf() try { val args = message as List val inputArg = args[0] as Input - wrapped["result"] = api.doSomething(inputArg) + wrapped = listOf(api.doSomething(inputArg)) } catch (exception: Error) { - wrapped["error"] = wrapError(exception) + wrapped = wrapError(exception) } reply.reply(wrapped) } @@ -367,8 +367,8 @@ void main() { generateKotlin(kotlinOptions, root, sink); final String code = sink.toString(); expect(code, contains('fun doSomething(): Output')); - expect(code, contains('wrapped["result"] = api.doSomething()')); - expect(code, contains('wrapped["error"] = wrapError(exception)')); + expect(code, contains('wrapped = listOf(api.doSomething())')); + expect(code, contains('wrapped = wrapError(exception)')); expect(code, contains('reply(wrapped)')); }); @@ -478,13 +478,11 @@ void main() { expect(code, contains('data class Outer')); expect(code, contains('data class Nested')); expect(code, contains('val nested: Nested? = null')); - expect(code, contains('fun fromMap(map: Map): Outer')); + expect(code, contains('fun fromList(list: List): Outer')); expect( - code, - contains( - 'val nested: Nested? = (map["nested"] as? Map)?.let')); - expect(code, contains('Nested.fromMap(it)')); - expect(code, contains('fun toMap(): Map')); + code, contains('val nested: Nested? = (list[0] as? List)?.let')); + expect(code, contains('Nested.fromList(it)')); + expect(code, contains('fun toList(): List')); }); test('gen one async Host Api', () { @@ -771,7 +769,7 @@ void main() { generateKotlin(kotlinOptions, root, sink); final String code = sink.toString(); expect(code, contains('fun doit(): List')); - expect(code, contains('wrapped["result"] = api.doit()')); + expect(code, contains('wrapped = listOf(api.doit())')); expect(code, contains('reply.reply(wrapped)')); }); @@ -835,7 +833,7 @@ void main() { code, contains( 'val yArg = args[1].let { if (it is Int) it.toLong() else it as Long }')); - expect(code, contains('wrapped["result"] = api.add(xArg, yArg)')); + expect(code, contains('wrapped = listOf(api.add(xArg, yArg))')); expect(code, contains('reply.reply(wrapped)')); }); diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index 0a56629539a..fef464163ae 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -110,7 +110,7 @@ void main() { expect( code, contains( - 'pigeonResult.enum1 = [GetNullableObject(dict, @"enum1") integerValue];')); + 'pigeonResult.enum1 = [GetNullableObjectAtIndex(list, 1) integerValue];')); }); test('primitive enum host', () { @@ -348,7 +348,7 @@ void main() { final String code = sink.toString(); expect(code, contains('@implementation Foobar')); expect(code, - contains('pigeonResult.aBool = GetNullableObject(dict, @"aBool");')); + contains('pigeonResult.aBool = GetNullableObjectAtIndex(list, 0);')); }); test('nested class header', () { @@ -390,8 +390,9 @@ void main() { expect( code, contains( - 'pigeonResult.nested = [Input nullableFromMap:GetNullableObject(dict, @"nested")];')); - expect(code, matches('[self.nested toMap].*@"nested"')); + 'pigeonResult.nested = [Input nullableFromList:(GetNullableObjectAtIndex(list, 0))];')); + expect( + code, contains('self.nested ? [self.nested toList] : [NSNull null]')); }); test('prefix class header', () { @@ -489,7 +490,7 @@ void main() { final StringBuffer sink = StringBuffer(); generateObjcSource(const ObjcOptions(prefix: 'ABC'), root, sink); final String code = sink.toString(); - expect(code, contains('ABCInput fromMap')); + expect(code, contains('ABCInput fromList')); expect(code, matches(r'ABCInput.*=.*args.*0.*\;')); expect(code, contains('void ABCApiSetup(')); }); diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index cda0f4804d5..1ba2fde3b80 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -30,9 +30,8 @@ void main() { final String code = sink.toString(); expect(code, contains('struct Foobar')); expect(code, contains('var field1: Int32? = nil')); - expect(code, - contains('static func fromMap(_ map: [String: Any?]) -> Foobar?')); - expect(code, contains('func toMap() -> [String: Any?]')); + expect(code, contains('static func fromList(_ list: [Any?]) -> Foobar?')); + expect(code, contains('func toList() -> [Any?]')); }); test('gen one enum', () { @@ -436,10 +435,9 @@ void main() { expect(code, contains('struct Outer')); expect(code, contains('struct Nested')); expect(code, contains('var nested: Nested? = nil')); - expect( - code, contains('static func fromMap(_ map: [String: Any?]) -> Outer?')); - expect(code, contains('nested = Nested.fromMap(nestedMap)')); - expect(code, contains('func toMap() -> [String: Any?]')); + expect(code, contains('static func fromList(_ list: [Any?]) -> Outer?')); + expect(code, contains('nested = Nested.fromList(nestedList)')); + expect(code, contains('func toList() -> [Any?]')); }); test('gen one async Host Api', () {