From 86e990df26bd5ffdfaa09ec0b48f1bed43bf4071 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 13 Jan 2023 17:16:02 -0800 Subject: [PATCH] [pigeon] Fix C++ generator's handling of Flutter APIs (#3042) * Add new APIs, unimplemented and unused * Add Dart implementation * Add multiple arity FlutterApi * Add Dart unit tests for desired output format * Enable the existing integration test * Add units tests for callback format * Adjust unit test expectations for error callback * First-pass implementation; mostly untested * Comment fix * Add todo * Minor fixes * Fix compilation error in Swift from new pigeons * Make new Maps string-keyed to avoid Swift error * Update generation * Update unit test for change * Update C++ test plugin for API changes * Fix type regression * missing ; * Drop string_view in Flutter API * Unwind incorrect 'simplification' of custom classes * Fix merge mistake * Merge mistake * Version bump * Address review comments * Fix Dart unit test compilation --- packages/pigeon/CHANGELOG.md | 6 + packages/pigeon/lib/cpp_generator.dart | 460 ++++++------ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/swift_generator.dart | 2 +- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- packages/pigeon/pigeons/core_tests.dart | 71 +- .../CoreTests.java | 223 +++++- .../ios/Classes/CoreTests.gen.h | 51 +- .../ios/Classes/CoreTests.gen.m | 188 ++++- .../lib/core_tests.gen.dart | 320 ++++++++- .../lib/multiple_arity.gen.dart | 2 +- .../lib/non_null_fields.gen.dart | 2 +- .../lib/null_fields.gen.dart | 2 +- .../lib/null_safe_pigeon.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../lib/primitive.dart | 2 +- .../lib/integration_tests.dart | 57 +- .../lib/src/generated/core_tests.gen.dart | 320 ++++++++- .../com/example/test_plugin/CoreTests.gen.kt | 129 +++- .../ios/Classes/CoreTests.gen.swift | 129 +++- .../macos/Classes/CoreTests.gen.swift | 129 +++- .../windows/pigeon/core_tests.gen.cpp | 663 +++++++++++++----- .../windows/pigeon/core_tests.gen.h | 89 ++- .../test_plugin/windows/test_plugin.cpp | 8 +- packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/test/cpp_generator_test.dart | 268 +++++++ .../pigeon/test/swift_generator_test.dart | 3 +- 28 files changed, 2668 insertions(+), 468 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 2bf8a72c63..9c62479a8d 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.0.1 + +* [c++] Fixes most non-class arguments and return values in Flutter APIs. The + types of arguments and return values have changed, so this may require updates + to existing code. + ## 6.0.0 * Creates StructuredGenerator class and implements it on all platforms. diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 105f6bd0f0..71a3a24067 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -191,10 +191,7 @@ class CppHeaderGenerator extends StructuredGenerator { addDocumentationComments( indent, field.documentationComments, _docCommentSpec); final HostDatatype baseDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); indent.writeln( '${_getterReturnType(baseDatatype)} ${_makeGetterName(field)}() const;'); indent.writeln( @@ -233,10 +230,7 @@ class CppHeaderGenerator extends StructuredGenerator { for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); indent.writeln( '${_valueType(hostDatatype)} ${_makeInstanceVariableName(field)};'); } @@ -273,24 +267,24 @@ class CppHeaderGenerator extends StructuredGenerator { indent .writeln('static const flutter::StandardMessageCodec& GetCodec();'); for (final Method func in api.methods) { - final String returnType = func.returnType.isVoid - ? 'void' - : _nullSafeCppTypeForDartType(func.returnType); - final String callback = 'std::function&& callback'; + final HostDatatype returnType = getHostDatatype(func.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); addDocumentationComments( indent, func.documentationComments, _docCommentSpec); - if (func.arguments.isEmpty) { - indent.writeln('void ${func.name}($callback);'); - } else { - final Iterable argTypes = func.arguments - .map((NamedType e) => _nullSafeCppTypeForDartType(e.type)); - final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); - final String argsSignature = - map2(argTypes, argNames, (String x, String y) => '$x $y') - .join(', '); - indent.writeln('void ${func.name}($argsSignature, $callback);'); - } + + final Iterable argTypes = func.arguments.map((NamedType arg) { + final HostDatatype hostType = getFieldHostDatatype( + arg, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + return _flutterApiArgumentType(hostType); + }); + final Iterable argNames = + indexMap(func.arguments, _getArgumentName); + final List parameters = [ + ...map2(argTypes, argNames, (String x, String y) => '$x $y'), + ..._flutterApiCallbackParameters(returnType), + ]; + indent.writeln( + 'void ${_makeMethodName(func)}(${parameters.join(', ')});'); } }); }, nestCount: 0); @@ -320,22 +314,16 @@ class CppHeaderGenerator extends StructuredGenerator { indent.writeln('${api.name}& operator=(const ${api.name}&) = delete;'); indent.writeln('virtual ~${api.name}() { };'); for (final Method method in api.methods) { - final HostDatatype returnType = getHostDatatype( - method.returnType, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String returnTypeName = _apiReturnType(returnType); + final HostDatatype returnType = getHostDatatype(method.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final String returnTypeName = _hostApiReturnType(returnType); final List argSignature = []; if (method.arguments.isNotEmpty) { final Iterable argTypes = method.arguments.map((NamedType arg) { - final HostDatatype hostType = getFieldHostDatatype( - arg, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final HostDatatype hostType = getFieldHostDatatype(arg, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); return _hostApiArgumentType(hostType); }); final Iterable argNames = @@ -557,36 +545,9 @@ class CppSourceGenerator extends StructuredGenerator { indent.scoped('return flutter::EncodableList{', '};', () { for (final NamedType field in getFieldsInSerializationOrder(klass)) { final HostDatatype hostDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - - final String instanceVariable = _makeInstanceVariableName(field); - - String encodableValue = ''; - if (!hostDatatype.isBuiltin && - customClassNames.contains(field.type.baseName)) { - final String operator = field.type.isNullable ? '->' : '.'; - encodableValue = - 'flutter::EncodableValue($instanceVariable${operator}ToEncodableList())'; - } else if (!hostDatatype.isBuiltin && - customEnumNames.contains(field.type.baseName)) { - final String nonNullValue = field.type.isNullable - ? '(*$instanceVariable)' - : instanceVariable; - encodableValue = 'flutter::EncodableValue((int)$nonNullValue)'; - } else { - final String operator = field.type.isNullable ? '*' : ''; - encodableValue = - 'flutter::EncodableValue($operator$instanceVariable)'; - } - - if (field.type.isNullable) { - encodableValue = - '$instanceVariable ? $encodableValue : flutter::EncodableValue()'; - } - + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + final String encodableValue = _wrappedHostApiArgumentExpression( + root, _makeInstanceVariableName(field), field.type, hostDatatype); indent.writeln('$encodableValue,'); } }); @@ -619,10 +580,7 @@ class CppSourceGenerator extends StructuredGenerator { 'if (const int32_t* $pointerFieldName = std::get_if(&$encodableFieldName))\t$instanceVariableName = (${field.type.baseName})*$pointerFieldName;'); } else { final HostDatatype hostDatatype = getFieldHostDatatype( - field, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); if (field.type.baseName == 'int') { indent.format(''' if (const int32_t* $pointerFieldName = std::get_if(&$encodableFieldName)) @@ -681,80 +639,66 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { '''); for (final Method func in api.methods) { final String channelName = makeChannelName(api, func); - final String returnType = func.returnType.isVoid - ? 'void' - : _nullSafeCppTypeForDartType(func.returnType); - String sendArgument; - final String callback = 'std::function&& callback'; - if (func.arguments.isEmpty) { - indent.write('void ${api.name}::${func.name}($callback) '); - sendArgument = 'flutter::EncodableValue()'; - } else { - final Iterable argTypes = func.arguments - .map((NamedType e) => _nullSafeCppTypeForDartType(e.type)); - final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); - sendArgument = - 'flutter::EncodableList { ${argNames.map((String arg) => 'flutter::CustomEncodableValue($arg)').join(', ')} }'; - final String argsSignature = - map2(argTypes, argNames, (String x, String y) => '$x $y') - .join(', '); - indent.write( - 'void ${api.name}::${func.name}($argsSignature, $callback) '); - } + final HostDatatype returnType = getHostDatatype(func.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); + + // Determine the input paramater list, saved in a structured form for later + // use as platform channel call arguments. + final Iterable<_HostNamedType> hostParameters = + indexMap(func.arguments, (int i, NamedType arg) { + final HostDatatype hostType = getFieldHostDatatype( + arg, root.classes, root.enums, _baseCppTypeForBuiltinDartType); + return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); + }); + final List parameters = [ + ...hostParameters.map((_HostNamedType arg) => + '${_flutterApiArgumentType(arg.hostType)} ${arg.name}'), + ..._flutterApiCallbackParameters(returnType), + ]; + indent.write( + 'void ${api.name}::${_makeMethodName(func)}(${parameters.join(', ')}) '); indent.scoped('{', '}', () { const String channel = 'channel'; indent.writeln( - 'auto channel = std::make_unique>('); - indent.inc(); - indent.inc(); - indent.writeln('binary_messenger_, "$channelName", &GetCodec());'); - indent.dec(); - indent.dec(); - indent.write( - '$channel->Send($sendArgument, [callback](const uint8_t* reply, size_t reply_size) '); + 'auto channel = std::make_unique>(binary_messenger_, ' + '"$channelName", &GetCodec());'); + + // Convert arguments to EncodableValue versions. + const String argumentListVariableName = 'encoded_api_arguments'; + indent.write('flutter::EncodableValue $argumentListVariableName = '); + if (func.arguments.isEmpty) { + indent.addln('flutter::EncodableValue();'); + } else { + indent.scoped( + 'flutter::EncodableValue(flutter::EncodableList{', '});', () { + for (final _HostNamedType param in hostParameters) { + final String encodedArgument = _wrappedHostApiArgumentExpression( + root, param.name, param.originalType, param.hostType); + indent.writeln('$encodedArgument,'); + } + }); + } + + indent.write('$channel->Send($argumentListVariableName, ' + // ignore: missing_whitespace_between_adjacent_strings + '[on_success = std::move(on_success), on_error = std::move(on_error)]' + '(const uint8_t* reply, size_t reply_size) '); indent.scoped('{', '});', () { + final String successCallbackArgument; if (func.returnType.isVoid) { - indent.writeln('callback();'); + successCallbackArgument = ''; } else { + successCallbackArgument = 'return_value'; + final String encodedReplyName = + 'encodable_$successCallbackArgument'; indent.writeln( - 'std::unique_ptr decoded_reply = GetCodec().DecodeMessage(reply, reply_size);'); - indent.writeln( - 'flutter::EncodableValue args = *(flutter::EncodableValue*)(decoded_reply.release());'); - const String output = 'output'; - - final bool isBuiltin = - _baseCppTypeForBuiltinDartType(func.returnType) != null; - final String returnTypeName = - _baseCppTypeForDartType(func.returnType); - if (func.returnType.isNullable) { - indent.writeln('$returnType $output{};'); - } else { - indent.writeln('$returnTypeName $output{};'); - } - const String pointerVariable = '${_pointerPrefix}_$output'; - if (func.returnType.baseName == 'int') { - indent.format(''' -if (const int32_t* $pointerVariable = std::get_if(&args)) -\t$output = *$pointerVariable; -else if (const int64_t* ${pointerVariable}_64 = std::get_if(&args)) -\t$output = *${pointerVariable}_64;'''); - } else if (!isBuiltin) { - indent.write( - 'if (const flutter::EncodableList* $pointerVariable = std::get_if(&args)) '); - indent.scoped('{', '}', () { - indent.writeln('$output = $returnTypeName(*$pointerVariable);'); - }); - } else { - indent.write( - 'if (const $returnTypeName* $pointerVariable = std::get_if<$returnTypeName>(&args)) '); - indent.scoped('{', '}', () { - indent.writeln('$output = *$pointerVariable;'); - }); - } - - indent.writeln('callback($output);'); + 'std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size);'); + indent.writeln('const auto& $encodedReplyName = *response;'); + _writeEncodableValueArgumentUnwrapping(indent, returnType, + argName: successCallbackArgument, + encodableArgName: encodedReplyName); } + indent.writeln('on_success($successCallbackArgument);'); }); }); } @@ -787,12 +731,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.write(''); indent.scoped('{', '}', () { indent.writeln( - 'auto channel = std::make_unique>('); - indent.inc(); - indent.inc(); - indent.writeln('binary_messenger, "$channelName", &GetCodec());'); - indent.dec(); - indent.dec(); + 'auto channel = std::make_unique>(binary_messenger, ' + '"$channelName", &GetCodec());'); indent.write('if (api != nullptr) '); indent.scoped('{', '} else {', () { indent.write( @@ -805,70 +745,6 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.writeln( 'const auto& args = std::get(message);'); - // Writes the code to declare and populate a variable called - // [argName] to use as a parameter to an API method call from - // an existing EncodablValue variable called [encodableArgName] - // which corresponds to [arg] in the API definition. - void extractEncodedArgument( - String argName, - String encodableArgName, - NamedType arg, - HostDatatype hostType) { - if (arg.type.isNullable) { - // Nullable arguments are always pointers, with nullptr - // corresponding to null. - if (hostType.datatype == 'int64_t') { - // The EncodableValue will either be an int32_t or an - // int64_t depending on the value, but the generated API - // requires an int64_t so that it can handle any case. - // Create a local variable for the 64-bit value... - final String valueVarName = '${argName}_value'; - indent.writeln( - 'const int64_t $valueVarName = $encodableArgName.IsNull() ? 0 : $encodableArgName.LongValue();'); - // ... then declare the arg as a reference to that local. - indent.writeln( - 'const auto* $argName = $encodableArgName.IsNull() ? nullptr : &$valueVarName;'); - } else if (hostType.datatype == - 'flutter::EncodableValue') { - // Generic objects just pass the EncodableValue through - // directly. - indent.writeln( - 'const auto* $argName = &$encodableArgName;'); - } else if (hostType.isBuiltin) { - indent.writeln( - 'const auto* $argName = std::get_if<${hostType.datatype}>(&$encodableArgName);'); - } else { - indent.writeln( - 'const auto* $argName = &(std::any_cast(std::get($encodableArgName)));'); - } - } else { - // Non-nullable arguments are either passed by value or - // reference, but the extraction doesn't need to distinguish - // since those are the same at the call site. - if (hostType.datatype == 'int64_t') { - // The EncodableValue will either be an int32_t or an - // int64_t depending on the value, but the generated API - // requires an int64_t so that it can handle any case. - indent.writeln( - 'const int64_t $argName = $encodableArgName.LongValue();'); - } else if (hostType.datatype == - 'flutter::EncodableValue') { - // Generic objects just pass the EncodableValue through - // directly. This creates an alias just to avoid having to - // special-case the argName/encodableArgName distinction - // at a higher level. - indent.writeln( - 'const auto& $argName = $encodableArgName;'); - } else if (hostType.isBuiltin) { - indent.writeln( - 'const auto& $argName = std::get<${hostType.datatype}>($encodableArgName);'); - } else { - indent.writeln( - 'const auto& $argName = std::any_cast(std::get($encodableArgName));'); - } - } - } - enumerate(method.arguments, (int index, NamedType arg) { final HostDatatype hostType = getHostDatatype( arg.type, @@ -890,8 +766,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.writeln('return;'); }); } - extractEncodedArgument( - argName, encodableArgName, arg, hostType); + _writeEncodableValueArgumentUnwrapping(indent, hostType, + argName: argName, encodableArgName: encodableArgName); methodArgument.add(argName); }); } @@ -900,8 +776,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { method.returnType, root.classes, root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String returnTypeName = _apiReturnType(returnType); + _baseCppTypeForBuiltinDartType); + final String returnTypeName = _hostApiReturnType(returnType); if (method.isAsynchronous) { methodArgument.add( '[reply]($returnTypeName&& output) {${indent.newline}' @@ -1011,8 +887,8 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) { void _writeCppSourceClassField(CppOptions generatorOptions, Root root, Indent indent, Class klass, NamedType field) { - final HostDatatype hostDatatype = getFieldHostDatatype(field, root.classes, - root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final HostDatatype hostDatatype = getFieldHostDatatype( + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); final String instanceVariableName = _makeInstanceVariableName(field); final String qualifiedGetterName = '${klass.name}::${_makeGetterName(field)}'; @@ -1058,8 +934,8 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) { errorCondition = 'output.has_value()'; errorGetter = 'value'; } else { - final HostDatatype hostType = getHostDatatype(returnType, root.classes, - root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final HostDatatype hostType = getHostDatatype( + returnType, root.classes, root.enums, _baseCppTypeForBuiltinDartType); const String extractedValue = 'std::move(output).TakeValue()'; final String wrapperType = hostType.isBuiltin ? 'flutter::EncodableValue' @@ -1104,6 +980,18 @@ ${prefix}reply(flutter::EncodableValue(std::move(wrapped)));'''; } } +/// Contains information about a host function argument. +/// +/// This is comparable to a [NamedType], but has already gone through host type +/// and variable name mapping, and it tracks the original [NamedType] that it +/// was created from. +class _HostNamedType { + const _HostNamedType(this.name, this.hostType, this.originalType); + final String name; + final HostDatatype hostType; + final TypeDeclaration originalType; +} + String _getCodecSerializerName(Api api) => '${api.name}CodecSerializer'; const String _pointerPrefix = 'pointer'; @@ -1162,6 +1050,15 @@ bool _isReferenceType(String dataType) { } } +/// Returns the parameters to use for the success and error callbacks in a +/// Flutter API function signature. +List _flutterApiCallbackParameters(HostDatatype returnType) { + return [ + 'std::function&& on_success', + 'std::function&& on_error', + ]; +} + /// Returns true if [type] corresponds to a plain-old-data type (i.e., one that /// should generally be passed by value rather than pointer/reference) in C++. bool _isPodType(HostDatatype type) { @@ -1190,12 +1087,6 @@ String? _baseCppTypeForBuiltinDartType(TypeDeclaration type) { } } -/// Returns the base C++ type (without pointer, reference, optional, etc.) for -/// the given [type]. -String _baseCppTypeForDartType(TypeDeclaration type) { - return _baseCppTypeForBuiltinDartType(type) ?? type.baseName; -} - /// Returns the C++ type to use in a value context (variable declaration, /// pass-by-value, etc.) for the given C++ base type. String _valueType(HostDatatype type) { @@ -1228,6 +1119,19 @@ String _hostApiArgumentType(HostDatatype type) { return type.isNullable ? 'const $baseType*' : 'const $baseType&'; } +/// Returns the C++ type to use for arguments to a Flutter API. +String _flutterApiArgumentType(HostDatatype type) { + // Nullable strings use std::string* rather than std::string_view* + // since there's no implicit conversion for the pointer types, making them + // more awkward to use. For consistency, and since EncodableValue will end + // up making a std::string internally anyway, std::string is used for the + // non-nullable case as well. + if (type.datatype == 'std::string') { + return type.isNullable ? 'const std::string*' : 'const std::string&'; + } + return _unownedArgumentType(type); +} + /// Returns the C++ type to use for the return of a getter for a field of type /// [type]. String _getterReturnType(HostDatatype type) { @@ -1241,9 +1145,9 @@ String _getterReturnType(HostDatatype type) { return type.isNullable ? 'const $baseType*' : 'const $baseType&'; } -/// Returns the C++ type to use for the return of an API method retutrning +/// Returns the C++ type to use for the return of a host API method returning /// [type]. -String _apiReturnType(HostDatatype type) { +String _hostApiReturnType(HostDatatype type) { if (type.datatype == 'void') { return 'std::optional'; } @@ -1254,31 +1158,25 @@ String _apiReturnType(HostDatatype type) { return 'ErrorOr<$valueType>'; } -// TODO(stuartmorgan): Audit all uses of this and convert them to context-based -// methods like those above. Code still using this method may well have bugs. -String _nullSafeCppTypeForDartType(TypeDeclaration type, - {bool considerReference = true}) { - if (type.isNullable) { - return 'std::optional<${_baseCppTypeForDartType(type)}>'; - } else { - String typeName = _baseCppTypeForDartType(type); - if (_isReferenceType(typeName)) { - if (considerReference) { - typeName = 'const $typeName&'; - } else { - typeName = 'std::unique_ptr<$typeName>'; - } - } - return typeName; +/// Returns the C++ type to use for the paramer to the asyncronous "return" +/// callback of a Flutter API method returning [type]. +String _flutterApiReturnType(HostDatatype type) { + if (type.datatype == 'void') { + return 'void'; } + // For anything other than void, handle it the same way as a host API argument + // since it has the same basic structure of being a function defined by the + // client, being called by the generated code. + return _hostApiArgumentType(type); } String _getGuardName(String? headerFileName) { - String guardName = 'PIGEON_'; + const String prefix = 'PIGEON_'; if (headerFileName != null) { - guardName += '${headerFileName.replaceAll('.', '_').toUpperCase()}_'; + return '$prefix${headerFileName.replaceAll('.', '_').toUpperCase()}_'; + } else { + return '${prefix}H_'; } - return '${guardName}H_'; } void _writeSystemHeaderIncludeBlock(Indent indent, List headers) { @@ -1288,6 +1186,88 @@ void _writeSystemHeaderIncludeBlock(Indent indent, List headers) { } } +/// Returns the expression to create an EncodableValue from a host API argument +/// with the given [variableName] and types. +String _wrappedHostApiArgumentExpression(Root root, String variableName, + TypeDeclaration dartType, HostDatatype hostType) { + final String encodableValue; + if (!hostType.isBuiltin && + root.classes.any((Class c) => c.name == dartType.baseName)) { + final String operator = hostType.isNullable ? '->' : '.'; + encodableValue = + 'flutter::EncodableValue($variableName${operator}ToEncodableList())'; + } else if (!hostType.isBuiltin && + root.enums.any((Enum e) => e.name == dartType.baseName)) { + final String nonNullValue = + hostType.isNullable ? '(*$variableName)' : variableName; + encodableValue = 'flutter::EncodableValue((int)$nonNullValue)'; + } else { + final String operator = hostType.isNullable ? '*' : ''; + encodableValue = 'flutter::EncodableValue($operator$variableName)'; + } + + if (hostType.isNullable) { + return '$variableName ? $encodableValue : flutter::EncodableValue()'; + } + return encodableValue; +} + +// Writes the code to declare and populate a variable of type [hostType] called +// [argName] to use as a parameter to an API method call, from an existing +// EncodableValue variable called [encodableArgName]. +void _writeEncodableValueArgumentUnwrapping( + Indent indent, + HostDatatype hostType, { + required String argName, + required String encodableArgName, +}) { + if (hostType.isNullable) { + // Nullable arguments are always pointers, with nullptr corresponding to + // null. + if (hostType.datatype == 'int64_t') { + // The EncodableValue will either be an int32_t or an int64_t depending + // on the value, but the generated API requires an int64_t so that it can + // handle any case. Create a local variable for the 64-bit value... + final String valueVarName = '${argName}_value'; + indent.writeln( + 'const int64_t $valueVarName = $encodableArgName.IsNull() ? 0 : $encodableArgName.LongValue();'); + // ... then declare the arg as a reference to that local. + indent.writeln( + 'const auto* $argName = $encodableArgName.IsNull() ? nullptr : &$valueVarName;'); + } else if (hostType.datatype == 'flutter::EncodableValue') { + // Generic objects just pass the EncodableValue through directly. + indent.writeln('const auto* $argName = &$encodableArgName;'); + } else if (hostType.isBuiltin) { + indent.writeln( + 'const auto* $argName = std::get_if<${hostType.datatype}>(&$encodableArgName);'); + } else { + indent.writeln( + 'const auto* $argName = &(std::any_cast(std::get($encodableArgName)));'); + } + } else { + // Non-nullable arguments are either passed by value or reference, but the + // extraction doesn't need to distinguish since those are the same at the + // call site. + if (hostType.datatype == 'int64_t') { + // The EncodableValue will either be an int32_t or an int64_t depending + // on the value, but the generated API requires an int64_t so that it can + // handle any case. + indent.writeln('const int64_t $argName = $encodableArgName.LongValue();'); + } else if (hostType.datatype == 'flutter::EncodableValue') { + // Generic objects just pass the EncodableValue through directly. This + // creates an alias just to avoid having to special-case the + // argName/encodableArgName distinction at a higher level. + indent.writeln('const auto& $argName = $encodableArgName;'); + } else if (hostType.isBuiltin) { + indent.writeln( + 'const auto& $argName = std::get<${hostType.datatype}>($encodableArgName);'); + } else { + indent.writeln( + 'const auto& $argName = std::any_cast(std::get($encodableArgName));'); + } + } +} + /// Validates an AST to make sure the cpp generator supports everything. List validateCpp(CppOptions options, Root root) { final List result = []; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 3dc1df4d51..40f2f5b11a 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 = '6.0.0'; +const String pigeonVersion = '6.0.1'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 46e14005ca..d8f5b1ab96 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -313,7 +313,7 @@ import FlutterMacOS indexMap(func.arguments, _getArgumentName); final Iterable argNames = indexMap(func.arguments, _getSafeArgumentName); - sendArgument = '[${argNames.join(', ')}]'; + sendArgument = '[${argNames.join(', ')}] as [Any?]'; final String argsSignature = map3( argTypes, argLabels, diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index bf02b40713..0afd3056f4 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 5cc8473b05..25f5d73b6d 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index ed4ba3a352..1699b0f49d 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -191,10 +191,12 @@ abstract class HostIntegrationCoreApi { @ObjCSelector('callFlutterEchoString:') String callFlutterEchoString(String aString); - // TODO(stuartmorgan): Add callFlutterEchoString and the associated test once - // either https://github.com/flutter/flutter/issues/116117 is fixed, or the - // problematic type is moved out of AllTypes and into its own test, since + // TODO(stuartmorgan): Add callFlutterEchoAllTypes and the associated test + // once either https://github.com/flutter/flutter/issues/116117 is fixed, or + // the problematic type is moved out of AllTypes and into its own test, since // the type mismatch breaks the second `encode` round. + + // TODO(stuartmorgan): Fill in the rest of the callFlutterEcho* tests. } /// The core interface that the Dart platform_test code implements for host @@ -213,9 +215,72 @@ abstract class FlutterIntegrationCoreApi { @ObjCSelector('echoAllNullableTypes:') AllNullableTypes echoAllNullableTypes(AllNullableTypes everything); + /// Returns passed in arguments of multiple types. + /// + /// Tests multiple-arity FlutterApi handling. + @ObjCSelector('sendMultipleNullableTypesABool:anInt:aString:') + AllNullableTypes sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString); + + // ========== Non-nullable argument/return type tests ========== + + /// Returns the passed boolean, to test serialization and deserialization. + @ObjCSelector('echoBool:') + bool echoBool(bool aBool); + + /// Returns the passed int, to test serialization and deserialization. + @ObjCSelector('echoInt:') + int echoInt(int anInt); + + /// Returns the passed double, to test serialization and deserialization. + @ObjCSelector('echoDouble:') + double echoDouble(double aDouble); + /// Returns the passed string, to test serialization and deserialization. @ObjCSelector('echoString:') String echoString(String aString); + + /// Returns the passed byte list, to test serialization and deserialization. + @ObjCSelector('echoUint8List:') + Uint8List echoUint8List(Uint8List aList); + + /// Returns the passed list, to test serialization and deserialization. + @ObjCSelector('echoList:') + List echoList(List aList); + + /// Returns the passed map, to test serialization and deserialization. + @ObjCSelector('echoMap:') + Map echoMap(Map aMap); + + // ========== Nullable argument/return type tests ========== + + /// Returns the passed boolean, to test serialization and deserialization. + @ObjCSelector('echoNullableBool:') + bool? echoNullableBool(bool? aBool); + + /// Returns the passed int, to test serialization and deserialization. + @ObjCSelector('echoNullableInt:') + int? echoNullableInt(int? anInt); + + /// Returns the passed double, to test serialization and deserialization. + @ObjCSelector('echoNullableDouble:') + double? echoNullableDouble(double? aDouble); + + /// Returns the passed string, to test serialization and deserialization. + @ObjCSelector('echoNullableString:') + String? echoNullableString(String? aString); + + /// Returns the passed byte list, to test serialization and deserialization. + @ObjCSelector('echoNullableUint8List:') + Uint8List? echoNullableUint8List(Uint8List? aList); + + /// Returns the passed list, to test serialization and deserialization. + @ObjCSelector('echoNullableList:') + List? echoNullableList(List? aList); + + /// Returns the passed map, to test serialization and deserialization. + @ObjCSelector('echoNullableMap:') + Map echoNullableMap(Map aMap); } /// An API that can be implemented for minimal, compile-only tests. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index d97d0cc5df..13367f2b6e 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; @@ -17,6 +17,7 @@ import io.flutter.plugin.common.StandardMessageCodec; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -1518,6 +1519,9 @@ public class CoreTests { return AllNullableTypes.fromList((ArrayList) readValue(buffer)); case (byte) 129: + return AllNullableTypesWrapper.fromList((ArrayList) readValue(buffer)); + + case (byte) 130: return AllTypes.fromList((ArrayList) readValue(buffer)); default: @@ -1530,8 +1534,11 @@ public class CoreTests { if (value instanceof AllNullableTypes) { stream.write(128); writeValue(stream, ((AllNullableTypes) value).toList()); - } else if (value instanceof AllTypes) { + } else if (value instanceof AllNullableTypesWrapper) { stream.write(129); + writeValue(stream, ((AllNullableTypesWrapper) value).toList()); + } else if (value instanceof AllTypes) { + stream.write(130); writeValue(stream, ((AllTypes) value).toList()); } else { super.writeValue(stream, value); @@ -1603,6 +1610,71 @@ public class CoreTests { callback.reply(output); }); } + /** + * Returns passed in arguments of multiple types. + * + *

Tests multiple-arity FlutterApi handling. + */ + public void sendMultipleNullableTypes( + @Nullable Boolean aNullableBoolArg, + @Nullable Long aNullableIntArg, + @Nullable String aNullableStringArg, + Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", + getCodec()); + channel.send( + new ArrayList( + Arrays.asList(aNullableBoolArg, aNullableIntArg, aNullableStringArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + AllNullableTypes output = (AllNullableTypes) channelReply; + callback.reply(output); + }); + } + /** Returns the passed boolean, to test serialization and deserialization. */ + public void echoBool(@NonNull Boolean aBoolArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aBoolArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Boolean output = (Boolean) channelReply; + callback.reply(output); + }); + } + /** Returns the passed int, to test serialization and deserialization. */ + public void echoInt(@NonNull Long anIntArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", getCodec()); + channel.send( + new ArrayList(Collections.singletonList(anIntArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Long output = channelReply == null ? null : ((Number) channelReply).longValue(); + callback.reply(output); + }); + } + /** Returns the passed double, to test serialization and deserialization. */ + public void echoDouble(@NonNull Double aDoubleArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aDoubleArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Double output = (Double) channelReply; + callback.reply(output); + }); + } /** Returns the passed string, to test serialization and deserialization. */ public void echoString(@NonNull String aStringArg, Reply callback) { BasicMessageChannel channel = @@ -1618,6 +1690,153 @@ public class CoreTests { callback.reply(output); }); } + /** Returns the passed byte list, to test serialization and deserialization. */ + public void echoUint8List(@NonNull byte[] aListArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aListArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + byte[] output = (byte[]) channelReply; + callback.reply(output); + }); + } + /** Returns the passed list, to test serialization and deserialization. */ + public void echoList(@NonNull List aListArg, Reply> callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aListArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + List output = (List) channelReply; + callback.reply(output); + }); + } + /** Returns the passed map, to test serialization and deserialization. */ + public void echoMap(@NonNull Map aMapArg, Reply> callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aMapArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Map output = (Map) channelReply; + callback.reply(output); + }); + } + /** Returns the passed boolean, to test serialization and deserialization. */ + public void echoNullableBool(@Nullable Boolean aBoolArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aBoolArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Boolean output = (Boolean) channelReply; + callback.reply(output); + }); + } + /** Returns the passed int, to test serialization and deserialization. */ + public void echoNullableInt(@Nullable Long anIntArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(anIntArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Long output = channelReply == null ? null : ((Number) channelReply).longValue(); + callback.reply(output); + }); + } + /** Returns the passed double, to test serialization and deserialization. */ + public void echoNullableDouble(@Nullable Double aDoubleArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aDoubleArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Double output = (Double) channelReply; + callback.reply(output); + }); + } + /** Returns the passed string, to test serialization and deserialization. */ + public void echoNullableString(@Nullable String aStringArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aStringArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + String output = (String) channelReply; + callback.reply(output); + }); + } + /** Returns the passed byte list, to test serialization and deserialization. */ + public void echoNullableUint8List(@Nullable byte[] aListArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aListArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + byte[] output = (byte[]) channelReply; + callback.reply(output); + }); + } + /** Returns the passed list, to test serialization and deserialization. */ + public void echoNullableList(@Nullable List aListArg, Reply> callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aListArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + List output = (List) channelReply; + callback.reply(output); + }); + } + /** Returns the passed map, to test serialization and deserialization. */ + public void echoNullableMap( + @NonNull Map aMapArg, Reply> callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", + getCodec()); + channel.send( + new ArrayList(Collections.singletonList(aMapArg)), + channelReply -> { + @SuppressWarnings("ConstantConditions") + Map output = (Map) channelReply; + callback.reply(output); + }); + } } /** * An API that can be implemented for minimal, compile-only tests. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index bfab566ab6..a5c55a3ddf 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @@ -205,9 +205,58 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); /// Returns the passed object, to test serialization and deserialization. - (void)echoAllNullableTypes:(AllNullableTypes *)everything completion:(void (^)(AllNullableTypes *_Nullable, NSError *_Nullable))completion; +/// Returns passed in arguments of multiple types. +/// +/// Tests multiple-arity FlutterApi handling. +- (void)sendMultipleNullableTypesABool:(nullable NSNumber *)aNullableBool + anInt:(nullable NSNumber *)aNullableInt + aString:(nullable NSString *)aNullableString + completion:(void (^)(AllNullableTypes *_Nullable, + NSError *_Nullable))completion; +/// Returns the passed boolean, to test serialization and deserialization. +- (void)echoBool:(NSNumber *)aBool + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; +/// Returns the passed int, to test serialization and deserialization. +- (void)echoInt:(NSNumber *)anInt + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; +/// Returns the passed double, to test serialization and deserialization. +- (void)echoDouble:(NSNumber *)aDouble + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; /// Returns the passed string, to test serialization and deserialization. - (void)echoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, NSError *_Nullable))completion; +/// Returns the passed byte list, to test serialization and deserialization. +- (void)echoUint8List:(FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, NSError *_Nullable))completion; +/// Returns the passed list, to test serialization and deserialization. +- (void)echoList:(NSArray *)aList + completion:(void (^)(NSArray *_Nullable, NSError *_Nullable))completion; +/// Returns the passed map, to test serialization and deserialization. +- (void)echoMap:(NSDictionary *)aMap + completion:(void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion; +/// Returns the passed boolean, to test serialization and deserialization. +- (void)echoNullableBool:(nullable NSNumber *)aBool + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; +/// Returns the passed int, to test serialization and deserialization. +- (void)echoNullableInt:(nullable NSNumber *)anInt + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; +/// Returns the passed double, to test serialization and deserialization. +- (void)echoNullableDouble:(nullable NSNumber *)aDouble + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion; +/// Returns the passed string, to test serialization and deserialization. +- (void)echoNullableString:(nullable NSString *)aString + completion:(void (^)(NSString *_Nullable, NSError *_Nullable))completion; +/// Returns the passed byte list, to test serialization and deserialization. +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + NSError *_Nullable))completion; +/// Returns the passed list, to test serialization and deserialization. +- (void)echoNullableList:(nullable NSArray *)aList + completion:(void (^)(NSArray *_Nullable, NSError *_Nullable))completion; +/// Returns the passed map, to test serialization and deserialization. +- (void)echoNullableMap:(NSDictionary *)aMap + completion: + (void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion; @end /// The codec used by HostTrivialApi. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index 7f73cf6a4d..c8fa7d8a3d 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" @@ -791,6 +791,9 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, return [AllNullableTypes fromList:[self readValue]]; case 129: + return [AllNullableTypesWrapper fromList:[self readValue]]; + + case 130: return [AllTypes fromList:[self readValue]]; default: @@ -806,9 +809,12 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllTypes class]]) { + } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { [self writeByte:129]; [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[AllTypes class]]) { + [self writeByte:130]; + [self writeValue:[value toList]]; } else { [super writeValue:value]; } @@ -884,6 +890,61 @@ NSObject *FlutterIntegrationCoreApiGetCodec() { completion(output, nil); }]; } +- (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool + anInt:(nullable NSNumber *)arg_aNullableInt + aString:(nullable NSString *)arg_aNullableString + completion:(void (^)(AllNullableTypes *_Nullable, + NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ + arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], + arg_aNullableString ?: [NSNull null] + ] + reply:^(id reply) { + AllNullableTypes *output = reply; + completion(output, nil); + }]; +} +- (void)echoBool:(NSNumber *)arg_aBool + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} +- (void)echoInt:(NSNumber *)arg_anInt + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} +- (void)echoDouble:(NSNumber *)arg_aDouble + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} - (void)echoString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, NSError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel @@ -896,6 +957,129 @@ NSObject *FlutterIntegrationCoreApiGetCodec() { completion(output, nil); }]; } +- (void)echoUint8List:(FlutterStandardTypedData *)arg_aList + completion: + (void (^)(FlutterStandardTypedData *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(id reply) { + FlutterStandardTypedData *output = reply; + completion(output, nil); + }]; +} +- (void)echoList:(NSArray *)arg_aList + completion:(void (^)(NSArray *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(id reply) { + NSArray *output = reply; + completion(output, nil); + }]; +} +- (void)echoMap:(NSDictionary *)arg_aMap + completion:(void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(id reply) { + NSDictionary *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableBool:(nullable NSNumber *)arg_aBool + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableInt:(nullable NSNumber *)arg_anInt + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble + completion:(void (^)(NSNumber *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] + reply:^(id reply) { + NSNumber *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableString:(nullable NSString *)arg_aString + completion:(void (^)(NSString *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aString ?: [NSNull null] ] + reply:^(id reply) { + NSString *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList + completion:(void (^)(FlutterStandardTypedData *_Nullable, + NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(id reply) { + FlutterStandardTypedData *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableList:(nullable NSArray *)arg_aList + completion:(void (^)(NSArray *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(id reply) { + NSArray *output = reply; + completion(output, nil); + }]; +} +- (void)echoNullableMap:(NSDictionary *)arg_aMap + completion: + (void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap" + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(id reply) { + NSDictionary *output = reply; + completion(output, nil); + }]; +} @end NSObject *HostTrivialApiGetCodec() { 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 1040f61c12..203f02bcf8 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 @@ -848,9 +848,12 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { if (value is AllNullableTypes) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllTypes) { + } else if (value is AllNullableTypesWrapper) { buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is AllTypes) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -863,6 +866,9 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { return AllNullableTypes.decode(readValue(buffer)!); case 129: + return AllNullableTypesWrapper.decode(readValue(buffer)!); + + case 130: return AllTypes.decode(readValue(buffer)!); default: @@ -886,9 +892,54 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. AllNullableTypes echoAllNullableTypes(AllNullableTypes everything); + /// Returns passed in arguments of multiple types. + /// + /// Tests multiple-arity FlutterApi handling. + AllNullableTypes sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString); + + /// Returns the passed boolean, to test serialization and deserialization. + bool echoBool(bool aBool); + + /// Returns the passed int, to test serialization and deserialization. + int echoInt(int anInt); + + /// Returns the passed double, to test serialization and deserialization. + double echoDouble(double aDouble); + /// Returns the passed string, to test serialization and deserialization. String echoString(String aString); + /// Returns the passed byte list, to test serialization and deserialization. + Uint8List echoUint8List(Uint8List aList); + + /// Returns the passed list, to test serialization and deserialization. + List echoList(List aList); + + /// Returns the passed map, to test serialization and deserialization. + Map echoMap(Map aMap); + + /// Returns the passed boolean, to test serialization and deserialization. + bool? echoNullableBool(bool? aBool); + + /// Returns the passed int, to test serialization and deserialization. + int? echoNullableInt(int? anInt); + + /// Returns the passed double, to test serialization and deserialization. + double? echoNullableDouble(double? aDouble); + + /// Returns the passed string, to test serialization and deserialization. + String? echoNullableString(String? aString); + + /// Returns the passed byte list, to test serialization and deserialization. + Uint8List? echoNullableUint8List(Uint8List? aList); + + /// Returns the passed list, to test serialization and deserialization. + List? echoNullableList(List? aList); + + /// Returns the passed map, to test serialization and deserialization. + Map echoNullableMap(Map aMap); + static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -946,6 +997,84 @@ abstract class FlutterIntegrationCoreApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes was null.'); + final List args = (message as List?)!; + final bool? arg_aNullableBool = (args[0] as bool?); + final int? arg_aNullableInt = (args[1] as int?); + final String? arg_aNullableString = (args[2] as String?); + final AllNullableTypes output = api.sendMultipleNullableTypes( + arg_aNullableBool, arg_aNullableInt, arg_aNullableString); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool was null.'); + final List args = (message as List?)!; + final bool? arg_aBool = (args[0] as bool?); + assert(arg_aBool != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool was null, expected non-null bool.'); + final bool output = api.echoBool(arg_aBool!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt was null.'); + final List args = (message as List?)!; + final int? arg_anInt = (args[0] as int?); + assert(arg_anInt != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt was null, expected non-null int.'); + final int output = api.echoInt(arg_anInt!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble was null.'); + final List args = (message as List?)!; + final double? arg_aDouble = (args[0] as double?); + assert(arg_aDouble != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble was null, expected non-null double.'); + final double output = api.echoDouble(arg_aDouble!); + return output; + }); + } + } { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString', codec, @@ -965,6 +1094,193 @@ abstract class FlutterIntegrationCoreApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List was null.'); + final List args = (message as List?)!; + final Uint8List? arg_aList = (args[0] as Uint8List?); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List was null, expected non-null Uint8List.'); + final Uint8List output = api.echoUint8List(arg_aList!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList was null.'); + final List args = (message as List?)!; + final List? arg_aList = + (args[0] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList was null, expected non-null List.'); + final List output = api.echoList(arg_aList!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap was null.'); + final List args = (message as List?)!; + final Map? arg_aMap = + (args[0] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap was null, expected non-null Map.'); + final Map output = api.echoMap(arg_aMap!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool was null.'); + final List args = (message as List?)!; + final bool? arg_aBool = (args[0] as bool?); + final bool? output = api.echoNullableBool(arg_aBool); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt was null.'); + final List args = (message as List?)!; + final int? arg_anInt = (args[0] as int?); + final int? output = api.echoNullableInt(arg_anInt); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble was null.'); + final List args = (message as List?)!; + final double? arg_aDouble = (args[0] as double?); + final double? output = api.echoNullableDouble(arg_aDouble); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString was null.'); + final List args = (message as List?)!; + final String? arg_aString = (args[0] as String?); + final String? output = api.echoNullableString(arg_aString); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List was null.'); + final List args = (message as List?)!; + final Uint8List? arg_aList = (args[0] as Uint8List?); + final Uint8List? output = api.echoNullableUint8List(arg_aList); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList was null.'); + final List args = (message as List?)!; + final List? arg_aList = + (args[0] as List?)?.cast(); + final List? output = api.echoNullableList(arg_aList); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap was null.'); + final List args = (message as List?)!; + final Map? arg_aMap = + (args[0] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap was null, expected non-null Map.'); + final Map output = api.echoNullableMap(arg_aMap!); + return output; + }); + } + } } } 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 c3b44b0a10..76a6a34767 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 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 3bf1fa5765..f316971d1e 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 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 82bfce2259..60f9dc42c4 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 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 a4a52e6c3f..5d7f772885 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 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 51af74c263..d29b2eb877 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 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 f9855f6dcc..72c9ea21ca 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 23a46acfdf..a47622b3c5 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -527,10 +527,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final String echoObject = await api.callFlutterEchoString(sentObject); expect(echoObject, sentObject); }); - }, - // TODO(stuartmorgan): Enable when FlutterApi generation is fixed for - // C++. See https://github.com/flutter/flutter/issues/108682. - skip: targetGenerator == TargetGenerator.cpp); + }); } class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { @@ -545,10 +542,56 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { } @override - String echoString(String aString) { - return aString; + void noop() {} + + @override + AllNullableTypes sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString) { + return AllNullableTypes( + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableString: aNullableString); } @override - void noop() {} + bool echoBool(bool aBool) => aBool; + + @override + double echoDouble(double aDouble) => aDouble; + + @override + int echoInt(int anInt) => anInt; + + @override + String echoString(String aString) => aString; + + @override + Uint8List echoUint8List(Uint8List aList) => aList; + + @override + List echoList(List aList) => aList; + + @override + Map echoMap(Map aMap) => aMap; + + @override + bool? echoNullableBool(bool? aBool) => aBool; + + @override + double? echoNullableDouble(double? aDouble) => aDouble; + + @override + int? echoNullableInt(int? anInt) => anInt; + + @override + List? echoNullableList(List? aList) => aList; + + @override + Map echoNullableMap(Map aMap) => aMap; + + @override + String? echoNullableString(String? aString) => aString; + + @override + Uint8List? echoNullableUint8List(Uint8List? aList) => aList; } 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 1040f61c12..203f02bcf8 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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), 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 @@ -848,9 +848,12 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { if (value is AllNullableTypes) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllTypes) { + } else if (value is AllNullableTypesWrapper) { buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is AllTypes) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -863,6 +866,9 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { return AllNullableTypes.decode(readValue(buffer)!); case 129: + return AllNullableTypesWrapper.decode(readValue(buffer)!); + + case 130: return AllTypes.decode(readValue(buffer)!); default: @@ -886,9 +892,54 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. AllNullableTypes echoAllNullableTypes(AllNullableTypes everything); + /// Returns passed in arguments of multiple types. + /// + /// Tests multiple-arity FlutterApi handling. + AllNullableTypes sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString); + + /// Returns the passed boolean, to test serialization and deserialization. + bool echoBool(bool aBool); + + /// Returns the passed int, to test serialization and deserialization. + int echoInt(int anInt); + + /// Returns the passed double, to test serialization and deserialization. + double echoDouble(double aDouble); + /// Returns the passed string, to test serialization and deserialization. String echoString(String aString); + /// Returns the passed byte list, to test serialization and deserialization. + Uint8List echoUint8List(Uint8List aList); + + /// Returns the passed list, to test serialization and deserialization. + List echoList(List aList); + + /// Returns the passed map, to test serialization and deserialization. + Map echoMap(Map aMap); + + /// Returns the passed boolean, to test serialization and deserialization. + bool? echoNullableBool(bool? aBool); + + /// Returns the passed int, to test serialization and deserialization. + int? echoNullableInt(int? anInt); + + /// Returns the passed double, to test serialization and deserialization. + double? echoNullableDouble(double? aDouble); + + /// Returns the passed string, to test serialization and deserialization. + String? echoNullableString(String? aString); + + /// Returns the passed byte list, to test serialization and deserialization. + Uint8List? echoNullableUint8List(Uint8List? aList); + + /// Returns the passed list, to test serialization and deserialization. + List? echoNullableList(List? aList); + + /// Returns the passed map, to test serialization and deserialization. + Map echoNullableMap(Map aMap); + static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -946,6 +997,84 @@ abstract class FlutterIntegrationCoreApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes was null.'); + final List args = (message as List?)!; + final bool? arg_aNullableBool = (args[0] as bool?); + final int? arg_aNullableInt = (args[1] as int?); + final String? arg_aNullableString = (args[2] as String?); + final AllNullableTypes output = api.sendMultipleNullableTypes( + arg_aNullableBool, arg_aNullableInt, arg_aNullableString); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool was null.'); + final List args = (message as List?)!; + final bool? arg_aBool = (args[0] as bool?); + assert(arg_aBool != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool was null, expected non-null bool.'); + final bool output = api.echoBool(arg_aBool!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt was null.'); + final List args = (message as List?)!; + final int? arg_anInt = (args[0] as int?); + assert(arg_anInt != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt was null, expected non-null int.'); + final int output = api.echoInt(arg_anInt!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble was null.'); + final List args = (message as List?)!; + final double? arg_aDouble = (args[0] as double?); + assert(arg_aDouble != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble was null, expected non-null double.'); + final double output = api.echoDouble(arg_aDouble!); + return output; + }); + } + } { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString', codec, @@ -965,6 +1094,193 @@ abstract class FlutterIntegrationCoreApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List was null.'); + final List args = (message as List?)!; + final Uint8List? arg_aList = (args[0] as Uint8List?); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List was null, expected non-null Uint8List.'); + final Uint8List output = api.echoUint8List(arg_aList!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList was null.'); + final List args = (message as List?)!; + final List? arg_aList = + (args[0] as List?)?.cast(); + assert(arg_aList != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList was null, expected non-null List.'); + final List output = api.echoList(arg_aList!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap was null.'); + final List args = (message as List?)!; + final Map? arg_aMap = + (args[0] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap was null, expected non-null Map.'); + final Map output = api.echoMap(arg_aMap!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool was null.'); + final List args = (message as List?)!; + final bool? arg_aBool = (args[0] as bool?); + final bool? output = api.echoNullableBool(arg_aBool); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt was null.'); + final List args = (message as List?)!; + final int? arg_anInt = (args[0] as int?); + final int? output = api.echoNullableInt(arg_anInt); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble was null.'); + final List args = (message as List?)!; + final double? arg_aDouble = (args[0] as double?); + final double? output = api.echoNullableDouble(arg_aDouble); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString was null.'); + final List args = (message as List?)!; + final String? arg_aString = (args[0] as String?); + final String? output = api.echoNullableString(arg_aString); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List was null.'); + final List args = (message as List?)!; + final Uint8List? arg_aList = (args[0] as Uint8List?); + final Uint8List? output = api.echoNullableUint8List(arg_aList); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList was null.'); + final List args = (message as List?)!; + final List? arg_aList = + (args[0] as List?)?.cast(); + final List? output = api.echoNullableList(arg_aList); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap was null.'); + final List args = (message as List?)!; + final Map? arg_aMap = + (args[0] as Map?)?.cast(); + assert(arg_aMap != null, + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap was null, expected non-null Map.'); + final Map output = api.echoNullableMap(arg_aMap!); + return output; + }); + } + } } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index c2c039086f..c5f0ee0fa4 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin @@ -713,6 +713,11 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { } } 129.toByte() -> { + return (readValue(buffer) as? List)?.let { + AllNullableTypesWrapper.fromList(it) + } + } + 130.toByte() -> { return (readValue(buffer) as? List)?.let { AllTypes.fromList(it) } @@ -726,10 +731,14 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { stream.write(128) writeValue(stream, value.toList()) } - is AllTypes -> { + is AllNullableTypesWrapper -> { stream.write(129) writeValue(stream, value.toList()) } + is AllTypes -> { + stream.write(130) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -775,6 +784,42 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(result) } } + /** + * Returns passed in arguments of multiple types. + * + * Tests multiple-arity FlutterApi handling. + */ + fun sendMultipleNullableTypes(aNullableBoolArg: Boolean?, aNullableIntArg: Long?, aNullableStringArg: String?, callback: (AllNullableTypes) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", codec) + channel.send(listOf(aNullableBoolArg, aNullableIntArg, aNullableStringArg)) { + val result = it as AllNullableTypes + callback(result) + } + } + /** Returns the passed boolean, to test serialization and deserialization. */ + fun echoBool(aBoolArg: Boolean, callback: (Boolean) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", codec) + channel.send(listOf(aBoolArg)) { + val result = it as Boolean + callback(result) + } + } + /** Returns the passed int, to test serialization and deserialization. */ + fun echoInt(anIntArg: Long, callback: (Long) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", codec) + channel.send(listOf(anIntArg)) { + val result = it as Long + callback(result) + } + } + /** Returns the passed double, to test serialization and deserialization. */ + fun echoDouble(aDoubleArg: Double, callback: (Double) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", codec) + channel.send(listOf(aDoubleArg)) { + val result = it as Double + callback(result) + } + } /** Returns the passed string, to test serialization and deserialization. */ fun echoString(aStringArg: String, callback: (String) -> Unit) { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", codec) @@ -783,6 +828,86 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(result) } } + /** Returns the passed byte list, to test serialization and deserialization. */ + fun echoUint8List(aListArg: ByteArray, callback: (ByteArray) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", codec) + channel.send(listOf(aListArg)) { + val result = it as ByteArray + callback(result) + } + } + /** Returns the passed list, to test serialization and deserialization. */ + fun echoList(aListArg: List, callback: (List) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", codec) + channel.send(listOf(aListArg)) { + val result = it as List + callback(result) + } + } + /** Returns the passed map, to test serialization and deserialization. */ + fun echoMap(aMapArg: Map, callback: (Map) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", codec) + channel.send(listOf(aMapArg)) { + val result = it as Map + callback(result) + } + } + /** Returns the passed boolean, to test serialization and deserialization. */ + fun echoNullableBool(aBoolArg: Boolean?, callback: (Boolean?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", codec) + channel.send(listOf(aBoolArg)) { + val result = it as? Boolean? + callback(result) + } + } + /** Returns the passed int, to test serialization and deserialization. */ + fun echoNullableInt(anIntArg: Long?, callback: (Long?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", codec) + channel.send(listOf(anIntArg)) { + val result = it as? Long? + callback(result) + } + } + /** Returns the passed double, to test serialization and deserialization. */ + fun echoNullableDouble(aDoubleArg: Double?, callback: (Double?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", codec) + channel.send(listOf(aDoubleArg)) { + val result = it as? Double? + callback(result) + } + } + /** Returns the passed string, to test serialization and deserialization. */ + fun echoNullableString(aStringArg: String?, callback: (String?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", codec) + channel.send(listOf(aStringArg)) { + val result = it as? String? + callback(result) + } + } + /** Returns the passed byte list, to test serialization and deserialization. */ + fun echoNullableUint8List(aListArg: ByteArray?, callback: (ByteArray?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", codec) + channel.send(listOf(aListArg)) { + val result = it as? ByteArray? + callback(result) + } + } + /** Returns the passed list, to test serialization and deserialization. */ + fun echoNullableList(aListArg: List?, callback: (List?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", codec) + channel.send(listOf(aListArg)) { + val result = it as? List? + callback(result) + } + } + /** Returns the passed map, to test serialization and deserialization. */ + fun echoNullableMap(aMapArg: Map, callback: (Map) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", codec) + channel.send(listOf(aMapArg)) { + val result = it as Map + callback(result) + } + } } /** * An API that can be implemented for minimal, compile-only tests. diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 407ee69353..522a9d7334 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -574,6 +574,8 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { case 128: return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + case 130: return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) @@ -586,9 +588,12 @@ private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { if let value = value as? AllNullableTypes { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllTypes { + } else if let value = value as? AllNullableTypesWrapper { super.writeByte(129) super.writeValue(value.toList()) + } else if let value = value as? AllTypes { + super.writeByte(130) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -632,7 +637,7 @@ class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. func echoAllTypes(everything everythingArg: AllTypes, completion: @escaping (AllTypes) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([everythingArg]) { response in + channel.sendMessage([everythingArg] as [Any?]) { response in let result = response as! AllTypes completion(result) } @@ -640,19 +645,133 @@ class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. func echoAllNullableTypes(everything everythingArg: AllNullableTypes, completion: @escaping (AllNullableTypes) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([everythingArg]) { response in + channel.sendMessage([everythingArg] as [Any?]) { response in let result = response as! AllNullableTypes completion(result) } } + /// Returns passed in arguments of multiple types. + /// + /// Tests multiple-arity FlutterApi handling. + func sendMultipleNullableTypes(aNullableBool aNullableBoolArg: Bool?, aNullableInt aNullableIntArg: Int32?, aNullableString aNullableStringArg: String?, completion: @escaping (AllNullableTypes) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in + let result = response as! AllNullableTypes + completion(result) + } + } + /// Returns the passed boolean, to test serialization and deserialization. + func echoBool(aBool aBoolArg: Bool, completion: @escaping (Bool) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aBoolArg] as [Any?]) { response in + let result = response as! Bool + completion(result) + } + } + /// Returns the passed int, to test serialization and deserialization. + func echoInt(anInt anIntArg: Int32, completion: @escaping (Int32) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([anIntArg] as [Any?]) { response in + let result = response as! Int32 + completion(result) + } + } + /// Returns the passed double, to test serialization and deserialization. + func echoDouble(aDouble aDoubleArg: Double, completion: @escaping (Double) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aDoubleArg] as [Any?]) { response in + let result = response as! Double + completion(result) + } + } /// Returns the passed string, to test serialization and deserialization. func echoString(aString aStringArg: String, completion: @escaping (String) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aStringArg]) { response in + channel.sendMessage([aStringArg] as [Any?]) { response in let result = response as! String completion(result) } } + /// Returns the passed byte list, to test serialization and deserialization. + func echoUint8List(aList aListArg: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as! FlutterStandardTypedData + completion(result) + } + } + /// Returns the passed list, to test serialization and deserialization. + func echoList(aList aListArg: [Any?], completion: @escaping ([Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as! [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] + completion(result) + } + } + /// Returns the passed boolean, to test serialization and deserialization. + func echoNullableBool(aBool aBoolArg: Bool?, completion: @escaping (Bool?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aBoolArg] as [Any?]) { response in + let result = response as? Bool + completion(result) + } + } + /// Returns the passed int, to test serialization and deserialization. + func echoNullableInt(anInt anIntArg: Int32?, completion: @escaping (Int32?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([anIntArg] as [Any?]) { response in + let result = response as? Int32 + completion(result) + } + } + /// Returns the passed double, to test serialization and deserialization. + func echoNullableDouble(aDouble aDoubleArg: Double?, completion: @escaping (Double?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aDoubleArg] as [Any?]) { response in + let result = response as? Double + completion(result) + } + } + /// Returns the passed string, to test serialization and deserialization. + func echoNullableString(aString aStringArg: String?, completion: @escaping (String?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aStringArg] as [Any?]) { response in + let result = response as? String + completion(result) + } + } + /// Returns the passed byte list, to test serialization and deserialization. + func echoNullableUint8List(aList aListArg: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as? FlutterStandardTypedData + completion(result) + } + } + /// Returns the passed list, to test serialization and deserialization. + func echoNullableList(aList aListArg: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as? [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] + completion(result) + } + } } /// An API that can be implemented for minimal, compile-only tests. /// diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 407ee69353..522a9d7334 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -574,6 +574,8 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { case 128: return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + case 130: return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) @@ -586,9 +588,12 @@ private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { if let value = value as? AllNullableTypes { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllTypes { + } else if let value = value as? AllNullableTypesWrapper { super.writeByte(129) super.writeValue(value.toList()) + } else if let value = value as? AllTypes { + super.writeByte(130) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -632,7 +637,7 @@ class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. func echoAllTypes(everything everythingArg: AllTypes, completion: @escaping (AllTypes) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([everythingArg]) { response in + channel.sendMessage([everythingArg] as [Any?]) { response in let result = response as! AllTypes completion(result) } @@ -640,19 +645,133 @@ class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. func echoAllNullableTypes(everything everythingArg: AllNullableTypes, completion: @escaping (AllNullableTypes) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([everythingArg]) { response in + channel.sendMessage([everythingArg] as [Any?]) { response in let result = response as! AllNullableTypes completion(result) } } + /// Returns passed in arguments of multiple types. + /// + /// Tests multiple-arity FlutterApi handling. + func sendMultipleNullableTypes(aNullableBool aNullableBoolArg: Bool?, aNullableInt aNullableIntArg: Int32?, aNullableString aNullableStringArg: String?, completion: @escaping (AllNullableTypes) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in + let result = response as! AllNullableTypes + completion(result) + } + } + /// Returns the passed boolean, to test serialization and deserialization. + func echoBool(aBool aBoolArg: Bool, completion: @escaping (Bool) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aBoolArg] as [Any?]) { response in + let result = response as! Bool + completion(result) + } + } + /// Returns the passed int, to test serialization and deserialization. + func echoInt(anInt anIntArg: Int32, completion: @escaping (Int32) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([anIntArg] as [Any?]) { response in + let result = response as! Int32 + completion(result) + } + } + /// Returns the passed double, to test serialization and deserialization. + func echoDouble(aDouble aDoubleArg: Double, completion: @escaping (Double) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aDoubleArg] as [Any?]) { response in + let result = response as! Double + completion(result) + } + } /// Returns the passed string, to test serialization and deserialization. func echoString(aString aStringArg: String, completion: @escaping (String) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aStringArg]) { response in + channel.sendMessage([aStringArg] as [Any?]) { response in let result = response as! String completion(result) } } + /// Returns the passed byte list, to test serialization and deserialization. + func echoUint8List(aList aListArg: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as! FlutterStandardTypedData + completion(result) + } + } + /// Returns the passed list, to test serialization and deserialization. + func echoList(aList aListArg: [Any?], completion: @escaping ([Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as! [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] + completion(result) + } + } + /// Returns the passed boolean, to test serialization and deserialization. + func echoNullableBool(aBool aBoolArg: Bool?, completion: @escaping (Bool?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aBoolArg] as [Any?]) { response in + let result = response as? Bool + completion(result) + } + } + /// Returns the passed int, to test serialization and deserialization. + func echoNullableInt(anInt anIntArg: Int32?, completion: @escaping (Int32?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([anIntArg] as [Any?]) { response in + let result = response as? Int32 + completion(result) + } + } + /// Returns the passed double, to test serialization and deserialization. + func echoNullableDouble(aDouble aDoubleArg: Double?, completion: @escaping (Double?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aDoubleArg] as [Any?]) { response in + let result = response as? Double + completion(result) + } + } + /// Returns the passed string, to test serialization and deserialization. + func echoNullableString(aString aStringArg: String?, completion: @escaping (String?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aStringArg] as [Any?]) { response in + let result = response as? String + completion(result) + } + } + /// Returns the passed byte list, to test serialization and deserialization. + func echoNullableUint8List(aList aListArg: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as? FlutterStandardTypedData + completion(result) + } + } + /// Returns the passed list, to test serialization and deserialization. + func echoNullableList(aList aListArg: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aListArg] as [Any?]) { response in + let result = response as? [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap(aMap aMapArg: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] + completion(result) + } + } } /// An API that can be implemented for minimal, compile-only tests. /// diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 6c39bceea1..d205dbb0e1 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -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 (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS @@ -545,10 +545,9 @@ const flutter::StandardMessageCodec& HostIntegrationCoreApi::GetCodec() { void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, HostIntegrationCoreApi* api) { { - auto channel = - std::make_unique>( - binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.noop", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.noop", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -571,11 +570,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -608,11 +605,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -648,11 +644,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.throwError", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.throwError", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -675,10 +669,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -709,11 +702,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -745,10 +736,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -779,11 +769,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -815,11 +803,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -852,11 +838,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -888,8 +872,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = std::make_unique< - flutter::BasicMessageChannel>( + auto channel = std::make_unique>( binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", &GetCodec()); @@ -932,8 +915,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = std::make_unique< - flutter::BasicMessageChannel>( + auto channel = std::make_unique>( binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", &GetCodec()); @@ -965,8 +947,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = std::make_unique< - flutter::BasicMessageChannel>( + auto channel = std::make_unique>( binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", &GetCodec()); @@ -1011,11 +992,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1055,11 +1035,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1093,11 +1072,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1131,11 +1109,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1169,11 +1146,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1208,11 +1184,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1246,10 +1221,9 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1273,11 +1247,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1311,11 +1284,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1340,11 +1312,10 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } } { - auto channel = - std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, @@ -1403,6 +1374,10 @@ FlutterIntegrationCoreApiCodecSerializer::ReadValueOfType( std::get(ReadValue(stream)))); case 129: + return flutter::CustomEncodableValue(AllNullableTypesWrapper( + std::get(ReadValue(stream)))); + + case 130: return flutter::CustomEncodableValue( AllTypes(std::get(ReadValue(stream)))); @@ -1424,8 +1399,16 @@ void FlutterIntegrationCoreApiCodecSerializer::WriteValue( stream); return; } - if (custom_value->type() == typeid(AllTypes)) { + if (custom_value->type() == typeid(AllNullableTypesWrapper)) { stream->WriteByte(129); + WriteValue(flutter::EncodableValue( + std::any_cast(*custom_value) + .ToEncodableList()), + stream); + return; + } + if (custom_value->type() == typeid(AllTypes)) { + stream->WriteByte(130); WriteValue(flutter::EncodableValue( std::any_cast(*custom_value).ToEncodableList()), stream); @@ -1447,82 +1430,423 @@ const flutter::StandardMessageCodec& FlutterIntegrationCoreApi::GetCodec() { &FlutterIntegrationCoreApiCodecSerializer::GetInstance()); } -void FlutterIntegrationCoreApi::noop(std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.noop", &GetCodec()); +void FlutterIntegrationCoreApi::Noop( + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, "dev.flutter.pigeon.FlutterIntegrationCoreApi.noop", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(); channel->Send( - flutter::EncodableValue(), - [callback](const uint8_t* reply, size_t reply_size) { callback(); }); + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { on_success(); }); } -void FlutterIntegrationCoreApi::echoAllTypes( +void FlutterIntegrationCoreApi::EchoAllTypes( const AllTypes& everything_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", - &GetCodec()); + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(everything_arg.ToEncodableList()), + }); channel->Send( - flutter::EncodableList{flutter::CustomEncodableValue(everything_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size); - flutter::EncodableValue args = - *(flutter::EncodableValue*)(decoded_reply.release()); - AllTypes output{}; - if (const flutter::EncodableList* pointer_output = - std::get_if(&args)) { - output = AllTypes(*pointer_output); - } - callback(output); + const auto& encodable_return_value = *response; + const auto& return_value = std::any_cast( + std::get(encodable_return_value)); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoAllNullableTypes( +void FlutterIntegrationCoreApi::EchoAllNullableTypes( const AllNullableTypes& everything_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", - &GetCodec()); + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(everything_arg.ToEncodableList()), + }); channel->Send( - flutter::EncodableList{flutter::CustomEncodableValue(everything_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size); - flutter::EncodableValue args = - *(flutter::EncodableValue*)(decoded_reply.release()); - AllNullableTypes output{}; - if (const flutter::EncodableList* pointer_output = - std::get_if(&args)) { - output = AllNullableTypes(*pointer_output); - } - callback(output); + const auto& encodable_return_value = *response; + const auto& return_value = std::any_cast( + std::get(encodable_return_value)); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoString( - const std::string& a_string_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", - &GetCodec()); +void FlutterIntegrationCoreApi::SendMultipleNullableTypes( + const bool* a_nullable_bool_arg, const int64_t* a_nullable_int_arg, + const std::string* a_nullable_string_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_nullable_bool_arg ? flutter::EncodableValue(*a_nullable_bool_arg) + : flutter::EncodableValue(), + a_nullable_int_arg ? flutter::EncodableValue(*a_nullable_int_arg) + : flutter::EncodableValue(), + a_nullable_string_arg + ? flutter::EncodableValue(*a_nullable_string_arg) + : flutter::EncodableValue(), + }); channel->Send( - flutter::EncodableList{flutter::CustomEncodableValue(a_string_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size); - flutter::EncodableValue args = - *(flutter::EncodableValue*)(decoded_reply.release()); - std::string output{}; - if (const std::string* pointer_output = - std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto& return_value = std::any_cast( + std::get(encodable_return_value)); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoBool( + bool a_bool_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_bool_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = std::get(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoInt( + int64_t an_int_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(an_int_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const int64_t return_value = encodable_return_value.LongValue(); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoDouble( + double a_double_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_double_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = std::get(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoString( + const std::string& a_string_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_string_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoUint8List( + const std::vector& a_list_arg, + std::function&)>&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_list_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get>(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoList( + const flutter::EncodableList& a_list_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_list_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoMap( + const flutter::EncodableMap& a_map_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_map_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableBool( + const bool* a_bool_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_bool_arg ? flutter::EncodableValue(*a_bool_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* return_value = std::get_if(&encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableInt( + const int64_t* an_int_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + an_int_arg ? flutter::EncodableValue(*an_int_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const int64_t return_value_value = + encodable_return_value.IsNull() + ? 0 + : encodable_return_value.LongValue(); + const auto* return_value = + encodable_return_value.IsNull() ? nullptr : &return_value_value; + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableDouble( + const double* a_double_arg, std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_double_arg ? flutter::EncodableValue(*a_double_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* return_value = std::get_if(&encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableString( + const std::string* a_string_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_string_arg ? flutter::EncodableValue(*a_string_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* return_value = + std::get_if(&encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableUint8List( + const std::vector* a_list_arg, + std::function*)>&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_list_arg ? flutter::EncodableValue(*a_list_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* return_value = + std::get_if>(&encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableList( + const flutter::EncodableList* a_list_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + a_list_arg ? flutter::EncodableValue(*a_list_arg) + : flutter::EncodableValue(), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* return_value = + std::get_if(&encodable_return_value); + on_success(return_value); + }); +} +void FlutterIntegrationCoreApi::EchoNullableMap( + const flutter::EncodableMap& a_map_arg, + std::function&& on_success, + std::function&& on_error) { + auto channel = std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", + &GetCodec()); + flutter::EncodableValue encoded_api_arguments = + flutter::EncodableValue(flutter::EncodableList{ + flutter::EncodableValue(a_map_arg), + }); + channel->Send( + encoded_api_arguments, + [on_success = std::move(on_success), on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); }); } /// The codec used by HostTrivialApi. @@ -1536,10 +1860,9 @@ const flutter::StandardMessageCodec& HostTrivialApi::GetCodec() { void HostTrivialApi::SetUp(flutter::BinaryMessenger* binary_messenger, HostTrivialApi* api) { { - auto channel = - std::make_unique>( - binary_messenger, "dev.flutter.pigeon.HostTrivialApi.noop", - &GetCodec()); + auto channel = std::make_unique>( + binary_messenger, "dev.flutter.pigeon.HostTrivialApi.noop", + &GetCodec()); if (api != nullptr) { channel->SetMessageHandler( [api](const flutter::EncodableValue& message, diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index c752a5a1f3..545a050caf 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v6.0.0), do not edit directly. +// Autogenerated from Pigeon (v6.0.1), do not edit directly. // See also: https://pub.dev/packages/pigeon -#ifndef PIGEON_CORE_TESTS_GEN_H_H_ -#define PIGEON_CORE_TESTS_GEN_H_H_ +#ifndef PIGEON_CORE_TESTS_GEN_H_ +#define PIGEON_CORE_TESTS_GEN_H_ #include #include #include @@ -376,17 +376,82 @@ class FlutterIntegrationCoreApi { static const flutter::StandardMessageCodec& GetCodec(); // A no-op function taking no arguments and returning no value, to sanity // test basic calling. - void noop(std::function&& callback); + void Noop(std::function&& on_success, + std::function&& on_error); // Returns the passed object, to test serialization and deserialization. - void echoAllTypes(const AllTypes& everything_arg, - std::function&& callback); + void EchoAllTypes(const AllTypes& everything, + std::function&& on_success, + std::function&& on_error); // Returns the passed object, to test serialization and deserialization. - void echoAllNullableTypes( - const AllNullableTypes& everything_arg, - std::function&& callback); + void EchoAllNullableTypes( + const AllNullableTypes& everything, + std::function&& on_success, + std::function&& on_error); + // Returns passed in arguments of multiple types. + // + // Tests multiple-arity FlutterApi handling. + void SendMultipleNullableTypes( + const bool* a_nullable_bool, const int64_t* a_nullable_int, + const std::string* a_nullable_string, + std::function&& on_success, + std::function&& on_error); + // Returns the passed boolean, to test serialization and deserialization. + void EchoBool(bool a_bool, std::function&& on_success, + std::function&& on_error); + // Returns the passed int, to test serialization and deserialization. + void EchoInt(int64_t an_int, std::function&& on_success, + std::function&& on_error); + // Returns the passed double, to test serialization and deserialization. + void EchoDouble(double a_double, std::function&& on_success, + std::function&& on_error); // Returns the passed string, to test serialization and deserialization. - void echoString(const std::string& a_string_arg, - std::function&& callback); + void EchoString(const std::string& a_string, + std::function&& on_success, + std::function&& on_error); + // Returns the passed byte list, to test serialization and deserialization. + void EchoUint8List( + const std::vector& a_list, + std::function&)>&& on_success, + std::function&& on_error); + // Returns the passed list, to test serialization and deserialization. + void EchoList(const flutter::EncodableList& a_list, + std::function&& on_success, + std::function&& on_error); + // Returns the passed map, to test serialization and deserialization. + void EchoMap(const flutter::EncodableMap& a_map, + std::function&& on_success, + std::function&& on_error); + // Returns the passed boolean, to test serialization and deserialization. + void EchoNullableBool(const bool* a_bool, + std::function&& on_success, + std::function&& on_error); + // Returns the passed int, to test serialization and deserialization. + void EchoNullableInt(const int64_t* an_int, + std::function&& on_success, + std::function&& on_error); + // Returns the passed double, to test serialization and deserialization. + void EchoNullableDouble(const double* a_double, + std::function&& on_success, + std::function&& on_error); + // Returns the passed string, to test serialization and deserialization. + void EchoNullableString(const std::string* a_string, + std::function&& on_success, + std::function&& on_error); + // Returns the passed byte list, to test serialization and deserialization. + void EchoNullableUint8List( + const std::vector* a_list, + std::function*)>&& on_success, + std::function&& on_error); + // Returns the passed list, to test serialization and deserialization. + void EchoNullableList( + const flutter::EncodableList* a_list, + std::function&& on_success, + std::function&& on_error); + // Returns the passed map, to test serialization and deserialization. + void EchoNullableMap( + const flutter::EncodableMap& a_map, + std::function&& on_success, + std::function&& on_error); }; // An API that can be implemented for minimal, compile-only tests. @@ -413,4 +478,4 @@ class HostTrivialApi { HostTrivialApi() = default; }; } // namespace core_tests_pigeontest -#endif // PIGEON_CORE_TESTS_GEN_H_H_ +#endif // PIGEON_CORE_TESTS_GEN_H_ diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index 8c35994b98..b5477b49df 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -179,15 +179,17 @@ void TestPlugin::EchoAsyncString( void TestPlugin::CallFlutterNoop( std::function reply)> result) { - flutter_api_->noop([result]() { result(std::nullopt); }); + flutter_api_->Noop([result]() { result(std::nullopt); }, + [result](const FlutterError& error) { result(error); }); } void TestPlugin::CallFlutterEchoString( const std::string& a_string, std::function reply)> result) { - flutter_api_->echoString( + flutter_api_->EchoString( a_string, - [result](const std::string& flutter_string) { result(flutter_string); }); + [result](const std::string& flutter_string) { result(flutter_string); }, + [result](const FlutterError& error) { result(error); }); } } // namespace test_plugin diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index caa82a391d..1f0861307f 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: 6.0.0 # This must match the version in lib/generator_tools.dart +version: 6.0.1 # 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 97dc129860..9aa4784708 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1154,6 +1154,274 @@ void main() { } }); + test('flutter nullable arguments map correctly', () { + final Root root = Root(apis: [ + Api(name: 'Api', location: ApiLocation.flutter, methods: [ + Method( + name: 'doSomething', + arguments: [ + NamedType( + name: 'aBool', + type: const TypeDeclaration( + baseName: 'bool', + isNullable: true, + )), + NamedType( + name: 'anInt', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + )), + NamedType( + name: 'aString', + type: const TypeDeclaration( + baseName: 'String', + isNullable: true, + )), + NamedType( + name: 'aList', + type: const TypeDeclaration( + baseName: 'List', + typeArguments: [ + TypeDeclaration(baseName: 'Object', isNullable: true) + ], + isNullable: true, + )), + NamedType( + name: 'aMap', + type: const TypeDeclaration( + baseName: 'Map', + typeArguments: [ + TypeDeclaration(baseName: 'String', isNullable: true), + TypeDeclaration(baseName: 'Object', isNullable: true), + ], + isNullable: true, + )), + NamedType( + name: 'anObject', + type: const TypeDeclaration( + baseName: 'ParameterObject', + isNullable: true, + )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: true, + )), + ], + returnType: const TypeDeclaration( + baseName: 'bool', + isNullable: true, + ), + ), + ]) + ], classes: [ + Class(name: 'ParameterObject', fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), + name: 'aValue'), + ]), + ], enums: []); + { + final StringBuffer sink = StringBuffer(); + const CppGenerator generator = CppGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.header, + languageOptions: const CppOptions(), + ); + generator.generate(generatorOptions, root, sink); + final String code = sink.toString(); + // Nullable arguments should all be pointers. This will make them somewhat + // awkward for some uses (literals, values that could be inlined) but + // unlike setters there's no way to provide reference-based alternatives + // since it's not always just one argument. + // TODO(stuartmorgan): Consider generating a second variant using + // `std::optional`s; that may be more ergonomic, but the perf implications + // would need to be considered. + expect( + code, + contains('DoSomething(const bool* a_bool, ' + 'const int64_t* an_int, ' + // Nullable strings use std::string* rather than std::string_view* + // since there's no implicit conversion for pointer types. + 'const std::string* a_string, ' + 'const flutter::EncodableList* a_list, ' + 'const flutter::EncodableMap* a_map, ' + 'const ParameterObject* an_object, ' + 'const flutter::EncodableValue* a_generic_object, ')); + // The callback should pass a pointer as well. + expect( + code, + contains('std::function&& on_success, ' + 'std::function&& on_error)')); + } + { + final StringBuffer sink = StringBuffer(); + const CppGenerator generator = CppGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.source, + languageOptions: const CppOptions(), + ); + generator.generate(generatorOptions, root, sink); + final String code = sink.toString(); + // All types pass nulls values when the pointer is null. + // Standard types are wrapped an EncodableValues. + expect( + code, + contains( + 'a_bool_arg ? flutter::EncodableValue(*a_bool_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'an_int_arg ? flutter::EncodableValue(*an_int_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'a_string_arg ? flutter::EncodableValue(*a_string_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'a_list_arg ? flutter::EncodableValue(*a_list_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'a_map_arg ? flutter::EncodableValue(*a_map_arg) : flutter::EncodableValue()')); + // Class types use ToEncodableList. + expect( + code, + contains( + 'an_object_arg ? flutter::EncodableValue(an_object_arg->ToEncodableList()) : flutter::EncodableValue()')); + } + }); + + test('flutter non-nullable arguments map correctly', () { + final Root root = Root(apis: [ + Api(name: 'Api', location: ApiLocation.flutter, methods: [ + Method( + name: 'doSomething', + arguments: [ + NamedType( + name: 'aBool', + type: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + )), + NamedType( + name: 'anInt', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + )), + NamedType( + name: 'aString', + type: const TypeDeclaration( + baseName: 'String', + isNullable: false, + )), + NamedType( + name: 'aList', + type: const TypeDeclaration( + baseName: 'List', + typeArguments: [ + TypeDeclaration(baseName: 'Object', isNullable: true) + ], + isNullable: false, + )), + NamedType( + name: 'aMap', + type: const TypeDeclaration( + baseName: 'Map', + typeArguments: [ + TypeDeclaration(baseName: 'String', isNullable: true), + TypeDeclaration(baseName: 'Object', isNullable: true), + ], + isNullable: false, + )), + NamedType( + name: 'anObject', + type: const TypeDeclaration( + baseName: 'ParameterObject', + isNullable: false, + )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: false, + )), + ], + returnType: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), + ), + ]) + ], classes: [ + Class(name: 'ParameterObject', fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), + name: 'aValue'), + ]), + ], enums: []); + { + final StringBuffer sink = StringBuffer(); + const CppGenerator generator = CppGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.header, + languageOptions: const CppOptions(), + ); + generator.generate(generatorOptions, root, sink); + final String code = sink.toString(); + expect( + code, + contains('DoSomething(bool a_bool, ' + 'int64_t an_int, ' + // Non-nullable strings use std::string for consistency with + // nullable strings. + 'const std::string& a_string, ' + // Non-POD types use const references. + 'const flutter::EncodableList& a_list, ' + 'const flutter::EncodableMap& a_map, ' + 'const ParameterObject& an_object, ' + 'const flutter::EncodableValue& a_generic_object, ')); + // The callback should pass a value. + expect( + code, + contains('std::function&& on_success, ' + 'std::function&& on_error)')); + } + { + final StringBuffer sink = StringBuffer(); + const CppGenerator generator = CppGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.source, + languageOptions: const CppOptions(), + ); + generator.generate(generatorOptions, root, sink); + final String code = sink.toString(); + // Standard types are wrapped an EncodableValues. + expect(code, contains('flutter::EncodableValue(a_bool_arg)')); + expect(code, contains('flutter::EncodableValue(an_int_arg)')); + expect(code, contains('flutter::EncodableValue(a_string_arg)')); + expect(code, contains('flutter::EncodableValue(a_list_arg)')); + expect(code, contains('flutter::EncodableValue(a_map_arg)')); + // Class types use ToEncodableList. + expect(code, + contains('flutter::EncodableValue(an_object_arg.ToEncodableList())')); + } + }); + test('host API argument extraction uses references', () { final Root root = Root(apis: [ Api(name: 'Api', location: ApiLocation.host, methods: [ diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index dfd2dfbb48..1bf859461b 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -834,7 +834,8 @@ void main() { code, contains( 'func add(x xArg: Int32, y yArg: Int32, completion: @escaping (Int32) -> Void)')); - expect(code, contains('channel.sendMessage([xArg, yArg]) { response in')); + expect(code, + contains('channel.sendMessage([xArg, yArg] as [Any?]) { response in')); }); test('return nullable host', () {