From eea85bcecf25ce63c43be846fab566184d43b368 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Dec 2022 08:09:40 -0500 Subject: [PATCH 01/25] Add new APIs, unimplemented and unused --- packages/pigeon/pigeons/core_tests.dart | 52 +++ .../CoreTests.java | 196 +++++++++++- .../ios/Classes/CoreTests.gen.h | 40 +++ .../ios/Classes/CoreTests.gen.m | 166 +++++++++- .../lib/src/generated/core_tests.gen.dart | 291 ++++++++++++++++- .../com/example/test_plugin/CoreTests.gen.kt | 115 ++++++- .../ios/Classes/CoreTests.gen.swift | 111 ++++++- .../macos/Classes/CoreTests.gen.swift | 111 ++++++- .../windows/pigeon/core_tests.gen.cpp | 302 +++++++++++++++++- .../windows/pigeon/core_tests.gen.h | 42 +++ 10 files changed, 1419 insertions(+), 7 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index ed4ba3a3521e..36eff7c3840f 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -213,9 +213,61 @@ abstract class FlutterIntegrationCoreApi { @ObjCSelector('echoAllNullableTypes:') AllNullableTypes echoAllNullableTypes(AllNullableTypes everything); + /// 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); + + /// 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 ea8e343c37f6..f820302e7f6b 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 @@ -1509,6 +1509,9 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { 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: @@ -1521,8 +1524,11 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { 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); @@ -1594,6 +1600,47 @@ public void echoAllNullableTypes( 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 = @@ -1609,6 +1656,153 @@ public void echoString(@NonNull String aStringArg, Reply callback) { 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 2db8f7122ae0..2ea3bd4ebe77 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 @@ -203,9 +203,49 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); /// Returns the passed object, to test serialization and deserialization. - (void)echoAllNullableTypes:(AllNullableTypes *)everything 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. NSObject *HostTrivialApiGetCodec(void); 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 078bf32b5011..4d902dfe21a0 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 @@ -788,6 +788,9 @@ - (nullable id)readValueOfType:(UInt8)type { return [AllNullableTypes fromList:[self readValue]]; case 129: + return [AllNullableTypesWrapper fromList:[self readValue]]; + + case 130: return [AllTypes fromList:[self readValue]]; default: @@ -803,9 +806,12 @@ - (void)writeValue:(id)value { 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]; } @@ -881,6 +887,42 @@ - (void)echoAllNullableTypes:(AllNullableTypes *)arg_everything 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 @@ -893,6 +935,128 @@ - (void)echoString:(NSString *)arg_aString 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() { static FlutterStandardMessageCodec *sSharedObject = nil; 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 3560cc2c37bb..7f22e44cb08e 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 @@ -847,9 +847,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); } @@ -862,6 +865,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: @@ -885,9 +891,48 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. AllNullableTypes echoAllNullableTypes(AllNullableTypes everything); + /// 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}) { { @@ -945,6 +990,63 @@ abstract class FlutterIntegrationCoreApi { }); } } + { + 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, @@ -964,6 +1066,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 17d7e9ffeb96..907eb382ae8f 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 @@ -703,6 +703,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) } @@ -716,10 +721,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) } } @@ -765,6 +774,30 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { 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) @@ -773,6 +806,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 bcf93bcfcc88..1d6005f7a837 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 @@ -563,6 +563,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) @@ -575,9 +577,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) } @@ -634,6 +639,30 @@ class FlutterIntegrationCoreApi { 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]) { 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]) { 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]) { 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) @@ -642,6 +671,86 @@ class FlutterIntegrationCoreApi { 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]) { 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]) { response in + let result = response as! [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoMap(aMap aMapArg: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg]) { response in + let result = response as! [Any?: 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]) { 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]) { 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]) { 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]) { 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]) { 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]) { response in + let result = response as? [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap(aMap aMapArg: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg]) { response in + let result = response as! [Any?: 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 bcf93bcfcc88..1d6005f7a837 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 @@ -563,6 +563,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) @@ -575,9 +577,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) } @@ -634,6 +639,30 @@ class FlutterIntegrationCoreApi { 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]) { 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]) { 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]) { 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) @@ -642,6 +671,86 @@ class FlutterIntegrationCoreApi { 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]) { 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]) { response in + let result = response as! [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoMap(aMap aMapArg: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg]) { response in + let result = response as! [Any?: 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]) { 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]) { 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]) { 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]) { 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]) { 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]) { response in + let result = response as? [Any?] + completion(result) + } + } + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap(aMap aMapArg: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([aMapArg]) { response in + let result = response as! [Any?: 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 98b9395618e0..5f79079c8983 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 @@ -1403,6 +1403,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 +1428,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); @@ -1502,6 +1514,68 @@ void FlutterIntegrationCoreApi::echoAllNullableTypes( callback(output); }); } +void FlutterIntegrationCoreApi::echoBool(bool a_bool_arg, + std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_bool_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + bool output{}; + if (const bool* pointer_output = std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoInt( + int64_t an_int_arg, std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(an_int_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + int64_t output{}; + if (const int32_t* pointer_output = std::get_if(&args)) + output = *pointer_output; + else if (const int64_t* pointer_output_64 = std::get_if(&args)) + output = *pointer_output_64; + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoDouble( + double a_double_arg, std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_double_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + double output{}; + if (const double* pointer_output = std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} void FlutterIntegrationCoreApi::echoString( const std::string& a_string_arg, std::function&& callback) { @@ -1525,6 +1599,232 @@ void FlutterIntegrationCoreApi::echoString( callback(output); }); } +void FlutterIntegrationCoreApi::echoUint8List( + const std::vector& a_list_arg, + std::function&)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::vector output{}; + if (const std::vector* pointer_output = + std::get_if>(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoList( + const flutter::EncodableList& a_list_arg, + std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + flutter::EncodableList output{}; + if (const flutter::EncodableList* pointer_output = + std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoMap( + const flutter::EncodableMap& a_map_arg, + std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_map_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + flutter::EncodableMap output{}; + if (const flutter::EncodableMap* pointer_output = + std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableBool( + std::optional a_bool_arg, + std::function)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_bool_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional output{}; + if (const bool* pointer_output = std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableInt( + std::optional an_int_arg, + std::function)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(an_int_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional output{}; + if (const int32_t* pointer_output = std::get_if(&args)) + output = *pointer_output; + else if (const int64_t* pointer_output_64 = std::get_if(&args)) + output = *pointer_output_64; + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableDouble( + std::optional a_double_arg, + std::function)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_double_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional output{}; + if (const double* pointer_output = std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableString( + std::optional a_string_arg, + std::function)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_string_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional output{}; + if (const std::string* pointer_output = + std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableUint8List( + std::optional> a_list_arg, + std::function>)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional> output{}; + if (const std::vector* pointer_output = + std::get_if>(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableList( + std::optional a_list_arg, + std::function)>&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + std::optional output{}; + if (const flutter::EncodableList* pointer_output = + std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} +void FlutterIntegrationCoreApi::echoNullableMap( + const flutter::EncodableMap& a_map_arg, + std::function&& callback) { + auto channel = + std::make_unique>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", + &GetCodec()); + channel->Send( + flutter::EncodableList{flutter::CustomEncodableValue(a_map_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + GetCodec().DecodeMessage(reply, reply_size); + flutter::EncodableValue args = + *(flutter::EncodableValue*)(decoded_reply.release()); + flutter::EncodableMap output{}; + if (const flutter::EncodableMap* pointer_output = + std::get_if(&args)) { + output = *pointer_output; + } + callback(output); + }); +} /// The codec used by HostTrivialApi. const flutter::StandardMessageCodec& HostTrivialApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( 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 aac405e9ce84..cb7c79f2b68f 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 @@ -383,9 +383,51 @@ class FlutterIntegrationCoreApi { void echoAllNullableTypes( const AllNullableTypes& everything_arg, std::function&& callback); + // Returns the passed boolean, to test serialization and deserialization. + void echoBool(bool a_bool_arg, std::function&& callback); + // Returns the passed int, to test serialization and deserialization. + void echoInt(int64_t an_int_arg, std::function&& callback); + // Returns the passed double, to test serialization and deserialization. + void echoDouble(double a_double_arg, std::function&& callback); // Returns the passed string, to test serialization and deserialization. void echoString(const std::string& a_string_arg, std::function&& callback); + // Returns the passed byte list, to test serialization and deserialization. + void echoUint8List( + const std::vector& a_list_arg, + std::function&)>&& callback); + // Returns the passed list, to test serialization and deserialization. + void echoList(const flutter::EncodableList& a_list_arg, + std::function&& callback); + // Returns the passed map, to test serialization and deserialization. + void echoMap(const flutter::EncodableMap& a_map_arg, + std::function&& callback); + // Returns the passed boolean, to test serialization and deserialization. + void echoNullableBool(std::optional a_bool_arg, + std::function)>&& callback); + // Returns the passed int, to test serialization and deserialization. + void echoNullableInt(std::optional an_int_arg, + std::function)>&& callback); + // Returns the passed double, to test serialization and deserialization. + void echoNullableDouble( + std::optional a_double_arg, + std::function)>&& callback); + // Returns the passed string, to test serialization and deserialization. + void echoNullableString( + std::optional a_string_arg, + std::function)>&& callback); + // Returns the passed byte list, to test serialization and deserialization. + void echoNullableUint8List( + std::optional> a_list_arg, + std::function>)>&& callback); + // Returns the passed list, to test serialization and deserialization. + void echoNullableList( + std::optional a_list_arg, + std::function)>&& callback); + // Returns the passed map, to test serialization and deserialization. + void echoNullableMap( + const flutter::EncodableMap& a_map_arg, + std::function&& callback); }; // An API that can be implemented for minimal, compile-only tests. From 3fec84418e4c033a7ff42e68ea927497af6e568b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Dec 2022 08:15:20 -0500 Subject: [PATCH 02/25] Add Dart implementation --- .../lib/integration_tests.dart | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) 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 23a46acfdfae..06f3d471ed15 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 @@ -545,10 +545,47 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { } @override - String echoString(String aString) { - return aString; - } + void noop() {} @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; } From a0b15bb72330ea778c78595f112728dee2d50d7c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Dec 2022 09:31:11 -0500 Subject: [PATCH 03/25] Add multiple arity FlutterApi --- packages/pigeon/pigeons/core_tests.dart | 11 ++++++++ .../CoreTests.java | 25 +++++++++++++++++ .../ios/Classes/CoreTests.gen.h | 8 ++++++ .../ios/Classes/CoreTests.gen.m | 19 +++++++++++++ .../lib/integration_tests.dart | 9 ++++++ .../lib/src/generated/core_tests.gen.dart | 27 ++++++++++++++++++ .../com/example/test_plugin/CoreTests.gen.kt | 12 ++++++++ .../ios/Classes/CoreTests.gen.swift | 10 +++++++ .../macos/Classes/CoreTests.gen.swift | 10 +++++++ .../windows/pigeon/core_tests.gen.cpp | 28 +++++++++++++++++++ .../windows/pigeon/core_tests.gen.h | 8 ++++++ 11 files changed, 167 insertions(+) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 36eff7c3840f..14efa90304a3 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -213,6 +213,15 @@ 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); @@ -241,6 +250,8 @@ abstract class FlutterIntegrationCoreApi { @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); 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 f820302e7f6b..fd504177af38 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 @@ -17,6 +17,7 @@ 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; @@ -1600,6 +1601,30 @@ public void echoAllNullableTypes( 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 = 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 2ea3bd4ebe77..b58106bbc184 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 @@ -203,6 +203,14 @@ 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; 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 4d902dfe21a0..8cc9b52e955e 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 @@ -887,6 +887,25 @@ - (void)echoAllNullableTypes:(AllNullableTypes *)arg_everything 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 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 06f3d471ed15..adff0186a9b8 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 @@ -547,6 +547,15 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { @override void noop() {} + @override + AllNullableTypes sendMultipleNullableTypes( + bool? aNullableBool, int? aNullableInt, String? aNullableString) { + return AllNullableTypes( + aNullableBool: aNullableBool, + aNullableInt: aNullableInt, + aNullableString: aNullableString); + } + @override bool echoBool(bool aBool) => aBool; 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 7f22e44cb08e..9f7cc8e8d0e9 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 @@ -891,6 +891,12 @@ 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); @@ -990,6 +996,27 @@ 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, 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 907eb382ae8f..c818a44fa439 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 @@ -774,6 +774,18 @@ 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) 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 1d6005f7a837..55c7bd1e9a09 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 @@ -639,6 +639,16 @@ class FlutterIntegrationCoreApi { 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]) { 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) 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 1d6005f7a837..55c7bd1e9a09 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 @@ -639,6 +639,16 @@ class FlutterIntegrationCoreApi { 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]) { 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) 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 5f79079c8983..7287c18e5d28 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 @@ -1514,6 +1514,34 @@ void FlutterIntegrationCoreApi::echoAllNullableTypes( callback(output); }); } +void FlutterIntegrationCoreApi::sendMultipleNullableTypes( + std::optional a_nullable_bool_arg, + std::optional a_nullable_int_arg, + std::optional a_nullable_string_arg, + std::function&& callback) { + auto channel = std::make_unique< + flutter::BasicMessageChannel>( + binary_messenger_, + "dev.flutter.pigeon.FlutterIntegrationCoreApi.sendMultipleNullableTypes", + &GetCodec()); + channel->Send( + flutter::EncodableList{ + flutter::CustomEncodableValue(a_nullable_bool_arg), + flutter::CustomEncodableValue(a_nullable_int_arg), + flutter::CustomEncodableValue(a_nullable_string_arg)}, + [callback](const uint8_t* reply, size_t reply_size) { + std::unique_ptr decoded_reply = + 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); + }); +} void FlutterIntegrationCoreApi::echoBool(bool a_bool_arg, std::function&& callback) { auto channel = 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 cb7c79f2b68f..801b7a949fac 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 @@ -383,6 +383,14 @@ class FlutterIntegrationCoreApi { void echoAllNullableTypes( const AllNullableTypes& everything_arg, std::function&& callback); + // Returns passed in arguments of multiple types. + // + // Tests multiple-arity FlutterApi handling. + void sendMultipleNullableTypes( + std::optional a_nullable_bool_arg, + std::optional a_nullable_int_arg, + std::optional a_nullable_string_arg, + std::function&& callback); // Returns the passed boolean, to test serialization and deserialization. void echoBool(bool a_bool_arg, std::function&& callback); // Returns the passed int, to test serialization and deserialization. From e64f12adfca560ce2c27116181259fb5e95aa730 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Dec 2022 09:55:18 -0500 Subject: [PATCH 04/25] Add Dart unit tests for desired output format --- packages/pigeon/test/cpp_generator_test.dart | 216 +++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index d8e991700a01..cc3dd3839db4 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1018,6 +1018,222 @@ 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, + )), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ]) + ], classes: [ + Class(name: 'ParameterObject', fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), + name: 'aValue'), + ]), + ], enums: []); + { + final StringBuffer sink = StringBuffer(); + generateCppHeader('', const CppOptions(), 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)')); + } + { + final StringBuffer sink = StringBuffer(); + generateCppSource(const CppOptions(), 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( + 'encodable_a_bool_arg ? flutter::EncodableValue(*encodable_a_bool_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'encodable_an_int_arg ? flutter::EncodableValue(*encodable_an_int_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'encodable_a_string_arg ? flutter::EncodableValue(*encodable_a_string_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'encodable_a_list_arg ? flutter::EncodableValue(*encodable_a_list_arg) : flutter::EncodableValue()')); + expect( + code, + contains( + 'encodable_a_map_arg ? flutter::EncodableValue(*encodable_a_map_arg) : flutter::EncodableValue()')); + // Class types use CustomEncodableValue. + expect( + code, + contains( + 'encodable_an_object_arg ? flutter::CustomEncodableValue(*encodable_an_object_arg) : 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, + )), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ]) + ], classes: [ + Class(name: 'ParameterObject', fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), + name: 'aValue'), + ]), + ], enums: []); + { + final StringBuffer sink = StringBuffer(); + generateCppHeader('', const CppOptions(), root, sink); + final String code = sink.toString(); + expect( + code, + contains('DoSomething(bool a_bool, ' + 'int64_t an_int, ' + // Non-nullable strings use string_view for flexibility. + 'std::string_view a_string, ' + // Non-POD types use const references. + 'const flutter::EncodableList& a_list, ' + 'const flutter::EncodableMap& a_map, ' + 'const ParameterObject& an_object)')); + } + { + final StringBuffer sink = StringBuffer(); + generateCppSource(const CppOptions(), root, sink); + final String code = sink.toString(); + // Standard types are wrapped an EncodableValues. + expect(code, contains('flutter::EncodableValue(*encodable_a_bool_arg)')); + expect(code, contains('flutter::EncodableValue(*encodable_an_int_arg)')); + expect( + code, contains('flutter::EncodableValue(*encodable_a_string_arg)')); + expect(code, contains('flutter::EncodableValue(*encodable_a_list_arg)')); + expect(code, contains('flutter::EncodableValue(*encodable_a_map_arg)')); + // Class types use CustomEncodableValue. + expect( + code, + contains( + 'const auto& an_object_arg = std::any_cast(std::get(encodable_an_object_arg));')); + } + }); + test('host API argument extraction uses references', () { final Root root = Root(apis: [ Api(name: 'Api', location: ApiLocation.host, methods: [ From 644f5c8f12dca0d4ba7f36c3b5540a658bf07264 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Dec 2022 09:57:09 -0500 Subject: [PATCH 05/25] Enable the existing integration test --- .../shared_test_plugin_code/lib/integration_tests.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 adff0186a9b8..1f065859b1b8 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 { From 728804797f8f976732d96bbe7a261068a7461627 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 21 Dec 2022 09:21:22 -0500 Subject: [PATCH 06/25] Add units tests for callback format --- packages/pigeon/test/cpp_generator_test.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index cc3dd3839db4..02517a5409ea 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1068,7 +1068,10 @@ void main() { isNullable: true, )), ], - returnType: const TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration( + baseName: 'bool', + isNullable: true, + ), ), ]) ], classes: [ @@ -1101,7 +1104,9 @@ void main() { 'const std::string* a_string, ' 'const flutter::EncodableList* a_list, ' 'const flutter::EncodableMap* a_map, ' - 'const ParameterObject* an_object)')); + 'const ParameterObject* an_object,')); + // The callback should pass a pointer as well. + expect(code, contains('std::function&& callback)')); } { final StringBuffer sink = StringBuffer(); @@ -1187,7 +1192,10 @@ void main() { isNullable: false, )), ], - returnType: const TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration( + baseName: 'bool', + isNullable: false, + ), ), ]) ], classes: [ @@ -1213,7 +1221,9 @@ void main() { // Non-POD types use const references. 'const flutter::EncodableList& a_list, ' 'const flutter::EncodableMap& a_map, ' - 'const ParameterObject& an_object)')); + 'const ParameterObject& an_object,')); + // The callback should pass a value. + expect(code, contains('std::function&& callback)')); } { final StringBuffer sink = StringBuffer(); From e5cf1e52aa50af375bc9f317ea41eb98e03a1992 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 21 Dec 2022 14:23:43 -0500 Subject: [PATCH 07/25] Adjust unit test expectations for error callback --- packages/pigeon/test/cpp_generator_test.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 02517a5409ea..12483d1cd799 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1106,7 +1106,10 @@ void main() { 'const flutter::EncodableMap* a_map, ' 'const ParameterObject* an_object,')); // The callback should pass a pointer as well. - expect(code, contains('std::function&& callback)')); + expect( + code, + contains('std::function&& callback, ' + 'std::function&& error_handler)')); } { final StringBuffer sink = StringBuffer(); @@ -1223,7 +1226,10 @@ void main() { 'const flutter::EncodableMap& a_map, ' 'const ParameterObject& an_object,')); // The callback should pass a value. - expect(code, contains('std::function&& callback)')); + expect( + code, + contains('std::function&& callback, ' + 'std::function&& error_handler)')); } { final StringBuffer sink = StringBuffer(); From cdad4966eed6c06c166410875debe79038ac52b0 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 19:43:24 -0500 Subject: [PATCH 08/25] First-pass implementation; mostly untested --- packages/pigeon/lib/cpp_generator.dart | 380 ++++---- .../windows/pigeon/core_tests.gen.cpp | 870 +++++++++--------- .../windows/pigeon/core_tests.gen.h | 99 +- packages/pigeon/test/cpp_generator_test.dart | 59 +- 4 files changed, 730 insertions(+), 678 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index ae5f91224ae8..b7eede6e61b7 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -353,30 +353,8 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String instanceVariable = _makeInstanceVariableName(field); - - String encodableValue = ''; - if (!hostDatatype.isBuiltin && - rootClassNameSet.contains(field.type.baseName)) { - final String operator = field.type.isNullable ? '->' : '.'; - encodableValue = - 'flutter::EncodableValue($instanceVariable${operator}ToEncodableList())'; - } else if (!hostDatatype.isBuiltin && - rootEnumNameSet.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()'; - } - + final String encodableValue = _wrappedHostApiArgumentExpression( + root, _makeInstanceVariableName(field), field.type, hostDatatype); indent.writeln('$encodableValue,'); } }); @@ -437,6 +415,88 @@ else if (const int64_t* ${pointerFieldName}_64 = std::get_if(&$encodabl indent.addln(''); } +/// 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::CustomEncodableValue($operator$variableName)'; + } 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 called [argName] to use +// as a parameter to an API method call from an existing EncodableValue +// variable called [encodableArgName] which corresponds to [arg] in the API +// definition. +void _writeEncodedArgumentExtraction( + 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));'); + } + } +} + void _writeHostApiHeader(Indent indent, Api api, Root root) { assert(api.location == ApiLocation.host); @@ -457,7 +517,7 @@ void _writeHostApiHeader(Indent indent, Api api, Root root) { root.classes, root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String returnTypeName = _apiReturnType(returnType); + final String returnTypeName = _hostApiReturnType(returnType); final List argSignature = []; if (method.arguments.isNotEmpty) { @@ -530,12 +590,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( @@ -548,68 +604,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, @@ -630,8 +624,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.writeln('return;'); }); } - extractEncodedArgument( - argName, encodableArgName, arg, hostType); + _writeEncodedArgumentExtraction(indent, hostType, + argName: argName, encodableArgName: encodableArgName); methodArgument.add(argName); }); } @@ -693,7 +687,7 @@ ${prefix}reply(flutter::EncodableValue(std::move(wrapped)));'''; root.classes, root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String returnTypeName = _apiReturnType(returnType); + final String returnTypeName = _hostApiReturnType(returnType); if (method.isAsynchronous) { methodArgument.add( '[reply]($returnTypeName&& output) {${indent.newline}' @@ -739,7 +733,7 @@ String _getArgumentName(int count, NamedType argument) => String _getSafeArgumentName(int count, NamedType argument) => '${_getArgumentName(count, argument)}_arg'; -void _writeFlutterApiHeader(Indent indent, Api api) { +void _writeFlutterApiHeader(Indent indent, Api api, Root root) { assert(api.location == ApiLocation.flutter); const List generatedMessages = [ @@ -757,29 +751,54 @@ void _writeFlutterApiHeader(Indent indent, Api api) { indent.writeln(''); 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, + (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final String successCallback = + 'std::function&& on_success'; + const String errorCallback = + 'std::function&& on_error'; addDocumentationComments( indent, func.documentationComments, _docCommentSpec); if (func.arguments.isEmpty) { - indent.writeln('void ${func.name}($callback);'); + indent.writeln('void ${_makeMethodName(func)}($successCallback, ' + '$errorCallback);'); } else { - final Iterable argTypes = func.arguments - .map((NamedType e) => _nullSafeCppTypeForDartType(e.type)); + final Iterable argTypes = func.arguments.map((NamedType arg) { + final HostDatatype hostType = getFieldHostDatatype( + arg, + root.classes, + root.enums, + (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + return _flutterApiArgumentType(hostType); + }); final Iterable argNames = - indexMap(func.arguments, _getSafeArgumentName); + indexMap(func.arguments, _getArgumentName); final String argsSignature = map2(argTypes, argNames, (String x, String y) => '$x $y') .join(', '); - indent.writeln('void ${func.name}($argsSignature, $callback);'); + indent.writeln('void ${_makeMethodName(func)}($argsSignature, ' + '$successCallback, $errorCallback);'); } } }); }, nestCount: 0); } +/// 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; +} + void _writeFlutterApiSource(Indent indent, Api api, Root root) { assert(api.location == ApiLocation.flutter); indent.writeln( @@ -800,79 +819,70 @@ 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); + final HostDatatype returnType = getHostDatatype( + func.returnType, + root.classes, + root.enums, + (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); 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 String successCallback = + 'std::function&& on_success'; + const String errorCallback = + 'std::function&& on_error'; + + // Determine the input argument list, saved in a structured form for later + // use as platform channel call arguments. + final Iterable<_HostNamedType> hostArgs = + indexMap(func.arguments, (int i, NamedType arg) { + final HostDatatype hostType = getFieldHostDatatype(arg, root.classes, + root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); + }); + final String inputArgumentList = hostArgs + .map((_HostNamedType arg) => '${arg.hostType} ${arg.name}') + .join(', '); + indent.write('void ${api.name}::${_makeMethodName(func)}(' + '${inputArgumentList.isEmpty ? '' : '$inputArgumentList, '}' + '$successCallback, $errorCallback) '); 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(); + '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.writeln('flutter::EncodableValue()'); + } else { + indent.scoped('flutter::EncodableValue(flutter::EncodableList{', '});', + () { + for (_HostNamedType arg in hostArgs) { + final String encodedArgument = _wrappedHostApiArgumentExpression( + root, arg.name, arg.originalType, arg.hostType); + indent.writeln('$encodedArgument,'); + } + }); + } + indent.write( - '$channel->Send($sendArgument, [callback](const uint8_t* reply, size_t reply_size) '); + '$channel->Send($argumentListVariableName, [on_success, 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;'); + _writeEncodedArgumentExtraction(indent, returnType, + argName: successCallbackArgument, + encodableArgName: encodedReplyName); } + indent.writeln('on_success($successCallbackArgument);'); }); }); } @@ -990,6 +1000,16 @@ 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 pointer types. + if (type.datatype == 'std::string' && type.isNullable) { + return '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) { @@ -1003,9 +1023,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'; } @@ -1016,6 +1036,18 @@ String _apiReturnType(HostDatatype type) { return 'ErrorOr<$valueType>'; } +/// 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); +} + // 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, @@ -1133,7 +1165,7 @@ void generateCppHeader(CppOptions options, Root root, StringSink sink) { if (api.location == ApiLocation.host) { _writeHostApiHeader(indent, api, root); } else if (api.location == ApiLocation.flutter) { - _writeFlutterApiHeader(indent, api); + _writeFlutterApiHeader(indent, api, root); } } @@ -1196,14 +1228,14 @@ flutter::EncodableValue ${api.name}::WrapError(std::string_view error_message) { \t\tflutter::EncodableValue(std::string(error_message)), \t\tflutter::EncodableValue("Error"), \t\tflutter::EncodableValue() -\t}); +\t}; } flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) { \treturn flutter::EncodableValue(flutter::EncodableList{ \t\tflutter::EncodableValue(error.message()), \t\tflutter::EncodableValue(error.code()), \t\terror.details() -\t}); +\t}; }'''); indent.addln(''); } else if (api.location == ApiLocation.flutter) { 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 7287c18e5d28..d42979dfe9d9 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 @@ -465,7 +465,7 @@ void AllNullableTypesWrapper::set_values(const AllNullableTypes& value_arg) { flutter::EncodableList AllNullableTypesWrapper::ToEncodableList() const { return flutter::EncodableList{ - flutter::EncodableValue(values_.ToEncodableList()), + flutter::CustomEncodableValue(values_), }; } @@ -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, @@ -1382,14 +1353,18 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, flutter::EncodableValue HostIntegrationCoreApi::WrapError( std::string_view error_message) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(std::string(error_message)), - flutter::EncodableValue("Error"), flutter::EncodableValue()}); + flutter::EncodableValue(std::string(error_message)), + flutter::EncodableValue("Error"), + flutter::EncodableValue() + }; } flutter::EncodableValue HostIntegrationCoreApi::WrapError( const FlutterError& error) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(error.message()), - flutter::EncodableValue(error.code()), error.details()}); + flutter::EncodableValue(error.message()), + flutter::EncodableValue(error.code()), + error.details() + }; } FlutterIntegrationCoreApiCodecSerializer:: @@ -1459,398 +1434,414 @@ 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()); - channel->Send( - flutter::EncodableValue(), - [callback](const uint8_t* reply, size_t reply_size) { callback(); }); -} -void FlutterIntegrationCoreApi::echoAllTypes( - const AllTypes& everything_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", - &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( + encoded_api_arguments, + [on_success, on_error](const uint8_t* reply, size_t reply_size) { + on_success(); + }); +} +void FlutterIntegrationCoreApi::EchoAllTypes( + Instance of 'HostDatatype' everything_arg, + 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::CustomEncodableValue(everything_arg), + }); 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, 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( - const AllNullableTypes& everything_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoAllNullableTypes( + Instance of 'HostDatatype' everything_arg, + 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::CustomEncodableValue(everything_arg), + }); 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, 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::sendMultipleNullableTypes( - std::optional a_nullable_bool_arg, - std::optional a_nullable_int_arg, - std::optional a_nullable_string_arg, - std::function&& callback) { - auto channel = std::make_unique< - flutter::BasicMessageChannel>( +void FlutterIntegrationCoreApi::SendMultipleNullableTypes( + Instance of 'HostDatatype' a_nullable_bool_arg, + Instance of 'HostDatatype' a_nullable_int_arg, + Instance of 'HostDatatype' 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_nullable_bool_arg), - flutter::CustomEncodableValue(a_nullable_int_arg), - flutter::CustomEncodableValue(a_nullable_string_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::echoBool(bool a_bool_arg, - std::function&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", &GetCodec()); +void FlutterIntegrationCoreApi::EchoBool( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_bool_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - bool output{}; - if (const bool* pointer_output = std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoInt", &GetCodec()); +void FlutterIntegrationCoreApi::EchoInt( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(an_int_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - int64_t output{}; - if (const int32_t* pointer_output = std::get_if(&args)) - output = *pointer_output; - else if (const int64_t* pointer_output_64 = std::get_if(&args)) - output = *pointer_output_64; - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoDouble( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_double_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - double output{}; - if (const double* pointer_output = std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoString", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoString( + Instance of 'HostDatatype' 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( - 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, 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::get(encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoUint8List( - const std::vector& a_list_arg, - std::function&)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoUint8List( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::vector output{}; - if (const std::vector* pointer_output = - std::get_if>(&args)) { - output = *pointer_output; - } - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoList", &GetCodec()); +void FlutterIntegrationCoreApi::EchoList( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - flutter::EncodableList output{}; - if (const flutter::EncodableList* pointer_output = - std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", &GetCodec()); +void FlutterIntegrationCoreApi::EchoMap( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_map_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - flutter::EncodableMap output{}; - if (const flutter::EncodableMap* pointer_output = - std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoNullableBool( - std::optional a_bool_arg, - std::function)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableBool", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableBool( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_bool_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::optional output{}; - if (const bool* pointer_output = std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto* return_value = std::get_if(&encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoNullableInt( - std::optional an_int_arg, - std::function)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableInt( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(an_int_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::optional output{}; - if (const int32_t* pointer_output = std::get_if(&args)) - output = *pointer_output; - else if (const int64_t* pointer_output_64 = std::get_if(&args)) - output = *pointer_output_64; - callback(output); + 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( - std::optional a_double_arg, - std::function)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableDouble", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableDouble( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_double_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::optional output{}; - if (const double* pointer_output = std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto* return_value = std::get_if(&encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoNullableString( - std::optional a_string_arg, - std::function)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableString( + Instance of 'HostDatatype' 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( - 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, 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::optional 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::get_if(&encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoNullableUint8List( - std::optional> a_list_arg, - std::function>)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableUint8List", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableUint8List( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::optional> output{}; - if (const std::vector* pointer_output = - std::get_if>(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto* return_value = + std::get_if>(&encodable_return_value); + on_success(return_value); }); } -void FlutterIntegrationCoreApi::echoNullableList( - std::optional a_list_arg, - std::function)>&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableList( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_list_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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::optional output{}; - if (const flutter::EncodableList* pointer_output = - std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + 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&& callback) { - auto channel = - std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableMap", - &GetCodec()); +void FlutterIntegrationCoreApi::EchoNullableMap( + Instance of 'HostDatatype' 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( - flutter::EncodableList{flutter::CustomEncodableValue(a_map_arg)}, - [callback](const uint8_t* reply, size_t reply_size) { - std::unique_ptr decoded_reply = + encoded_api_arguments, + [on_success, 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()); - flutter::EncodableMap output{}; - if (const flutter::EncodableMap* pointer_output = - std::get_if(&args)) { - output = *pointer_output; - } - callback(output); + const auto& encodable_return_value = *response; + const auto& return_value = + std::get(encodable_return_value); + on_success(return_value); }); } /// The codec used by HostTrivialApi. @@ -1864,10 +1855,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, @@ -1894,13 +1884,17 @@ void HostTrivialApi::SetUp(flutter::BinaryMessenger* binary_messenger, flutter::EncodableValue HostTrivialApi::WrapError( std::string_view error_message) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(std::string(error_message)), - flutter::EncodableValue("Error"), flutter::EncodableValue()}); + flutter::EncodableValue(std::string(error_message)), + flutter::EncodableValue("Error"), + flutter::EncodableValue() + }; } flutter::EncodableValue HostTrivialApi::WrapError(const FlutterError& error) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(error.message()), - flutter::EncodableValue(error.code()), error.details()}); + flutter::EncodableValue(error.message()), + flutter::EncodableValue(error.code()), + error.details() + }; } } // namespace core_tests_pigeontest 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 801b7a949fac..1542800cf5e9 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 @@ -375,67 +375,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( - std::optional a_nullable_bool_arg, - std::optional a_nullable_int_arg, - std::optional a_nullable_string_arg, - std::function&& callback); + 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_arg, std::function&& callback); + 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_arg, std::function&& callback); + 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_arg, std::function&& callback); + 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(std::string_view 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_arg, - std::function&)>&& callback); + 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_arg, - std::function&& callback); + 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_arg, - std::function&& callback); + 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(std::optional a_bool_arg, - std::function)>&& callback); + 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(std::optional an_int_arg, - std::function)>&& callback); + 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( - std::optional a_double_arg, - std::function)>&& callback); + 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( - std::optional a_string_arg, - std::function)>&& callback); + 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( - std::optional> a_list_arg, - std::function>)>&& callback); + 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( - std::optional a_list_arg, - std::function)>&& callback); + 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_arg, - std::function&& callback); + 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. diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 12483d1cd799..e2f8560205ff 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -463,7 +463,7 @@ void main() { expect( code, contains( - 'nullable_nested_ ? flutter::EncodableValue(nullable_nested_->ToEncodableList()) ' + 'nullable_nested_ ? flutter::CustomEncodableValue(*nullable_nested_) ' ': flutter::EncodableValue()')); } }); @@ -561,7 +561,8 @@ void main() { expect(code, contains('non_nullable_nested_ = value_arg;')); // Serialization uses the value directly. expect(code, contains('flutter::EncodableValue(non_nullable_bool_)')); - expect(code, contains('non_nullable_nested_.ToEncodableList()')); + expect(code, + contains('flutter::CustomEncodableValue(non_nullable_nested_)')); } }); @@ -1067,6 +1068,12 @@ void main() { baseName: 'ParameterObject', isNullable: true, )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: true, + )), ], returnType: const TypeDeclaration( baseName: 'bool', @@ -1104,12 +1111,13 @@ void main() { 'const std::string* a_string, ' 'const flutter::EncodableList* a_list, ' 'const flutter::EncodableMap* a_map, ' - 'const ParameterObject* an_object,')); + 'const ParameterObject* an_object, ' + 'const flutter::EncodableValue* a_generic_object, ')); // The callback should pass a pointer as well. expect( code, - contains('std::function&& callback, ' - 'std::function&& error_handler)')); + contains('std::function&& on_success, ' + 'std::function&& on_error)')); } { final StringBuffer sink = StringBuffer(); @@ -1120,28 +1128,28 @@ void main() { expect( code, contains( - 'encodable_a_bool_arg ? flutter::EncodableValue(*encodable_a_bool_arg) : flutter::EncodableValue()')); + 'a_bool_arg ? flutter::EncodableValue(*a_bool_arg) : flutter::EncodableValue()')); expect( code, contains( - 'encodable_an_int_arg ? flutter::EncodableValue(*encodable_an_int_arg) : flutter::EncodableValue()')); + 'an_int_arg ? flutter::EncodableValue(*an_int_arg) : flutter::EncodableValue()')); expect( code, contains( - 'encodable_a_string_arg ? flutter::EncodableValue(*encodable_a_string_arg) : flutter::EncodableValue()')); + 'a_string_arg ? flutter::EncodableValue(*a_string_arg) : flutter::EncodableValue()')); expect( code, contains( - 'encodable_a_list_arg ? flutter::EncodableValue(*encodable_a_list_arg) : flutter::EncodableValue()')); + 'a_list_arg ? flutter::EncodableValue(*a_list_arg) : flutter::EncodableValue()')); expect( code, contains( - 'encodable_a_map_arg ? flutter::EncodableValue(*encodable_a_map_arg) : flutter::EncodableValue()')); + 'a_map_arg ? flutter::EncodableValue(*a_map_arg) : flutter::EncodableValue()')); // Class types use CustomEncodableValue. expect( code, contains( - 'encodable_an_object_arg ? flutter::CustomEncodableValue(*encodable_an_object_arg) : flutter::EncodableValue()')); + 'an_object_arg ? flutter::CustomEncodableValue(*an_object_arg) : flutter::EncodableValue()')); } }); @@ -1194,6 +1202,12 @@ void main() { baseName: 'ParameterObject', isNullable: false, )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: false, + )), ], returnType: const TypeDeclaration( baseName: 'bool', @@ -1224,29 +1238,26 @@ void main() { // Non-POD types use const references. 'const flutter::EncodableList& a_list, ' 'const flutter::EncodableMap& a_map, ' - 'const ParameterObject& an_object,')); + 'const ParameterObject& an_object, ' + 'const flutter::EncodableValue& a_generic_object, ')); // The callback should pass a value. expect( code, - contains('std::function&& callback, ' - 'std::function&& error_handler)')); + contains('std::function&& on_success, ' + 'std::function&& on_error)')); } { final StringBuffer sink = StringBuffer(); generateCppSource(const CppOptions(), root, sink); final String code = sink.toString(); // Standard types are wrapped an EncodableValues. - expect(code, contains('flutter::EncodableValue(*encodable_a_bool_arg)')); - expect(code, contains('flutter::EncodableValue(*encodable_an_int_arg)')); - expect( - code, contains('flutter::EncodableValue(*encodable_a_string_arg)')); - expect(code, contains('flutter::EncodableValue(*encodable_a_list_arg)')); - expect(code, contains('flutter::EncodableValue(*encodable_a_map_arg)')); + 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 CustomEncodableValue. - expect( - code, - contains( - 'const auto& an_object_arg = std::any_cast(std::get(encodable_an_object_arg));')); + expect(code, contains('flutter::CustomEncodableValue(an_object_arg)')); } }); From de9af5edebd2673687bc6acdb81cc66dbcc3ee56 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 11:29:24 -0500 Subject: [PATCH 09/25] Comment fix --- packages/pigeon/pigeons/core_tests.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 14efa90304a3..2468e789e007 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -191,9 +191,9 @@ 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. } From 3c3a5bbd15f18c29dc6bca631a8fe98acffed09d Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 11:35:27 -0500 Subject: [PATCH 10/25] Add todo --- packages/pigeon/pigeons/core_tests.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 2468e789e007..7af39eb72603 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -195,6 +195,8 @@ abstract class HostIntegrationCoreApi { // 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 From c60cabdb907f6a0d508d4e908c2b1df5fbca56dc Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 11:44:44 -0500 Subject: [PATCH 11/25] Minor fixes --- packages/pigeon/lib/cpp_generator.dart | 32 ++------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index b7eede6e61b7..2386f771f866 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -295,8 +295,6 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, /// See [_writeDataClassDeclaration] for the corresponding declaration. /// This is intended to be added to the implementation file. void _writeDataClassImplementation(Indent indent, Class klass, Root root) { - final Set rootClassNameSet = - root.classes.map((Class x) => x.name).toSet(); final Set rootEnumNameSet = root.enums.map((Enum x) => x.name).toSet(); @@ -824,7 +822,6 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { root.classes, root.enums, (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - String sendArgument; final String successCallback = 'std::function&& on_success'; const String errorCallback = @@ -839,7 +836,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); }); final String inputArgumentList = hostArgs - .map((_HostNamedType arg) => '${arg.hostType} ${arg.name}') + .map((_HostNamedType arg) => '${arg.hostType.datatype} ${arg.name}') .join(', '); indent.write('void ${api.name}::${_makeMethodName(func)}(' '${inputArgumentList.isEmpty ? '' : '$inputArgumentList, '}' @@ -858,7 +855,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { } else { indent.scoped('flutter::EncodableValue(flutter::EncodableList{', '});', () { - for (_HostNamedType arg in hostArgs) { + for (final _HostNamedType arg in hostArgs) { final String encodedArgument = _wrappedHostApiArgumentExpression( root, arg.name, arg.originalType, arg.hostType); indent.writeln('$encodedArgument,'); @@ -962,12 +959,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) { @@ -1048,25 +1039,6 @@ String _flutterApiReturnType(HostDatatype type) { return _hostApiArgumentType(type); } -// 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; - } -} - String _getGuardName(String? headerFileName, String? namespace) { String guardName = 'PIGEON_'; if (headerFileName != null) { From fbbb6677e631e07d6909ea07d601757081191faa Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 12:19:33 -0500 Subject: [PATCH 12/25] Fix compilation error in Swift from new pigeons --- packages/pigeon/lib/swift_generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 77fff7e2fac3..4f89e7e7087a 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -338,7 +338,7 @@ void _writeFlutterApi(Indent indent, Api api, Root root) { 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, From 04d6191421856db7a603c7825019bf108601ac76 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 12:20:07 -0500 Subject: [PATCH 13/25] Make new Maps string-keyed to avoid Swift error --- packages/pigeon/pigeons/core_tests.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 7af39eb72603..1699b0f49df5 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -250,7 +250,7 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoMap:') - Map echoMap(Map aMap); + Map echoMap(Map aMap); // ========== Nullable argument/return type tests ========== @@ -280,7 +280,7 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoNullableMap:') - Map echoNullableMap(Map aMap); + Map echoNullableMap(Map aMap); } /// An API that can be implemented for minimal, compile-only tests. From abfba12ad4e370843b1d5d5bf4793288c708cff2 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 12:20:55 -0500 Subject: [PATCH 14/25] Update generation --- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- .../CoreTests.java | 8 +- .../ios/Classes/CoreTests.gen.h | 9 +- .../ios/Classes/CoreTests.gen.m | 13 +- .../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 | 4 +- .../lib/src/generated/core_tests.gen.dart | 20 +- .../com/example/test_plugin/CoreTests.gen.kt | 8 +- .../ios/Classes/CoreTests.gen.swift | 42 +-- .../macos/Classes/CoreTests.gen.swift | 42 +-- .../windows/pigeon/core_tests.gen.cpp | 44 +-- 18 files changed, 418 insertions(+), 108 deletions(-) diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 4f6c9d14457c..00ecc407416b 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 9b97826b605d..e1644f13686c 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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/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 fd504177af38..188b2a02e140 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 @@ -1710,7 +1710,7 @@ public void echoList(@NonNull List aListArg, Reply> callbac }); } /** Returns the passed map, to test serialization and deserialization. */ - public void echoMap(@NonNull Map aMapArg, Reply> callback) { + public void echoMap(@NonNull Map aMapArg, Reply> callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", getCodec()); @@ -1718,7 +1718,7 @@ public void echoMap(@NonNull Map aMapArg, Reply(Collections.singletonList(aMapArg)), channelReply -> { @SuppressWarnings("ConstantConditions") - Map output = (Map) channelReply; + Map output = (Map) channelReply; callback.reply(output); }); } @@ -1814,7 +1814,7 @@ public void echoNullableList(@Nullable List aListArg, Reply } /** Returns the passed map, to test serialization and deserialization. */ public void echoNullableMap( - @NonNull Map aMapArg, Reply> callback) { + @NonNull Map aMapArg, Reply> callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, @@ -1824,7 +1824,7 @@ public void echoNullableMap( new ArrayList(Collections.singletonList(aMapArg)), channelReply -> { @SuppressWarnings("ConstantConditions") - Map output = (Map) channelReply; + Map output = (Map) channelReply; callback.reply(output); }); } 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 b58106bbc184..407fba80c041 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 @@ -230,8 +230,8 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (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; +- (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; @@ -252,8 +252,9 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (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; +- (void)echoNullableMap:(NSDictionary *)aMap + completion: + (void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion; @end /// The codec used by HostTrivialApi. NSObject *HostTrivialApiGetCodec(void); 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 8cc9b52e955e..2a09f6edd865 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 @@ -979,15 +979,15 @@ - (void)echoList:(NSArray *)arg_aList completion(output, nil); }]; } -- (void)echoMap:(NSDictionary *)arg_aMap - completion:(void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion { +- (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; + NSDictionary *output = reply; completion(output, nil); }]; } @@ -1064,15 +1064,16 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList completion(output, nil); }]; } -- (void)echoNullableMap:(NSDictionary *)arg_aMap - completion:(void (^)(NSDictionary *_Nullable, NSError *_Nullable))completion { +- (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; + NSDictionary *output = reply; completion(output, nil); }]; } 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 fe0fe3335eaa..2c18e5613a2a 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; @@ -847,9 +847,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); } @@ -862,6 +865,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: @@ -885,9 +891,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}) { { @@ -945,6 +996,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, @@ -964,6 +1093,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 e92ab29cebda..9600a969cdf1 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 1ff71bfa346c..a73dbb8ceed0 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 88f4611e7466..1683e856567e 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 13fe926bcf1a..83f20830fc0b 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 be1979c8adfa..c5e1738c53d6 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 36a569e4f46f..8ca3c619f342 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 (v5.0.0), do not edit directly. +// Autogenerated from Pigeon (v5.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 import 'dart:async'; 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 1f065859b1b8..a47622b3c5dc 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 @@ -572,7 +572,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { List echoList(List aList) => aList; @override - Map echoMap(Map aMap) => aMap; + Map echoMap(Map aMap) => aMap; @override bool? echoNullableBool(bool? aBool) => aBool; @@ -587,7 +587,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { List? echoNullableList(List? aList) => aList; @override - Map echoNullableMap(Map aMap) => aMap; + Map echoNullableMap(Map aMap) => aMap; @override String? echoNullableString(String? aString) => aString; 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 9f7cc8e8d0e9..2c18e5613a2a 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 @@ -916,7 +916,7 @@ abstract class FlutterIntegrationCoreApi { List echoList(List aList); /// Returns the passed map, to test serialization and deserialization. - Map echoMap(Map aMap); + Map echoMap(Map aMap); /// Returns the passed boolean, to test serialization and deserialization. bool? echoNullableBool(bool? aBool); @@ -937,7 +937,7 @@ abstract class FlutterIntegrationCoreApi { List? echoNullableList(List? aList); /// Returns the passed map, to test serialization and deserialization. - Map echoNullableMap(Map aMap); + Map echoNullableMap(Map aMap); static void setup(FlutterIntegrationCoreApi? api, {BinaryMessenger? binaryMessenger}) { @@ -1143,11 +1143,11 @@ abstract class FlutterIntegrationCoreApi { 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(); + 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!); + 'Argument for dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap was null, expected non-null Map.'); + final Map output = api.echoMap(arg_aMap!); return output; }); } @@ -1271,11 +1271,11 @@ abstract class FlutterIntegrationCoreApi { 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(); + 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!); + '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 c818a44fa439..c80b571177d2 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 @@ -835,10 +835,10 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { } } /** Returns the passed map, to test serialization and deserialization. */ - fun echoMap(aMapArg: Map, callback: (Map) -> Unit) { + 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 + val result = it as Map callback(result) } } @@ -891,10 +891,10 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { } } /** Returns the passed map, to test serialization and deserialization. */ - fun echoNullableMap(aMapArg: Map, callback: (Map) -> Unit) { + 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 + val result = it as Map callback(result) } } 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 55c7bd1e9a09..7a18e70928ed 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 @@ -626,7 +626,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) } @@ -634,7 +634,7 @@ 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) } @@ -644,7 +644,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in let result = response as! AllNullableTypes completion(result) } @@ -652,7 +652,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aBoolArg] as [Any?]) { response in let result = response as! Bool completion(result) } @@ -660,7 +660,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([anIntArg] as [Any?]) { response in let result = response as! Int32 completion(result) } @@ -668,7 +668,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aDoubleArg] as [Any?]) { response in let result = response as! Double completion(result) } @@ -676,7 +676,7 @@ class FlutterIntegrationCoreApi { /// 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) } @@ -684,7 +684,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aListArg] as [Any?]) { response in let result = response as! FlutterStandardTypedData completion(result) } @@ -692,23 +692,23 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + 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: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + 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]) { response in - let result = response as! [Any?: Any?] + 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]) { response in + channel.sendMessage([aBoolArg] as [Any?]) { response in let result = response as? Bool completion(result) } @@ -716,7 +716,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([anIntArg] as [Any?]) { response in let result = response as? Int32 completion(result) } @@ -724,7 +724,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aDoubleArg] as [Any?]) { response in let result = response as? Double completion(result) } @@ -732,7 +732,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aStringArg] as [Any?]) { response in let result = response as? String completion(result) } @@ -740,7 +740,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aListArg] as [Any?]) { response in let result = response as? FlutterStandardTypedData completion(result) } @@ -748,16 +748,16 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + 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: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + 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]) { response in - let result = response as! [Any?: Any?] + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] completion(result) } } 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 55c7bd1e9a09..7a18e70928ed 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 @@ -626,7 +626,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) } @@ -634,7 +634,7 @@ 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) } @@ -644,7 +644,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in let result = response as! AllNullableTypes completion(result) } @@ -652,7 +652,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aBoolArg] as [Any?]) { response in let result = response as! Bool completion(result) } @@ -660,7 +660,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([anIntArg] as [Any?]) { response in let result = response as! Int32 completion(result) } @@ -668,7 +668,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aDoubleArg] as [Any?]) { response in let result = response as! Double completion(result) } @@ -676,7 +676,7 @@ class FlutterIntegrationCoreApi { /// 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) } @@ -684,7 +684,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aListArg] as [Any?]) { response in let result = response as! FlutterStandardTypedData completion(result) } @@ -692,23 +692,23 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + 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: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + 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]) { response in - let result = response as! [Any?: Any?] + 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]) { response in + channel.sendMessage([aBoolArg] as [Any?]) { response in let result = response as? Bool completion(result) } @@ -716,7 +716,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([anIntArg] as [Any?]) { response in let result = response as? Int32 completion(result) } @@ -724,7 +724,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aDoubleArg] as [Any?]) { response in let result = response as? Double completion(result) } @@ -732,7 +732,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aStringArg] as [Any?]) { response in let result = response as? String completion(result) } @@ -740,7 +740,7 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + channel.sendMessage([aListArg] as [Any?]) { response in let result = response as? FlutterStandardTypedData completion(result) } @@ -748,16 +748,16 @@ class FlutterIntegrationCoreApi { /// 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]) { response in + 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: [Any?: Any?], completion: @escaping ([Any?: Any?]) -> Void) { + 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]) { response in - let result = response as! [Any?: Any?] + channel.sendMessage([aMapArg] as [Any?]) { response in + let result = response as! [String?: Any?] completion(result) } } 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 d42979dfe9d9..43079cf9e1fd 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 @@ -1448,8 +1448,7 @@ void FlutterIntegrationCoreApi::Noop( }); } void FlutterIntegrationCoreApi::EchoAllTypes( - Instance of 'HostDatatype' everything_arg, - std::function&& on_success, + AllTypes everything_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1470,7 +1469,7 @@ void FlutterIntegrationCoreApi::EchoAllTypes( }); } void FlutterIntegrationCoreApi::EchoAllNullableTypes( - Instance of 'HostDatatype' everything_arg, + AllNullableTypes everything_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1493,9 +1492,8 @@ void FlutterIntegrationCoreApi::EchoAllNullableTypes( }); } void FlutterIntegrationCoreApi::SendMultipleNullableTypes( - Instance of 'HostDatatype' a_nullable_bool_arg, - Instance of 'HostDatatype' a_nullable_int_arg, - Instance of 'HostDatatype' a_nullable_string_arg, + bool a_nullable_bool_arg, int64_t a_nullable_int_arg, + std::string a_nullable_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1524,8 +1522,7 @@ void FlutterIntegrationCoreApi::SendMultipleNullableTypes( }); } void FlutterIntegrationCoreApi::EchoBool( - Instance of 'HostDatatype' a_bool_arg, - std::function&& on_success, + bool a_bool_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1545,8 +1542,7 @@ void FlutterIntegrationCoreApi::EchoBool( }); } void FlutterIntegrationCoreApi::EchoInt( - Instance of 'HostDatatype' an_int_arg, - std::function&& on_success, + 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", @@ -1566,8 +1562,7 @@ void FlutterIntegrationCoreApi::EchoInt( }); } void FlutterIntegrationCoreApi::EchoDouble( - Instance of 'HostDatatype' a_double_arg, - std::function&& on_success, + double a_double_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1587,7 +1582,7 @@ void FlutterIntegrationCoreApi::EchoDouble( }); } void FlutterIntegrationCoreApi::EchoString( - Instance of 'HostDatatype' a_string_arg, + std::string a_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1609,7 +1604,7 @@ void FlutterIntegrationCoreApi::EchoString( }); } void FlutterIntegrationCoreApi::EchoUint8List( - Instance of 'HostDatatype' a_list_arg, + std::vector a_list_arg, std::function&)>&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1632,7 +1627,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( }); } void FlutterIntegrationCoreApi::EchoList( - Instance of 'HostDatatype' a_list_arg, + flutter::EncodableList a_list_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1654,7 +1649,7 @@ void FlutterIntegrationCoreApi::EchoList( }); } void FlutterIntegrationCoreApi::EchoMap( - Instance of 'HostDatatype' a_map_arg, + flutter::EncodableMap a_map_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1676,8 +1671,7 @@ void FlutterIntegrationCoreApi::EchoMap( }); } void FlutterIntegrationCoreApi::EchoNullableBool( - Instance of 'HostDatatype' a_bool_arg, - std::function&& on_success, + bool a_bool_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1699,8 +1693,7 @@ void FlutterIntegrationCoreApi::EchoNullableBool( }); } void FlutterIntegrationCoreApi::EchoNullableInt( - Instance of 'HostDatatype' an_int_arg, - std::function&& on_success, + int64_t an_int_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1727,8 +1720,7 @@ void FlutterIntegrationCoreApi::EchoNullableInt( }); } void FlutterIntegrationCoreApi::EchoNullableDouble( - Instance of 'HostDatatype' a_double_arg, - std::function&& on_success, + double a_double_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1750,7 +1742,7 @@ void FlutterIntegrationCoreApi::EchoNullableDouble( }); } void FlutterIntegrationCoreApi::EchoNullableString( - Instance of 'HostDatatype' a_string_arg, + std::string a_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1774,7 +1766,7 @@ void FlutterIntegrationCoreApi::EchoNullableString( }); } void FlutterIntegrationCoreApi::EchoNullableUint8List( - Instance of 'HostDatatype' a_list_arg, + std::vector a_list_arg, std::function*)>&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1798,7 +1790,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( }); } void FlutterIntegrationCoreApi::EchoNullableList( - Instance of 'HostDatatype' a_list_arg, + flutter::EncodableList a_list_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1822,7 +1814,7 @@ void FlutterIntegrationCoreApi::EchoNullableList( }); } void FlutterIntegrationCoreApi::EchoNullableMap( - Instance of 'HostDatatype' a_map_arg, + flutter::EncodableMap a_map_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( From b056dd04648ffd1a1dfac2e7659f983fd2a315cf Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 12:25:17 -0500 Subject: [PATCH 15/25] Update unit test for change --- packages/pigeon/test/swift_generator_test.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 74c8aad15caf..ba6c20f57784 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -809,7 +809,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', () { From 8f8ea3d41e870f854f1ceb712914ca79b6b41807 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 13:08:40 -0500 Subject: [PATCH 16/25] Update C++ test plugin for API changes --- .../platform_tests/test_plugin/windows/test_plugin.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 8c35994b98f8..b5477b49dfda 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 From b4b804ca9cf27f8a2a5bac4933a6ccb28d932628 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 13:53:34 -0500 Subject: [PATCH 17/25] Fix type regression --- packages/pigeon/lib/cpp_generator.dart | 3 +- .../windows/pigeon/core_tests.gen.cpp | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 2386f771f866..a4a204026881 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -836,7 +836,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { return _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); }); final String inputArgumentList = hostArgs - .map((_HostNamedType arg) => '${arg.hostType.datatype} ${arg.name}') + .map((_HostNamedType arg) => + '${_flutterApiArgumentType(arg.hostType)} ${arg.name}') .join(', '); indent.write('void ${api.name}::${_makeMethodName(func)}(' '${inputArgumentList.isEmpty ? '' : '$inputArgumentList, '}' 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 43079cf9e1fd..b2d0321db3c4 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 @@ -1448,7 +1448,8 @@ void FlutterIntegrationCoreApi::Noop( }); } void FlutterIntegrationCoreApi::EchoAllTypes( - AllTypes everything_arg, std::function&& on_success, + const AllTypes& everything_arg, + std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1469,7 +1470,7 @@ void FlutterIntegrationCoreApi::EchoAllTypes( }); } void FlutterIntegrationCoreApi::EchoAllNullableTypes( - AllNullableTypes everything_arg, + const AllNullableTypes& everything_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1492,8 +1493,8 @@ void FlutterIntegrationCoreApi::EchoAllNullableTypes( }); } void FlutterIntegrationCoreApi::SendMultipleNullableTypes( - bool a_nullable_bool_arg, int64_t a_nullable_int_arg, - std::string a_nullable_string_arg, + 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>( @@ -1582,7 +1583,7 @@ void FlutterIntegrationCoreApi::EchoDouble( }); } void FlutterIntegrationCoreApi::EchoString( - std::string a_string_arg, + std::string_view a_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1604,7 +1605,7 @@ void FlutterIntegrationCoreApi::EchoString( }); } void FlutterIntegrationCoreApi::EchoUint8List( - std::vector a_list_arg, + const std::vector& a_list_arg, std::function&)>&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1627,7 +1628,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( }); } void FlutterIntegrationCoreApi::EchoList( - flutter::EncodableList a_list_arg, + const flutter::EncodableList& a_list_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1649,7 +1650,7 @@ void FlutterIntegrationCoreApi::EchoList( }); } void FlutterIntegrationCoreApi::EchoMap( - flutter::EncodableMap a_map_arg, + const flutter::EncodableMap& a_map_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1671,7 +1672,7 @@ void FlutterIntegrationCoreApi::EchoMap( }); } void FlutterIntegrationCoreApi::EchoNullableBool( - bool a_bool_arg, std::function&& on_success, + const bool* a_bool_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1693,7 +1694,7 @@ void FlutterIntegrationCoreApi::EchoNullableBool( }); } void FlutterIntegrationCoreApi::EchoNullableInt( - int64_t an_int_arg, std::function&& on_success, + const int64_t* an_int_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1720,7 +1721,7 @@ void FlutterIntegrationCoreApi::EchoNullableInt( }); } void FlutterIntegrationCoreApi::EchoNullableDouble( - double a_double_arg, std::function&& on_success, + const double* a_double_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( binary_messenger_, @@ -1742,7 +1743,7 @@ void FlutterIntegrationCoreApi::EchoNullableDouble( }); } void FlutterIntegrationCoreApi::EchoNullableString( - std::string a_string_arg, + const std::string* a_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1766,7 +1767,7 @@ void FlutterIntegrationCoreApi::EchoNullableString( }); } void FlutterIntegrationCoreApi::EchoNullableUint8List( - std::vector a_list_arg, + const std::vector* a_list_arg, std::function*)>&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1790,7 +1791,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( }); } void FlutterIntegrationCoreApi::EchoNullableList( - flutter::EncodableList a_list_arg, + const flutter::EncodableList* a_list_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( @@ -1814,7 +1815,7 @@ void FlutterIntegrationCoreApi::EchoNullableList( }); } void FlutterIntegrationCoreApi::EchoNullableMap( - flutter::EncodableMap a_map_arg, + const flutter::EncodableMap& a_map_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( From f4eb9f80d0b9468c3ba6fd5c516c23d695b01ad2 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 14:00:28 -0500 Subject: [PATCH 18/25] missing ; --- packages/pigeon/lib/cpp_generator.dart | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index a4a204026881..69b995b08d49 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -852,7 +852,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { const String argumentListVariableName = 'encoded_api_arguments'; indent.write('flutter::EncodableValue $argumentListVariableName = '); if (func.arguments.isEmpty) { - indent.writeln('flutter::EncodableValue()'); + indent.addln('flutter::EncodableValue();'); } else { indent.scoped('flutter::EncodableValue(flutter::EncodableList{', '});', () { 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 b2d0321db3c4..49ba710f248b 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 @@ -1440,12 +1440,10 @@ void FlutterIntegrationCoreApi::Noop( auto channel = std::make_unique>( binary_messenger_, "dev.flutter.pigeon.FlutterIntegrationCoreApi.noop", &GetCodec()); - flutter::EncodableValue encoded_api_arguments = - flutter::EncodableValue() channel->Send( - encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { - on_success(); - }); + flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(); + channel->Send(encoded_api_arguments, + [on_success, on_error](const uint8_t* reply, + size_t reply_size) { on_success(); }); } void FlutterIntegrationCoreApi::EchoAllTypes( const AllTypes& everything_arg, From 5d7ea154eaf8ca157a63c08eb9dac3e45622165a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 14:27:22 -0500 Subject: [PATCH 19/25] Drop string_view in Flutter API --- packages/pigeon/lib/cpp_generator.dart | 9 ++++++--- .../test_plugin/windows/pigeon/core_tests.gen.cpp | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/test/cpp_generator_test.dart | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 69b995b08d49..1ed79ef4021a 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -995,9 +995,12 @@ String _hostApiArgumentType(HostDatatype type) { /// 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 pointer types. - if (type.datatype == 'std::string' && type.isNullable) { - return 'const std::string*'; + // 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); } 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 49ba710f248b..fbc1f69399f4 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 @@ -1581,7 +1581,7 @@ void FlutterIntegrationCoreApi::EchoDouble( }); } void FlutterIntegrationCoreApi::EchoString( - std::string_view a_string_arg, + const std::string& a_string_arg, std::function&& on_success, std::function&& on_error) { auto channel = std::make_unique>( 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 1542800cf5e9..4206a73c3250 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 @@ -404,7 +404,7 @@ class FlutterIntegrationCoreApi { void EchoDouble(double a_double, std::function&& on_success, std::function&& on_error); // Returns the passed string, to test serialization and deserialization. - void EchoString(std::string_view a_string, + 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. diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index e2f8560205ff..0bf39103d325 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1233,8 +1233,9 @@ void main() { code, contains('DoSomething(bool a_bool, ' 'int64_t an_int, ' - // Non-nullable strings use string_view for flexibility. - 'std::string_view a_string, ' + // 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, ' From a9beb662b0836b2ddfcf572822b645e1b4e153d8 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 10 Jan 2023 20:25:38 -0500 Subject: [PATCH 20/25] Unwind incorrect 'simplification' of custom classes --- packages/pigeon/lib/cpp_generator.dart | 5 +++-- packages/pigeon/test/cpp_generator_test.dart | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 1ed79ef4021a..d5c0b7cbe89e 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -420,8 +420,9 @@ String _wrappedHostApiArgumentExpression(Root root, String variableName, final String encodableValue; if (!hostType.isBuiltin && root.classes.any((Class c) => c.name == dartType.baseName)) { - final String operator = hostType.isNullable ? '*' : ''; - encodableValue = 'flutter::CustomEncodableValue($operator$variableName)'; + 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 = diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 0bf39103d325..268a6dc0b845 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -463,7 +463,7 @@ void main() { expect( code, contains( - 'nullable_nested_ ? flutter::CustomEncodableValue(*nullable_nested_) ' + 'nullable_nested_ ? flutter::EncodableValue(nullable_nested_->ToEncodableList()) ' ': flutter::EncodableValue()')); } }); @@ -561,8 +561,7 @@ void main() { expect(code, contains('non_nullable_nested_ = value_arg;')); // Serialization uses the value directly. expect(code, contains('flutter::EncodableValue(non_nullable_bool_)')); - expect(code, - contains('flutter::CustomEncodableValue(non_nullable_nested_)')); + expect(code, contains('non_nullable_nested_.ToEncodableList()')); } }); @@ -1145,11 +1144,11 @@ void main() { code, contains( 'a_map_arg ? flutter::EncodableValue(*a_map_arg) : flutter::EncodableValue()')); - // Class types use CustomEncodableValue. + // Class types use ToEncodableList. expect( code, contains( - 'an_object_arg ? flutter::CustomEncodableValue(*an_object_arg) : flutter::EncodableValue()')); + 'an_object_arg ? flutter::EncodableValue(an_object_arg->ToEncodableList()) : flutter::EncodableValue()')); } }); @@ -1257,8 +1256,9 @@ void main() { 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 CustomEncodableValue. - expect(code, contains('flutter::CustomEncodableValue(an_object_arg)')); + // Class types use ToEncodableList. + expect(code, + contains('flutter::EncodableValue(an_object_arg.ToEncodableList())')); } }); From 3550260bb627c65af5b4bf2380c6d360c2dd62ba Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 11 Jan 2023 14:07:05 -0500 Subject: [PATCH 21/25] Fix merge mistake --- packages/pigeon/lib/cpp_generator.dart | 4 +-- .../windows/pigeon/core_tests.gen.cpp | 30 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index d5c0b7cbe89e..1bb6f9795158 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -1205,14 +1205,14 @@ flutter::EncodableValue ${api.name}::WrapError(std::string_view error_message) { \t\tflutter::EncodableValue(std::string(error_message)), \t\tflutter::EncodableValue("Error"), \t\tflutter::EncodableValue() -\t}; +\t}); } flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) { \treturn flutter::EncodableValue(flutter::EncodableList{ \t\tflutter::EncodableValue(error.message()), \t\tflutter::EncodableValue(error.code()), \t\terror.details() -\t}; +\t}); }'''); indent.addln(''); } else if (api.location == ApiLocation.flutter) { 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 fbc1f69399f4..eb5d6c3aad8e 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 @@ -465,7 +465,7 @@ void AllNullableTypesWrapper::set_values(const AllNullableTypes& value_arg) { flutter::EncodableList AllNullableTypesWrapper::ToEncodableList() const { return flutter::EncodableList{ - flutter::CustomEncodableValue(values_), + flutter::EncodableValue(values_.ToEncodableList()), }; } @@ -1353,18 +1353,14 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, flutter::EncodableValue HostIntegrationCoreApi::WrapError( std::string_view error_message) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(std::string(error_message)), - flutter::EncodableValue("Error"), - flutter::EncodableValue() - }; + flutter::EncodableValue(std::string(error_message)), + flutter::EncodableValue("Error"), flutter::EncodableValue()}); } flutter::EncodableValue HostIntegrationCoreApi::WrapError( const FlutterError& error) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(error.message()), - flutter::EncodableValue(error.code()), - error.details() - }; + flutter::EncodableValue(error.message()), + flutter::EncodableValue(error.code()), error.details()}); } FlutterIntegrationCoreApiCodecSerializer:: @@ -1454,7 +1450,7 @@ void FlutterIntegrationCoreApi::EchoAllTypes( "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", &GetCodec()); flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(flutter::EncodableList{ - flutter::CustomEncodableValue(everything_arg), + flutter::EncodableValue(everything_arg.ToEncodableList()), }); channel->Send( encoded_api_arguments, @@ -1477,7 +1473,7 @@ void FlutterIntegrationCoreApi::EchoAllNullableTypes( &GetCodec()); flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(flutter::EncodableList{ - flutter::CustomEncodableValue(everything_arg), + flutter::EncodableValue(everything_arg.ToEncodableList()), }); channel->Send( encoded_api_arguments, @@ -1875,17 +1871,13 @@ void HostTrivialApi::SetUp(flutter::BinaryMessenger* binary_messenger, flutter::EncodableValue HostTrivialApi::WrapError( std::string_view error_message) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(std::string(error_message)), - flutter::EncodableValue("Error"), - flutter::EncodableValue() - }; + flutter::EncodableValue(std::string(error_message)), + flutter::EncodableValue("Error"), flutter::EncodableValue()}); } flutter::EncodableValue HostTrivialApi::WrapError(const FlutterError& error) { return flutter::EncodableValue(flutter::EncodableList{ - flutter::EncodableValue(error.message()), - flutter::EncodableValue(error.code()), - error.details() - }; + flutter::EncodableValue(error.message()), + flutter::EncodableValue(error.code()), error.details()}); } } // namespace core_tests_pigeontest From 7b0a960328d096c0d4797b1edea7c0fde10999cb Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 12 Jan 2023 11:01:30 -0500 Subject: [PATCH 22/25] Merge mistake --- packages/pigeon/test/cpp_generator_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 268a6dc0b845..b993b3573042 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1092,7 +1092,7 @@ void main() { ], enums: []); { final StringBuffer sink = StringBuffer(); - generateCppHeader('', const CppOptions(), root, sink); + generateCppHeader(const CppOptions(), 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 @@ -1226,7 +1226,7 @@ void main() { ], enums: []); { final StringBuffer sink = StringBuffer(); - generateCppHeader('', const CppOptions(), root, sink); + generateCppHeader(const CppOptions(), root, sink); final String code = sink.toString(); expect( code, From 47c2d0f55e3cfbcaac1ed41cf55efb6b398d8058 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 12 Jan 2023 11:07:37 -0500 Subject: [PATCH 23/25] Version bump --- packages/pigeon/CHANGELOG.md | 6 +++ packages/pigeon/lib/generator_tools.dart | 2 +- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- .../CoreTests.java | 2 +- .../ios/Classes/CoreTests.gen.h | 2 +- .../ios/Classes/CoreTests.gen.m | 2 +- .../lib/core_tests.gen.dart | 2 +- .../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/src/generated/core_tests.gen.dart | 2 +- .../com/example/test_plugin/CoreTests.gen.kt | 4 +- .../ios/Classes/CoreTests.gen.swift | 46 +++++++++---------- .../macos/Classes/CoreTests.gen.swift | 46 +++++++++---------- .../windows/pigeon/core_tests.gen.cpp | 2 +- .../windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/pubspec.yaml | 2 +- 21 files changed, 71 insertions(+), 65 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 1c47219f08cd..91b362fb8024 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,9 @@ +## 5.0.2 + +* [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. + ## 5.0.1 * [c++] Fixes undefined behavior in `@async` methods. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 4355096e0014..c2df561eaccb 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 = '5.0.1'; +const String pigeonVersion = '5.0.2'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 00ecc407416b..f07524a9c5c7 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index e1644f13686c..fc826e364b69 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), 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/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 188b2a02e140..2ed25d07d030 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; 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 407fba80c041..8245a98cd08e 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; 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 2a09f6edd865..446d714c4c89 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" #import 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 2c18e5613a2a..9208f7dd405d 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 9600a969cdf1..8d99f55d0be4 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 a73dbb8ceed0..bc93a4fbaf88 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 1683e856567e..bc6d5937237d 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 83f20830fc0b..0afaf127f7cc 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 c5e1738c53d6..86951dfabfbc 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 8ca3c619f342..34920238821b 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 2c18e5613a2a..9208f7dd405d 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; 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 c80b571177d2..8033039b4e3c 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 @@ -1,8 +1,8 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// Autogenerated from Pigeon (v5.0.1), do not edit directly. +// +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin 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 7a18e70928ed..09994014344e 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 @@ -1,8 +1,8 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// Autogenerated from Pigeon (v5.0.1), do not edit directly. +// +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -99,19 +99,19 @@ struct AllNullableTypes { var aNullableEnum: AnEnum? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool = list[0] as? Bool - let aNullableInt = list[1] as? Int32 - let aNullableDouble = list[2] as? Double - let aNullableString = list[3] as? String - let aNullableByteArray = list[4] as? FlutterStandardTypedData - let aNullable4ByteArray = list[5] as? FlutterStandardTypedData - let aNullable8ByteArray = list[6] as? FlutterStandardTypedData - let aNullableFloatArray = list[7] as? FlutterStandardTypedData - let aNullableList = list[8] as? [Any?] - let aNullableMap = list[9] as? [AnyHashable: Any?] - let nullableNestedList = list[10] as? [[Bool?]?] - let nullableMapWithAnnotations = list[11] as? [String?: String?] - let nullableMapWithObject = list[12] as? [String?: Any?] + let aNullableBool = list[0] as? Bool + let aNullableInt = list[1] as? Int32 + let aNullableDouble = list[2] as? Double + let aNullableString = list[3] as? String + let aNullableByteArray = list[4] as? FlutterStandardTypedData + let aNullable4ByteArray = list[5] as? FlutterStandardTypedData + let aNullable8ByteArray = list[6] as? FlutterStandardTypedData + let aNullableFloatArray = list[7] as? FlutterStandardTypedData + let aNullableList = list[8] as? [Any?] + let aNullableMap = list[9] as? [AnyHashable: Any?] + let nullableNestedList = list[10] as? [[Bool?]?] + let nullableMapWithAnnotations = list[11] as? [String?: String?] + let nullableMapWithObject = list[12] as? [String?: Any?] var aNullableEnum: AnEnum? = nil if let aNullableEnumRawValue = list[13] as? Int { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue) @@ -176,14 +176,14 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any]) + return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) case 130: - return AllTypes.fromList(self.readValue() as! [Any]) + return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) - + } } } @@ -561,14 +561,14 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any]) + return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) case 130: - return AllTypes.fromList(self.readValue() as! [Any]) + return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) - + } } } 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 7a18e70928ed..09994014344e 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 @@ -1,8 +1,8 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// -// Autogenerated from Pigeon (v5.0.1), do not edit directly. +// +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -99,19 +99,19 @@ struct AllNullableTypes { var aNullableEnum: AnEnum? = nil static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool = list[0] as? Bool - let aNullableInt = list[1] as? Int32 - let aNullableDouble = list[2] as? Double - let aNullableString = list[3] as? String - let aNullableByteArray = list[4] as? FlutterStandardTypedData - let aNullable4ByteArray = list[5] as? FlutterStandardTypedData - let aNullable8ByteArray = list[6] as? FlutterStandardTypedData - let aNullableFloatArray = list[7] as? FlutterStandardTypedData - let aNullableList = list[8] as? [Any?] - let aNullableMap = list[9] as? [AnyHashable: Any?] - let nullableNestedList = list[10] as? [[Bool?]?] - let nullableMapWithAnnotations = list[11] as? [String?: String?] - let nullableMapWithObject = list[12] as? [String?: Any?] + let aNullableBool = list[0] as? Bool + let aNullableInt = list[1] as? Int32 + let aNullableDouble = list[2] as? Double + let aNullableString = list[3] as? String + let aNullableByteArray = list[4] as? FlutterStandardTypedData + let aNullable4ByteArray = list[5] as? FlutterStandardTypedData + let aNullable8ByteArray = list[6] as? FlutterStandardTypedData + let aNullableFloatArray = list[7] as? FlutterStandardTypedData + let aNullableList = list[8] as? [Any?] + let aNullableMap = list[9] as? [AnyHashable: Any?] + let nullableNestedList = list[10] as? [[Bool?]?] + let nullableMapWithAnnotations = list[11] as? [String?: String?] + let nullableMapWithObject = list[12] as? [String?: Any?] var aNullableEnum: AnEnum? = nil if let aNullableEnumRawValue = list[13] as? Int { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue) @@ -176,14 +176,14 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any]) + return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) case 130: - return AllTypes.fromList(self.readValue() as! [Any]) + return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) - + } } } @@ -561,14 +561,14 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: - return AllNullableTypes.fromList(self.readValue() as! [Any]) + return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) + return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) case 130: - return AllTypes.fromList(self.readValue() as! [Any]) + return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) - + } } } 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 eb5d6c3aad8e..1e0a086365bb 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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS 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 4206a73c3250..39f9c33e1aa0 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,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 (v5.0.1), do not edit directly. +// Autogenerated from Pigeon (v5.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_PIGEONTEST_H_ diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index f2a5a9a66392..3e1b364ac62b 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: 5.0.1 # This must match the version in lib/generator_tools.dart +version: 5.0.2 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" From f742c20c20411785809e5236a65b35dec19a9713 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 13 Jan 2023 13:32:49 -0500 Subject: [PATCH 24/25] Address review comments --- packages/pigeon/lib/cpp_generator.dart | 171 +++++++----------- .../windows/pigeon/core_tests.gen.cpp | 58 ++++-- 2 files changed, 105 insertions(+), 124 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 1bb6f9795158..9ab45b1c6cdf 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -236,10 +236,7 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, 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( @@ -278,10 +275,7 @@ void _writeDataClassDeclaration(Indent indent, Class klass, Root root, 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)};'); } @@ -304,8 +298,8 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { // Getters and setters. for (final NamedType field in getFieldsInSerializationOrder(klass)) { - 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)}'; @@ -346,10 +340,7 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { 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)); + field, root.classes, root.enums, _baseCppTypeForBuiltinDartType); final String encodableValue = _wrappedHostApiArgumentExpression( root, _makeInstanceVariableName(field), field.type, hostDatatype); @@ -380,10 +371,7 @@ void _writeDataClassImplementation(Indent indent, Class klass, Root root) { '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)) @@ -439,11 +427,10 @@ String _wrappedHostApiArgumentExpression(Root root, String variableName, return encodableValue; } -// Writes the code to declare and populate a variable called [argName] to use -// as a parameter to an API method call from an existing EncodableValue -// variable called [encodableArgName] which corresponds to [arg] in the API -// definition. -void _writeEncodedArgumentExtraction( +// 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, @@ -511,11 +498,8 @@ void _writeHostApiHeader(Indent indent, Api api, Root root) { 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 HostDatatype returnType = getHostDatatype(method.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); final String returnTypeName = _hostApiReturnType(returnType); final List argSignature = []; @@ -523,10 +507,7 @@ void _writeHostApiHeader(Indent indent, Api api, Root root) { final Iterable argTypes = method.arguments.map((NamedType arg) { final HostDatatype hostType = getFieldHostDatatype( - arg, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + arg, root.classes, root.enums, _baseCppTypeForBuiltinDartType); return _hostApiArgumentType(hostType); }); final Iterable argNames = @@ -604,11 +585,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { 'const auto& args = std::get(message);'); enumerate(method.arguments, (int index, NamedType arg) { - final HostDatatype hostType = getHostDatatype( - arg.type, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final HostDatatype hostType = getHostDatatype(arg.type, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); final String argName = _getSafeArgumentName(index, arg); final String encodableArgName = @@ -623,7 +601,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.writeln('return;'); }); } - _writeEncodedArgumentExtraction(indent, hostType, + _writeEncodableValueArgumentUnwrapping(indent, hostType, argName: argName, encodableArgName: encodableArgName); methodArgument.add(argName); }); @@ -641,11 +619,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { 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' @@ -681,11 +656,8 @@ $nonErrorPath ${prefix}reply(flutter::EncodableValue(std::move(wrapped)));'''; } - final HostDatatype returnType = getHostDatatype( - method.returnType, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); + final HostDatatype returnType = getHostDatatype(method.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); final String returnTypeName = _hostApiReturnType(returnType); if (method.isAsynchronous) { methodArgument.add( @@ -750,37 +722,24 @@ void _writeFlutterApiHeader(Indent indent, Api api, Root root) { indent.writeln(''); indent.writeln('static const flutter::StandardMessageCodec& GetCodec();'); for (final Method func in api.methods) { - final HostDatatype returnType = getHostDatatype( - func.returnType, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String successCallback = - 'std::function&& on_success'; - const String errorCallback = - 'std::function&& on_error'; + final HostDatatype returnType = getHostDatatype(func.returnType, + root.classes, root.enums, _baseCppTypeForBuiltinDartType); addDocumentationComments( indent, func.documentationComments, _docCommentSpec); - if (func.arguments.isEmpty) { - indent.writeln('void ${_makeMethodName(func)}($successCallback, ' - '$errorCallback);'); - } else { - final Iterable argTypes = func.arguments.map((NamedType arg) { - final HostDatatype hostType = getFieldHostDatatype( - arg, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - return _flutterApiArgumentType(hostType); - }); - final Iterable argNames = - indexMap(func.arguments, _getArgumentName); - final String argsSignature = - map2(argTypes, argNames, (String x, String y) => '$x $y') - .join(', '); - indent.writeln('void ${_makeMethodName(func)}($argsSignature, ' - '$successCallback, $errorCallback);'); - } + + 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); @@ -798,6 +757,15 @@ class _HostNamedType { final TypeDeclaration originalType; } +/// 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', + ]; +} + void _writeFlutterApiSource(Indent indent, Api api, Root root) { assert(api.location == ApiLocation.flutter); indent.writeln( @@ -818,38 +786,31 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { '''); for (final Method func in api.methods) { final String channelName = makeChannelName(api, func); - final HostDatatype returnType = getHostDatatype( - func.returnType, - root.classes, - root.enums, - (TypeDeclaration x) => _baseCppTypeForBuiltinDartType(x)); - final String successCallback = - 'std::function&& on_success'; - const String errorCallback = - 'std::function&& on_error'; - - // Determine the input argument list, saved in a structured form for later + 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> hostArgs = + final Iterable<_HostNamedType> hostParameters = indexMap(func.arguments, (int i, 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 _HostNamedType(_getSafeArgumentName(i, arg), hostType, arg.type); }); - final String inputArgumentList = hostArgs - .map((_HostNamedType arg) => - '${_flutterApiArgumentType(arg.hostType)} ${arg.name}') - .join(', '); - indent.write('void ${api.name}::${_makeMethodName(func)}(' - '${inputArgumentList.isEmpty ? '' : '$inputArgumentList, '}' - '$successCallback, $errorCallback) '); + 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>(binary_messenger_, ' '"$channelName", &GetCodec());'); - // Convert arguments to EncodableValue versions + // Convert arguments to EncodableValue versions. const String argumentListVariableName = 'encoded_api_arguments'; indent.write('flutter::EncodableValue $argumentListVariableName = '); if (func.arguments.isEmpty) { @@ -857,16 +818,18 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { } else { indent.scoped('flutter::EncodableValue(flutter::EncodableList{', '});', () { - for (final _HostNamedType arg in hostArgs) { + for (final _HostNamedType param in hostParameters) { final String encodedArgument = _wrappedHostApiArgumentExpression( - root, arg.name, arg.originalType, arg.hostType); + root, param.name, param.originalType, param.hostType); indent.writeln('$encodedArgument,'); } }); } - indent.write( - '$channel->Send($argumentListVariableName, [on_success, on_error](const uint8_t* reply, size_t reply_size) '); + 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) { @@ -877,7 +840,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { indent.writeln( 'std::unique_ptr response = GetCodec().DecodeMessage(reply, reply_size);'); indent.writeln('const auto& $encodedReplyName = *response;'); - _writeEncodedArgumentExtraction(indent, returnType, + _writeEncodableValueArgumentUnwrapping(indent, returnType, argName: successCallbackArgument, encodableArgName: encodedReplyName); } 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 1e0a086365bb..c60b93ea15e3 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 @@ -1437,9 +1437,10 @@ void FlutterIntegrationCoreApi::Noop( binary_messenger_, "dev.flutter.pigeon.FlutterIntegrationCoreApi.noop", &GetCodec()); flutter::EncodableValue encoded_api_arguments = flutter::EncodableValue(); - channel->Send(encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, - size_t reply_size) { on_success(); }); + 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) { on_success(); }); } void FlutterIntegrationCoreApi::EchoAllTypes( const AllTypes& everything_arg, @@ -1454,7 +1455,8 @@ void FlutterIntegrationCoreApi::EchoAllTypes( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1477,7 +1479,8 @@ void FlutterIntegrationCoreApi::EchoAllNullableTypes( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1507,7 +1510,8 @@ void FlutterIntegrationCoreApi::SendMultipleNullableTypes( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1528,7 +1532,8 @@ void FlutterIntegrationCoreApi::EchoBool( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1548,7 +1553,8 @@ void FlutterIntegrationCoreApi::EchoInt( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1568,7 +1574,8 @@ void FlutterIntegrationCoreApi::EchoDouble( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1589,7 +1596,8 @@ void FlutterIntegrationCoreApi::EchoString( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1612,7 +1620,8 @@ void FlutterIntegrationCoreApi::EchoUint8List( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1634,7 +1643,8 @@ void FlutterIntegrationCoreApi::EchoList( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1656,7 +1666,8 @@ void FlutterIntegrationCoreApi::EchoMap( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1679,7 +1690,8 @@ void FlutterIntegrationCoreApi::EchoNullableBool( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1701,7 +1713,8 @@ void FlutterIntegrationCoreApi::EchoNullableInt( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1728,7 +1741,8 @@ void FlutterIntegrationCoreApi::EchoNullableDouble( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1751,7 +1765,8 @@ void FlutterIntegrationCoreApi::EchoNullableString( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1775,7 +1790,8 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1799,7 +1815,8 @@ void FlutterIntegrationCoreApi::EchoNullableList( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; @@ -1822,7 +1839,8 @@ void FlutterIntegrationCoreApi::EchoNullableMap( }); channel->Send( encoded_api_arguments, - [on_success, on_error](const uint8_t* reply, size_t reply_size) { + [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; From 889364168c28789748fc5251ab4750f823943b3f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 13 Jan 2023 19:53:52 -0500 Subject: [PATCH 25/25] Fix Dart unit test compilation --- packages/pigeon/test/cpp_generator_test.dart | 32 +++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 8834480ed10c..9aa4784708a0 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1228,7 +1228,13 @@ void main() { ], enums: []); { final StringBuffer sink = StringBuffer(); - generateCppHeader(const CppOptions(), root, sink); + 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 @@ -1256,7 +1262,13 @@ void main() { } { final StringBuffer sink = StringBuffer(); - generateCppSource(const CppOptions(), root, sink); + 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. @@ -1362,7 +1374,13 @@ void main() { ], enums: []); { final StringBuffer sink = StringBuffer(); - generateCppHeader(const CppOptions(), root, sink); + 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, @@ -1384,7 +1402,13 @@ void main() { } { final StringBuffer sink = StringBuffer(); - generateCppSource(const CppOptions(), root, sink); + 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)'));