diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 13033b336a8..4fa98cd73e2 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,12 @@ +## 20.0.0 + +* Moves all codec logic to single custom codec per file. +* **Breaking Change** Limits the number of total custom types to 126. + * If more than 126 custom types are needed, consider breaking up your definition files. +* Fixes bug that prevented collection subtypes from being added properly. +* [swift] Adds `@unchecked Sendable` to codec method. +* [objc] [cpp] Fixes bug that prevented setting custom header import path. + ## 19.0.2 * [kotlin] Adds the `@JvmOverloads` to the `HostApi` setUp method. This prevents the calling Java code from having to provide an empty `String` as Kotlin provides it by default diff --git a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java index f8029ebcd92..4993909460e 100644 --- a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java +++ b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java @@ -181,7 +181,7 @@ ArrayList toList() { ArrayList toListResult = new ArrayList(4); toListResult.add(name); toListResult.add(description); - toListResult.add(code == null ? null : code.index); + toListResult.add(code); toListResult.add(data); return toListResult; } @@ -193,13 +193,45 @@ ArrayList toList() { Object description = __pigeon_list.get(1); pigeonResult.setDescription((String) description); Object code = __pigeon_list.get(2); - pigeonResult.setCode(Code.values()[(int) code]); + pigeonResult.setCode((Code) code); Object data = __pigeon_list.get(3); pigeonResult.setData((Map) data); return pigeonResult; } } + private static class PigeonCodec extends StandardMessageCodec { + public static final PigeonCodec INSTANCE = new PigeonCodec(); + + private PigeonCodec() {} + + @Override + protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { + switch (type) { + case (byte) 129: + return MessageData.fromList((ArrayList) readValue(buffer)); + case (byte) 130: + Object value = readValue(buffer); + return value == null ? null : Code.values()[(int) value]; + default: + return super.readValueOfType(type, buffer); + } + } + + @Override + protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { + if (value instanceof MessageData) { + stream.write(129); + writeValue(stream, ((MessageData) value).toList()); + } else if (value instanceof Code) { + stream.write(130); + writeValue(stream, value == null ? null : ((Code) value).index); + } else { + super.writeValue(stream, value); + } + } + } + /** Asynchronous error handling return type for non-nullable API method returns. */ public interface Result { /** Success case callback method for handling returns. */ @@ -224,33 +256,6 @@ public interface VoidResult { /** Failure case callback method for handling errors. */ void error(@NonNull Throwable error); } - - private static class ExampleHostApiCodec extends StandardMessageCodec { - public static final ExampleHostApiCodec INSTANCE = new ExampleHostApiCodec(); - - private ExampleHostApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return MessageData.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof MessageData) { - stream.write(128); - writeValue(stream, ((MessageData) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ExampleHostApi { @@ -264,7 +269,7 @@ public interface ExampleHostApi { /** The codec used by ExampleHostApi. */ static @NonNull MessageCodec getCodec() { - return ExampleHostApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } /** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */ static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable ExampleHostApi api) { @@ -382,7 +387,7 @@ public MessageFlutterApi( /** Public interface for sending reply. */ /** The codec used by MessageFlutterApi. */ static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); + return PigeonCodec.INSTANCE; } public void flutterMethod(@Nullable String aStringArg, @NonNull Result result) { diff --git a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt index 7f0e75cefa9..6542e190e78 100644 --- a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt +++ b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt @@ -69,28 +69,31 @@ data class MessageData( fun fromList(__pigeon_list: List): MessageData { val name = __pigeon_list[0] as String? val description = __pigeon_list[1] as String? - val code = Code.ofRaw(__pigeon_list[2] as Int)!! + val code = __pigeon_list[2] as Code val data = __pigeon_list[3] as Map return MessageData(name, description, code, data) } } fun toList(): List { - return listOf( + return listOf( name, description, - code.raw, + code, data, ) } } -private object ExampleHostApiCodec : StandardMessageCodec() { +private object MessagesPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { - 128.toByte() -> { + 129.toByte() -> { return (readValue(buffer) as? List)?.let { MessageData.fromList(it) } } + 130.toByte() -> { + return (readValue(buffer) as Int?)?.let { Code.ofRaw(it) } + } else -> super.readValueOfType(type, buffer) } } @@ -98,9 +101,13 @@ private object ExampleHostApiCodec : StandardMessageCodec() { override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { is MessageData -> { - stream.write(128) + stream.write(129) writeValue(stream, value.toList()) } + is Code -> { + stream.write(130) + writeValue(stream, value.raw) + } else -> super.writeValue(stream, value) } } @@ -116,7 +123,7 @@ interface ExampleHostApi { companion object { /** The codec used by ExampleHostApi. */ - val codec: MessageCodec by lazy { ExampleHostApiCodec } + val codec: MessageCodec by lazy { MessagesPigeonCodec } /** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */ @JvmOverloads fun setUp( @@ -136,7 +143,7 @@ interface ExampleHostApi { channel.setMessageHandler { _, reply -> val wrapped: List = try { - listOf(api.getHostLanguage()) + listOf(api.getHostLanguage()) } catch (exception: Throwable) { wrapError(exception) } @@ -159,7 +166,7 @@ interface ExampleHostApi { val bArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long } val wrapped: List = try { - listOf(api.add(aArg, bArg)) + listOf(api.add(aArg, bArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -203,7 +210,7 @@ class MessageFlutterApi( ) { companion object { /** The codec used by MessageFlutterApi. */ - val codec: MessageCodec by lazy { StandardMessageCodec() } + val codec: MessageCodec by lazy { MessagesPigeonCodec } } fun flutterMethod(aStringArg: String?, callback: (Result) -> Unit) { diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index 51b3cfa61de..3d5362cc4f1 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -89,7 +89,7 @@ struct MessageData { static func fromList(_ __pigeon_list: [Any?]) -> MessageData? { let name: String? = nilOrValue(__pigeon_list[0]) let description: String? = nilOrValue(__pigeon_list[1]) - let code = Code(rawValue: __pigeon_list[2] as! Int)! + let code = __pigeon_list[2] as! Code let data = __pigeon_list[3] as! [String?: String?] return MessageData( @@ -103,46 +103,55 @@ struct MessageData { return [ name, description, - code.rawValue, + code, data, ] } } - -private class ExampleHostApiCodecReader: FlutterStandardReader { +private class MessagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: + case 129: return MessageData.fromList(self.readValue() as! [Any?]) + case 130: + var enumResult: Code? = nil + let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int) + if let enumResultAsInt = enumResultAsInt { + enumResult = Code(rawValue: enumResultAsInt) + } + return enumResult default: return super.readValue(ofType: type) } } } -private class ExampleHostApiCodecWriter: FlutterStandardWriter { +private class MessagesPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { if let value = value as? MessageData { - super.writeByte(128) + super.writeByte(129) super.writeValue(value.toList()) + } else if let value = value as? Code { + super.writeByte(130) + super.writeValue(value.rawValue) } else { super.writeValue(value) } } } -private class ExampleHostApiCodecReaderWriter: FlutterStandardReaderWriter { +private class MessagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return ExampleHostApiCodecReader(data: data) + return MessagesPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return ExampleHostApiCodecWriter(data: data) + return MessagesPigeonCodecWriter(data: data) } } -class ExampleHostApiCodec: FlutterStandardMessageCodec { - static let shared = ExampleHostApiCodec(readerWriter: ExampleHostApiCodecReaderWriter()) +class MessagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = MessagesPigeonCodec(readerWriter: MessagesPigeonCodecReaderWriter()) } /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -154,8 +163,7 @@ protocol ExampleHostApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class ExampleHostApiSetup { - /// The codec used by ExampleHostApi. - static var codec: FlutterStandardMessageCodec { ExampleHostApiCodec.shared } + static var codec: FlutterStandardMessageCodec { MessagesPigeonCodec.shared } /// Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: ExampleHostApi?, messageChannelSuffix: String = "" @@ -228,12 +236,16 @@ class MessageFlutterApi: MessageFlutterApiProtocol { self.binaryMessenger = binaryMessenger self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } + var codec: MessagesPigeonCodec { + return MessagesPigeonCodec.shared + } func flutterMethod( aString aStringArg: String?, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod\(messageChannelSuffix)" - let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger) + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 071711ffaa9..d8d4fde551c 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -54,7 +54,7 @@ class MessageData { return [ name, description, - code.index, + code, data, ]; } @@ -64,19 +64,22 @@ class MessageData { return MessageData( name: result[0] as String?, description: result[1] as String?, - code: Code.values[result[2]! as int], + code: result[2]! as Code, data: (result[3] as Map?)!.cast(), ); } } -class _ExampleHostApiCodec extends StandardMessageCodec { - const _ExampleHostApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is MessageData) { - buffer.putUint8(128); + buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is Code) { + buffer.putUint8(130); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -85,8 +88,11 @@ class _ExampleHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return MessageData.decode(readValue(buffer)!); + case 130: + final int? value = readValue(buffer) as int?; + return value == null ? null : Code.values[value]; default: return super.readValueOfType(type, buffer); } @@ -104,8 +110,7 @@ class ExampleHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _ExampleHostApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -198,8 +203,7 @@ class ExampleHostApi { } abstract class MessageFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); String flutterMethod(String? aString); diff --git a/packages/pigeon/example/app/macos/Runner/messages.g.h b/packages/pigeon/example/app/macos/Runner/messages.g.h index db20dcba17e..8a51885ec9f 100644 --- a/packages/pigeon/example/app/macos/Runner/messages.g.h +++ b/packages/pigeon/example/app/macos/Runner/messages.g.h @@ -39,8 +39,8 @@ typedef NS_ENUM(NSUInteger, PGNCode) { @property(nonatomic, copy) NSDictionary *data; @end -/// The codec used by PGNExampleHostApi. -NSObject *PGNExampleHostApiGetCodec(void); +/// The codec used by all APIs. +NSObject *PGNGetMessagesCodec(void); @protocol PGNExampleHostApi /// @return `nil` only when `error != nil`. @@ -60,9 +60,6 @@ extern void SetUpPGNExampleHostApiWithSuffix(id binaryMe NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by PGNMessageFlutterApi. -NSObject *PGNMessageFlutterApiGetCodec(void); - @interface PGNMessageFlutterApi : NSObject - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger diff --git a/packages/pigeon/example/app/macos/Runner/messages.g.m b/packages/pigeon/example/app/macos/Runner/messages.g.m index 90bd065401c..1471345b880 100644 --- a/packages/pigeon/example/app/macos/Runner/messages.g.m +++ b/packages/pigeon/example/app/macos/Runner/messages.g.m @@ -16,7 +16,7 @@ #error File requires ARC to be enabled. #endif -static NSArray *wrapResult(id result, FlutterError *error) { +static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] @@ -34,7 +34,7 @@ details:@""]; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } @@ -50,9 +50,9 @@ - (instancetype)initWithValue:(PGNCode)value { @end @interface PGNMessageData () -+ (PGNMessageData *)fromList:(NSArray *)list; -+ (nullable PGNMessageData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (PGNMessageData *)fromList:(NSArray *)list; ++ (nullable PGNMessageData *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @implementation PGNMessageData @@ -67,75 +67,84 @@ + (instancetype)makeWithName:(nullable NSString *)name pigeonResult.data = data; return pigeonResult; } -+ (PGNMessageData *)fromList:(NSArray *)list { ++ (PGNMessageData *)fromList:(NSArray *)list { PGNMessageData *pigeonResult = [[PGNMessageData alloc] init]; pigeonResult.name = GetNullableObjectAtIndex(list, 0); pigeonResult.description = GetNullableObjectAtIndex(list, 1); - pigeonResult.code = [GetNullableObjectAtIndex(list, 2) integerValue]; + PGNCodeBox *enumBox = GetNullableObjectAtIndex(list, 2); + pigeonResult.code = enumBox.value; pigeonResult.data = GetNullableObjectAtIndex(list, 3); return pigeonResult; } -+ (nullable PGNMessageData *)nullableFromList:(NSArray *)list { ++ (nullable PGNMessageData *)nullableFromList:(NSArray *)list { return (list) ? [PGNMessageData fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.name ?: [NSNull null], self.description ?: [NSNull null], - @(self.code), + [[PGNCodeBox alloc] initWithValue:self.code], self.data ?: [NSNull null], ]; } @end -@interface PGNExampleHostApiCodecReader : FlutterStandardReader +@interface PGNMessagesPigeonCodecReader : FlutterStandardReader @end -@implementation PGNExampleHostApiCodecReader +@implementation PGNMessagesPigeonCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 129: return [PGNMessageData fromList:[self readValue]]; + case 130: { + NSNumber *enumAsNumber = [self readValue]; + return enumAsNumber == nil ? nil + : [[PGNCodeBox alloc] initWithValue:[enumAsNumber integerValue]]; + } default: return [super readValueOfType:type]; } } @end -@interface PGNExampleHostApiCodecWriter : FlutterStandardWriter +@interface PGNMessagesPigeonCodecWriter : FlutterStandardWriter @end -@implementation PGNExampleHostApiCodecWriter +@implementation PGNMessagesPigeonCodecWriter - (void)writeValue:(id)value { if ([value isKindOfClass:[PGNMessageData class]]) { - [self writeByte:128]; + [self writeByte:129]; [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[PGNCodeBox class]]) { + PGNCodeBox *box = (PGNCodeBox *)value; + [self writeByte:130]; + [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else { [super writeValue:value]; } } @end -@interface PGNExampleHostApiCodecReaderWriter : FlutterStandardReaderWriter +@interface PGNMessagesPigeonCodecReaderWriter : FlutterStandardReaderWriter @end -@implementation PGNExampleHostApiCodecReaderWriter +@implementation PGNMessagesPigeonCodecReaderWriter - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[PGNExampleHostApiCodecWriter alloc] initWithData:data]; + return [[PGNMessagesPigeonCodecWriter alloc] initWithData:data]; } - (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[PGNExampleHostApiCodecReader alloc] initWithData:data]; + return [[PGNMessagesPigeonCodecReader alloc] initWithData:data]; } @end -NSObject *PGNExampleHostApiGetCodec(void) { +NSObject *PGNGetMessagesCodec(void) { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - PGNExampleHostApiCodecReaderWriter *readerWriter = - [[PGNExampleHostApiCodecReaderWriter alloc] init]; + PGNMessagesPigeonCodecReaderWriter *readerWriter = + [[PGNMessagesPigeonCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - void SetUpPGNExampleHostApi(id binaryMessenger, NSObject *api) { SetUpPGNExampleHostApiWithSuffix(binaryMessenger, api, @""); @@ -154,7 +163,7 @@ void SetUpPGNExampleHostApiWithSuffix(id binaryMessenger @"ExampleHostApi.getHostLanguage", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PGNExampleHostApiGetCodec()]; + codec:PGNGetMessagesCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(getHostLanguageWithError:)], @@ -177,14 +186,14 @@ void SetUpPGNExampleHostApiWithSuffix(id binaryMessenger @"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PGNExampleHostApiGetCodec()]; + codec:PGNGetMessagesCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(addNumber:toNumber:error:)], @"PGNExampleHostApi api (%@) doesn't respond to @selector(addNumber:toNumber:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_a = [GetNullableObjectAtIndex(args, 0) integerValue]; NSInteger arg_b = [GetNullableObjectAtIndex(args, 1) integerValue]; FlutterError *error; @@ -202,14 +211,14 @@ void SetUpPGNExampleHostApiWithSuffix(id binaryMessenger @"ExampleHostApi.sendMessage", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PGNExampleHostApiGetCodec()]; + codec:PGNGetMessagesCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(sendMessageMessage:completion:)], @"PGNExampleHostApi api (%@) doesn't respond to " @"@selector(sendMessageMessage:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; PGNMessageData *arg_message = GetNullableObjectAtIndex(args, 0); [api sendMessageMessage:arg_message completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -221,12 +230,6 @@ void SetUpPGNExampleHostApiWithSuffix(id binaryMessenger } } } -NSObject *PGNMessageFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - @interface PGNMessageFlutterApi () @property(nonatomic, strong) NSObject *binaryMessenger; @property(nonatomic, strong) NSString *messageChannelSuffix; @@ -257,7 +260,7 @@ - (void)flutterMethodAString:(nullable NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:PGNMessageFlutterApiGetCodec()]; + codec:PGNGetMessagesCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { diff --git a/packages/pigeon/example/app/windows/runner/messages.g.cpp b/packages/pigeon/example/app/windows/runner/messages.g.cpp index 5f6e25a18db..7a43ec397a3 100644 --- a/packages/pigeon/example/app/windows/runner/messages.g.cpp +++ b/packages/pigeon/example/app/windows/runner/messages.g.cpp @@ -82,14 +82,15 @@ EncodableList MessageData::ToEncodableList() const { list.push_back(name_ ? EncodableValue(*name_) : EncodableValue()); list.push_back(description_ ? EncodableValue(*description_) : EncodableValue()); - list.push_back(EncodableValue((int)code_)); + list.push_back(CustomEncodableValue(code_)); list.push_back(EncodableValue(data_)); return list; } MessageData MessageData::FromEncodableList(const EncodableList& list) { - MessageData decoded((Code)(std::get(list[2])), - std::get(list[3])); + MessageData decoded( + std::any_cast(std::get(list[2])), + std::get(list[3])); auto& encodable_name = list[0]; if (!encodable_name.IsNull()) { decoded.set_name(std::get(encodable_name)); @@ -101,31 +102,46 @@ MessageData MessageData::FromEncodableList(const EncodableList& list) { return decoded; } -ExampleHostApiCodecSerializer::ExampleHostApiCodecSerializer() {} +PigeonCodecSerializer::PigeonCodecSerializer() {} -EncodableValue ExampleHostApiCodecSerializer::ReadValueOfType( +EncodableValue PigeonCodecSerializer::ReadValueOfType( uint8_t type, flutter::ByteStreamReader* stream) const { switch (type) { - case 128: + case 129: return CustomEncodableValue(MessageData::FromEncodableList( std::get(ReadValue(stream)))); + case 130: { + const auto& encodable_enum_arg = ReadValue(stream); + const int64_t enum_arg_value = + encodable_enum_arg.IsNull() ? 0 : encodable_enum_arg.LongValue(); + return encodable_enum_arg.IsNull() + ? EncodableValue() + : CustomEncodableValue(static_cast(enum_arg_value)); + } default: return flutter::StandardCodecSerializer::ReadValueOfType(type, stream); } } -void ExampleHostApiCodecSerializer::WriteValue( +void PigeonCodecSerializer::WriteValue( const EncodableValue& value, flutter::ByteStreamWriter* stream) const { if (const CustomEncodableValue* custom_value = std::get_if(&value)) { if (custom_value->type() == typeid(MessageData)) { - stream->WriteByte(128); + stream->WriteByte(129); WriteValue( EncodableValue( std::any_cast(*custom_value).ToEncodableList()), stream); return; } + if (custom_value->type() == typeid(Code)) { + stream->WriteByte(130); + WriteValue( + EncodableValue(static_cast(std::any_cast(*custom_value))), + stream); + return; + } } flutter::StandardCodecSerializer::WriteValue(value, stream); } @@ -133,7 +149,7 @@ void ExampleHostApiCodecSerializer::WriteValue( /// The codec used by ExampleHostApi. const flutter::StandardMessageCodec& ExampleHostApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &ExampleHostApiCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } // Sets up an instance of `ExampleHostApi` to handle messages through the @@ -282,7 +298,7 @@ MessageFlutterApi::MessageFlutterApi(flutter::BinaryMessenger* binary_messenger, const flutter::StandardMessageCodec& MessageFlutterApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &flutter::StandardCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } void MessageFlutterApi::FlutterMethod( diff --git a/packages/pigeon/example/app/windows/runner/messages.g.h b/packages/pigeon/example/app/windows/runner/messages.g.h index 1b9ca3626cb..84368cbb1df 100644 --- a/packages/pigeon/example/app/windows/runner/messages.g.h +++ b/packages/pigeon/example/app/windows/runner/messages.g.h @@ -89,20 +89,19 @@ class MessageData { static MessageData FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class ExampleHostApi; - friend class ExampleHostApiCodecSerializer; friend class MessageFlutterApi; - friend class MessageFlutterApiCodecSerializer; + friend class PigeonCodecSerializer; std::optional name_; std::optional description_; Code code_; flutter::EncodableMap data_; }; -class ExampleHostApiCodecSerializer : public flutter::StandardCodecSerializer { +class PigeonCodecSerializer : public flutter::StandardCodecSerializer { public: - ExampleHostApiCodecSerializer(); - inline static ExampleHostApiCodecSerializer& GetInstance() { - static ExampleHostApiCodecSerializer sInstance; + PigeonCodecSerializer(); + inline static PigeonCodecSerializer& GetInstance() { + static PigeonCodecSerializer sInstance; return sInstance; } diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index d7bc2139729..b3469b03295 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -515,6 +515,18 @@ class TypeDeclaration { ); } + /// Returns duplicated `TypeDeclaration` with attached `associatedProxyApi` value. + TypeDeclaration copyWithTypeArguments(List types) { + return TypeDeclaration( + baseName: baseName, + isNullable: isNullable, + typeArguments: types, + associatedClass: associatedClass, + associatedEnum: associatedEnum, + associatedProxyApi: associatedProxyApi, + ); + } + @override String toString() { final String typeArgumentsStr = diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 00a156b0c5d..5c42df0b082 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -18,7 +18,10 @@ const DocumentCommentSpecification _docCommentSpec = DocumentCommentSpecification(_commentPrefix); /// The default serializer for Flutter. -const String _defaultCodecSerializer = 'flutter::StandardCodecSerializer'; +const String _standardCodecSerializer = 'flutter::StandardCodecSerializer'; + +/// The name of the codec serializer. +const String _codecSerializerName = 'PigeonCodecSerializer'; /// Options that control how C++ code will be generated. class CppOptions { @@ -47,7 +50,7 @@ class CppOptions { /// `x = CppOptions.fromMap(x.toMap())`. static CppOptions fromMap(Map map) { return CppOptions( - headerIncludePath: map['header'] as String?, + headerIncludePath: map['headerIncludePath'] as String?, namespace: map['namespace'] as String?, copyrightHeader: map['copyrightHeader'] as Iterable?, headerOutPath: map['cppHeaderOut'] as String?, @@ -58,7 +61,7 @@ class CppOptions { /// `x = CppOptions.fromMap(x.toMap())`. Map toMap() { final Map result = { - if (headerIncludePath != null) 'header': headerIncludePath!, + if (headerIncludePath != null) 'headerIncludePath': headerIncludePath!, if (namespace != null) 'namespace': namespace!, if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, }; @@ -332,8 +335,8 @@ class CppHeaderGenerator extends StructuredGenerator { // TODO(gaaclarke): Find a way to be more precise with our // friendships. indent.writeln('friend class ${api.name};'); - indent.writeln('friend class ${_getCodecSerializerName(api)};'); } + indent.writeln('friend class $_codecSerializerName;'); if (testFixtureClass != null) { indent.writeln('friend class $testFixtureClass;'); } @@ -349,6 +352,49 @@ class CppHeaderGenerator extends StructuredGenerator { indent.newln(); } + @override + void writeGeneralCodec( + CppOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + indent.write( + 'class $_codecSerializerName : public $_standardCodecSerializer '); + indent.addScoped('{', '};', () { + _writeAccessBlock(indent, _ClassAccess.public, () { + _writeFunctionDeclaration(indent, _codecSerializerName, + isConstructor: true); + _writeFunctionDeclaration(indent, 'GetInstance', + returnType: '$_codecSerializerName&', + isStatic: true, inlineBody: () { + indent.writeln('static $_codecSerializerName sInstance;'); + indent.writeln('return sInstance;'); + }); + indent.newln(); + _writeFunctionDeclaration(indent, 'WriteValue', + returnType: _voidType, + parameters: [ + 'const flutter::EncodableValue& value', + 'flutter::ByteStreamWriter* stream' + ], + isConst: true, + isOverride: true); + }); + indent.writeScoped(' protected:', '', () { + _writeFunctionDeclaration(indent, 'ReadValueOfType', + returnType: 'flutter::EncodableValue', + parameters: [ + 'uint8_t type', + 'flutter::ByteStreamReader* stream' + ], + isConst: true, + isOverride: true); + }); + }, nestCount: 0); + indent.newln(); + } + @override void writeFlutterApi( CppOptions generatorOptions, @@ -357,9 +403,6 @@ class CppHeaderGenerator extends StructuredGenerator { AstFlutterApi api, { required String dartPackageName, }) { - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(generatorOptions, root, indent, api); - } const List generatedMessages = [ ' Generated class from Pigeon that represents Flutter messages that can be called from C++.' ]; @@ -415,9 +458,6 @@ class CppHeaderGenerator extends StructuredGenerator { AstHostApi api, { required String dartPackageName, }) { - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(generatorOptions, root, indent, api); - } const List generatedMessages = [ ' Generated interface from Pigeon that represents a handler of messages from Flutter.' ]; @@ -521,45 +561,6 @@ class CppHeaderGenerator extends StructuredGenerator { indent.newln(); } - void _writeCodec( - CppOptions generatorOptions, Root root, Indent indent, Api api) { - assert(getCodecClasses(api, root).isNotEmpty); - final String codeSerializerName = _getCodecSerializerName(api); - indent - .write('class $codeSerializerName : public $_defaultCodecSerializer '); - indent.addScoped('{', '};', () { - _writeAccessBlock(indent, _ClassAccess.public, () { - _writeFunctionDeclaration(indent, codeSerializerName, - isConstructor: true); - _writeFunctionDeclaration(indent, 'GetInstance', - returnType: '$codeSerializerName&', isStatic: true, inlineBody: () { - indent.writeln('static $codeSerializerName sInstance;'); - indent.writeln('return sInstance;'); - }); - indent.newln(); - _writeFunctionDeclaration(indent, 'WriteValue', - returnType: _voidType, - parameters: [ - 'const flutter::EncodableValue& value', - 'flutter::ByteStreamWriter* stream' - ], - isConst: true, - isOverride: true); - }); - indent.writeScoped(' protected:', '', () { - _writeFunctionDeclaration(indent, 'ReadValueOfType', - returnType: 'flutter::EncodableValue', - parameters: [ - 'uint8_t type', - 'flutter::ByteStreamReader* stream' - ], - isConst: true, - isOverride: true); - }); - }, nestCount: 0); - indent.newln(); - } - void _writeFlutterError(Indent indent) { indent.format(''' @@ -810,16 +811,14 @@ class CppSourceGenerator extends StructuredGenerator { // Returns the expression to convert the given EncodableValue to a field // value. String getValueExpression(NamedType field, String encodable) { - if (field.type.isEnum) { - return '(${field.type.baseName})(std::get($encodable))'; - } else if (field.type.baseName == 'int') { + if (field.type.baseName == 'int') { return '$encodable.LongValue()'; } else if (field.type.baseName == 'Object') { return encodable; } else { final HostDatatype hostDatatype = getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); - if (field.type.isClass) { + if (field.type.isClass || field.type.isEnum) { return _classReferenceFromEncodableValue(hostDatatype, encodable); } else { return 'std::get<${hostDatatype.datatype}>($encodable)'; @@ -875,6 +874,90 @@ class CppSourceGenerator extends StructuredGenerator { }); } + @override + void writeGeneralCodec( + CppOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final Iterable customTypes = getEnumeratedTypes(root); + indent.newln(); + _writeFunctionDefinition(indent, _codecSerializerName, + scope: _codecSerializerName); + _writeFunctionDefinition(indent, 'ReadValueOfType', + scope: _codecSerializerName, + returnType: 'EncodableValue', + parameters: [ + 'uint8_t type', + 'flutter::ByteStreamReader* stream', + ], + isConst: true, body: () { + if (customTypes.isNotEmpty) { + indent.writeln('switch (type) {'); + indent.inc(); + for (final EnumeratedType customType in customTypes) { + indent.writeln('case ${customType.enumeration}:'); + indent.nest(1, () { + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'return CustomEncodableValue(${customType.name}::FromEncodableList(std::get(ReadValue(stream))));'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeScoped('{', '}', () { + indent.writeln( + 'const auto& encodable_enum_arg = ReadValue(stream);'); + indent.writeln( + 'const int64_t enum_arg_value = encodable_enum_arg.IsNull() ? 0 : encodable_enum_arg.LongValue();'); + indent.writeln( + 'return encodable_enum_arg.IsNull() ? EncodableValue() : CustomEncodableValue(static_cast<${customType.name}>(enum_arg_value));'); + }); + } + }); + } + indent.writeln('default:'); + indent.inc(); + } + indent.writeln( + 'return $_standardCodecSerializer::ReadValueOfType(type, stream);'); + if (customTypes.isNotEmpty) { + indent.dec(); + indent.writeln('}'); + indent.dec(); + } + }); + _writeFunctionDefinition(indent, 'WriteValue', + scope: _codecSerializerName, + returnType: _voidType, + parameters: [ + 'const EncodableValue& value', + 'flutter::ByteStreamWriter* stream', + ], + isConst: true, body: () { + if (customTypes.isNotEmpty) { + indent.write( + 'if (const CustomEncodableValue* custom_value = std::get_if(&value)) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in customTypes) { + indent.write( + 'if (custom_value->type() == typeid(${customType.name})) '); + indent.addScoped('{', '}', () { + indent.writeln('stream->WriteByte(${customType.enumeration});'); + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'WriteValue(EncodableValue(std::any_cast<${customType.name}>(*custom_value).ToEncodableList()), stream);'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeln( + 'WriteValue(EncodableValue(static_cast(std::any_cast<${customType.name}>(*custom_value))), stream);'); + } + indent.writeln('return;'); + }); + } + }); + } + indent.writeln('$_standardCodecSerializer::WriteValue(value, stream);'); + }); + } + @override void writeFlutterApi( CppOptions generatorOptions, @@ -883,9 +966,6 @@ class CppSourceGenerator extends StructuredGenerator { AstFlutterApi api, { required String dartPackageName, }) { - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(generatorOptions, root, indent, api); - } indent.writeln( '$_commentPrefix Generated class from Pigeon that represents Flutter messages that can be called from C++.'); _writeFunctionDefinition( @@ -913,9 +993,6 @@ class CppSourceGenerator extends StructuredGenerator { 'message_channel_suffix_(message_channel_suffix.length() > 0 ? std::string(".") + message_channel_suffix : "")' ], ); - final String codeSerializerName = getCodecClasses(api, root).isNotEmpty - ? _getCodecSerializerName(api) - : _defaultCodecSerializer; _writeFunctionDefinition( indent, 'GetCodec', @@ -923,7 +1000,7 @@ class CppSourceGenerator extends StructuredGenerator { returnType: 'const flutter::StandardMessageCodec&', body: () { indent.writeln( - 'return flutter::StandardMessageCodec::GetInstance(&$codeSerializerName::GetInstance());'); + 'return flutter::StandardMessageCodec::GetInstance(&$_codecSerializerName::GetInstance());'); }, ); for (final Method func in api.methods) { @@ -1023,19 +1100,12 @@ class CppSourceGenerator extends StructuredGenerator { AstHostApi api, { required String dartPackageName, }) { - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(generatorOptions, root, indent, api); - } - - final String codeSerializerName = getCodecClasses(api, root).isNotEmpty - ? _getCodecSerializerName(api) - : _defaultCodecSerializer; indent.writeln('/// The codec used by ${api.name}.'); _writeFunctionDefinition(indent, 'GetCodec', scope: api.name, returnType: 'const flutter::StandardMessageCodec&', body: () { indent.writeln( - 'return flutter::StandardMessageCodec::GetInstance(&$codeSerializerName::GetInstance());'); + 'return flutter::StandardMessageCodec::GetInstance(&$_codecSerializerName::GetInstance());'); }); indent.writeln( '$_commentPrefix Sets up an instance of `${api.name}` to handle messages through the `binary_messenger`.'); @@ -1177,67 +1247,6 @@ return EncodableValue(EncodableList{ }); } - void _writeCodec( - CppOptions generatorOptions, - Root root, - Indent indent, - Api api, - ) { - assert(getCodecClasses(api, root).isNotEmpty); - final String codeSerializerName = _getCodecSerializerName(api); - indent.newln(); - _writeFunctionDefinition(indent, codeSerializerName, - scope: codeSerializerName); - _writeFunctionDefinition(indent, 'ReadValueOfType', - scope: codeSerializerName, - returnType: 'EncodableValue', - parameters: [ - 'uint8_t type', - 'flutter::ByteStreamReader* stream', - ], - isConst: true, body: () { - indent.write('switch (type) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in getCodecClasses(api, root)) { - indent.writeln('case ${customClass.enumeration}:'); - indent.nest(1, () { - indent.writeln( - 'return CustomEncodableValue(${customClass.name}::FromEncodableList(std::get(ReadValue(stream))));'); - }); - } - indent.writeln('default:'); - indent.nest(1, () { - indent.writeln( - 'return $_defaultCodecSerializer::ReadValueOfType(type, stream);'); - }); - }); - }); - _writeFunctionDefinition(indent, 'WriteValue', - scope: codeSerializerName, - returnType: _voidType, - parameters: [ - 'const EncodableValue& value', - 'flutter::ByteStreamWriter* stream', - ], - isConst: true, body: () { - indent.write( - 'if (const CustomEncodableValue* custom_value = std::get_if(&value)) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in getCodecClasses(api, root)) { - indent.write( - 'if (custom_value->type() == typeid(${customClass.name})) '); - indent.addScoped('{', '}', () { - indent.writeln('stream->WriteByte(${customClass.enumeration});'); - indent.writeln( - 'WriteValue(EncodableValue(std::any_cast<${customClass.name}>(*custom_value).ToEncodableList()), stream);'); - indent.writeln('return;'); - }); - } - }); - indent.writeln('$_defaultCodecSerializer::WriteValue(value, stream);'); - }); - } - void _writeClassConstructor(Root root, Indent indent, Class classDefinition, Iterable params) { final Iterable<_HostNamedType> hostParams = params.map((NamedType param) { @@ -1396,10 +1405,6 @@ return EncodableValue(EncodableList{ final String errorGetter; const String nullValue = 'EncodableValue()'; - String enumPrefix = ''; - if (returnType.isEnum) { - enumPrefix = '(int) '; - } if (returnType.isVoid) { nonErrorPath = '${prefix}wrapped.push_back($nullValue);'; errorCondition = 'output.has_value()'; @@ -1409,22 +1414,21 @@ return EncodableValue(EncodableList{ getHostDatatype(returnType, _shortBaseCppTypeForBuiltinDartType); const String extractedValue = 'std::move(output).TakeValue()'; - final String wrapperType = hostType.isBuiltin || returnType.isEnum - ? 'EncodableValue' - : 'CustomEncodableValue'; + final String wrapperType = + hostType.isBuiltin ? 'EncodableValue' : 'CustomEncodableValue'; if (returnType.isNullable) { // The value is a std::optional, so needs an extra layer of // handling. nonErrorPath = ''' ${prefix}auto output_optional = $extractedValue; ${prefix}if (output_optional) { -$prefix\twrapped.push_back($wrapperType(${enumPrefix}std::move(output_optional).value())); +$prefix\twrapped.push_back($wrapperType(std::move(output_optional).value())); $prefix} else { $prefix\twrapped.push_back($nullValue); $prefix}'''; } else { nonErrorPath = - '${prefix}wrapped.push_back($wrapperType($enumPrefix$extractedValue));'; + '${prefix}wrapped.push_back($wrapperType($extractedValue));'; } errorCondition = 'output.has_error()'; errorGetter = 'error'; @@ -1465,17 +1469,12 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; bool isNestedClass, ) { final String encodableValue; - if (!hostType.isBuiltin && - root.classes.any((Class c) => c.name == dartType.baseName)) { - final String nonNullValue = hostType.isNullable || isNestedClass - ? '*$variableName' - : variableName; - encodableValue = 'CustomEncodableValue($nonNullValue)'; - } else if (!hostType.isBuiltin && - root.enums.any((Enum e) => e.name == dartType.baseName)) { + if (!hostType.isBuiltin) { final String nonNullValue = - hostType.isNullable ? '(*$variableName)' : variableName; - encodableValue = 'EncodableValue((int)$nonNullValue)'; + hostType.isNullable || (!hostType.isEnum && isNestedClass) + ? '*$variableName' + : variableName; + encodableValue = 'CustomEncodableValue($nonNullValue)'; } else if (dartType.baseName == 'Object') { final String operator = hostType.isNullable ? '*' : ''; encodableValue = '$operator$variableName'; @@ -1521,18 +1520,13 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; indent.writeln( 'const auto* $argName = std::get_if<${hostType.datatype}>(&$encodableArgName);'); } else if (hostType.isEnum) { - final String valueVarName = '${argName}_value'; - indent.writeln( - 'const int64_t $valueVarName = $encodableArgName.IsNull() ? 0 : $encodableArgName.LongValue();'); - if (apiType == ApiType.flutter) { - indent.writeln( - 'const ${hostType.datatype} enum_$argName = (${hostType.datatype})$valueVarName;'); - indent.writeln( - 'const auto* $argName = $encodableArgName.IsNull() ? nullptr : &enum_$argName;'); - } else { - indent.writeln( - 'const auto $argName = $encodableArgName.IsNull() ? std::nullopt : std::make_optional<${hostType.datatype}>(static_cast<${hostType.datatype}>(${argName}_value));'); - } + indent.format(''' +${hostType.datatype} ${argName}_value; +const ${hostType.datatype}* $argName = nullptr; +if (!$encodableArgName.IsNull()) { + ${argName}_value = ${_classReferenceFromEncodableValue(hostType, encodableArgName)}; + $argName = &${argName}_value; +}'''); } else { indent.writeln( 'const auto* $argName = &(${_classReferenceFromEncodableValue(hostType, encodableArgName)});'); @@ -1555,9 +1549,6 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; } else if (hostType.isBuiltin) { indent.writeln( 'const auto& $argName = std::get<${hostType.datatype}>($encodableArgName);'); - } else if (hostType.isEnum) { - indent.writeln( - 'const ${hostType.datatype}& $argName = (${hostType.datatype})$encodableArgName.LongValue();'); } else { indent.writeln( 'const auto& $argName = ${_classReferenceFromEncodableValue(hostType, encodableArgName)};'); @@ -1599,8 +1590,6 @@ class _IndexedField { final NamedType field; } -String _getCodecSerializerName(Api api) => '${api.name}CodecSerializer'; - const String _encodablePrefix = 'encodable'; String _getArgumentName(int count, NamedType argument) => diff --git a/packages/pigeon/lib/dart/templates.dart b/packages/pigeon/lib/dart/templates.dart index 212a06e7b4f..48c5859dc3d 100644 --- a/packages/pigeon/lib/dart/templates.dart +++ b/packages/pigeon/lib/dart/templates.dart @@ -262,7 +262,7 @@ abstract class $proxyApiBaseClassName { /// adds support to convert instances to their corresponding identifier from an /// `InstanceManager` and vice versa. const String proxyApiBaseCodec = ''' -class $_proxyApiCodecName extends StandardMessageCodec { +class $_proxyApiCodecName extends _PigeonCodec { const $_proxyApiCodecName(this.instanceManager); final $instanceManagerClassName instanceManager; @override diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 5769f09bb65..b5c0e42d365 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -15,14 +15,8 @@ import 'generator_tools.dart'; /// Documentation comment open symbol. const String _docCommentPrefix = '///'; -/// Prefix for all local variables in host API methods. -/// -/// This lowers the chances of variable name collisions with -/// user defined parameters. -const String _varNamePrefix = '__pigeon_'; - /// Name of the variable that contains the message channel suffix for APIs. -const String _suffixVarName = '${_varNamePrefix}messageChannelSuffix'; +const String _suffixVarName = '${varNamePrefix}messageChannelSuffix'; /// Name of the `InstanceManager` variable for a ProxyApi class; const String _instanceManagerVarName = @@ -35,8 +29,8 @@ const String _pigeonChannelCodec = 'pigeonChannelCodec'; const DocumentCommentSpecification _docCommentSpec = DocumentCommentSpecification(_docCommentPrefix); -/// The standard codec for Flutter, used for any non custom codecs and extended for custom codecs. -const String _standardMessageCodec = 'StandardMessageCodec'; +/// The custom codec used for all pigeon APIs. +const String _pigeonCodec = '_PigeonCodec'; /// Options that control how Dart code will be generated. class DartOptions { @@ -229,14 +223,7 @@ class DartGenerator extends StructuredGenerator { indent.addScoped('[', '];', () { for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { - final String conditional = field.type.isNullable ? '?' : ''; - if (field.type.isEnum) { - indent.writeln( - '${field.name}$conditional.index,', - ); - } else { - indent.writeln('${field.name},'); - } + indent.writeln('${field.name},'); } }); }); @@ -256,18 +243,7 @@ class DartGenerator extends StructuredGenerator { final String genericType = _makeGenericTypeArguments(field.type); final String castCall = _makeGenericCastCall(field.type); final String nullableTag = field.type.isNullable ? '?' : ''; - if (field.type.isEnum) { - final String nonNullValue = - '${field.type.baseName}.values[$resultAt! as int]'; - if (field.type.isNullable) { - indent.format(''' -$resultAt != null -\t\t? $nonNullValue -\t\t: null''', leadingSpace: false, trailingNewline: false); - } else { - indent.add(nonNullValue); - } - } else if (field.type.typeArguments.isNotEmpty) { + if (field.type.typeArguments.isNotEmpty) { indent.add( '($resultAt as $genericType?)$castCallPrefix$castCall', ); @@ -300,6 +276,69 @@ $resultAt != null }); } + @override + void writeGeneralCodec( + DartOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + indent.newln(); + final Iterable enumeratedTypes = getEnumeratedTypes(root); + indent.newln(); + indent.write('class $_pigeonCodec extends StandardMessageCodec'); + indent.addScoped(' {', '}', () { + indent.writeln('const $_pigeonCodec();'); + if (enumeratedTypes.isNotEmpty) { + indent.writeln('@override'); + indent.write('void writeValue(WriteBuffer buffer, Object? value) '); + indent.addScoped('{', '}', () { + enumerate(enumeratedTypes, + (int index, final EnumeratedType customType) { + indent.writeScoped('if (value is ${customType.name}) {', '} else ', + () { + indent.writeln('buffer.putUint8(${customType.enumeration});'); + if (customType.type == CustomTypes.customClass) { + indent.writeln('writeValue(buffer, value.encode());'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeln('writeValue(buffer, value.index);'); + } + }, addTrailingNewline: false); + }); + indent.addScoped('{', '}', () { + indent.writeln('super.writeValue(buffer, value);'); + }); + }); + indent.newln(); + indent.writeln('@override'); + indent.write('Object? readValueOfType(int type, ReadBuffer buffer) '); + indent.addScoped('{', '}', () { + indent.write('switch (type) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in enumeratedTypes) { + indent.writeln('case ${customType.enumeration}: '); + indent.nest(1, () { + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'return ${customType.name}.decode(readValue(buffer)!);'); + } else if (customType.type == CustomTypes.customEnum) { + indent + .writeln('final int? value = readValue(buffer) as int?;'); + indent.writeln( + 'return value == null ? null : ${customType.name}.values[value];'); + } + }); + } + indent.writeln('default:'); + indent.nest(1, () { + indent.writeln('return super.readValueOfType(type, buffer);'); + }); + }); + }); + } + }); + } + /// Writes the code for host [Api], [api]. /// Example: /// class FooCodec extends StandardMessageCodec {...} @@ -319,11 +358,6 @@ $resultAt != null bool isMockHandler = false, required String dartPackageName, }) { - String codecName = _standardMessageCodec; - if (getCodecClasses(api, root).isNotEmpty) { - codecName = _getCodecName(api); - _writeCodec(indent, codecName, api, root); - } indent.newln(); addDocumentationComments( indent, api.documentationComments, _docCommentSpec); @@ -335,7 +369,7 @@ $resultAt != null 'static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance;'); } indent.writeln( - 'static const MessageCodec $_pigeonChannelCodec = $codecName();'); + 'static const MessageCodec $_pigeonChannelCodec = $_pigeonCodec();'); indent.newln(); for (final Method func in api.methods) { addDocumentationComments( @@ -399,11 +433,6 @@ $resultAt != null AstHostApi api, { required String dartPackageName, }) { - String codecName = _standardMessageCodec; - if (getCodecClasses(api, root).isNotEmpty) { - codecName = _getCodecName(api); - _writeCodec(indent, codecName, api, root); - } indent.newln(); bool first = true; addDocumentationComments( @@ -415,13 +444,13 @@ $resultAt != null /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. ${api.name}({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : ${_varNamePrefix}binaryMessenger = binaryMessenger, - ${_varNamePrefix}messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.\$messageChannelSuffix' : ''; -final BinaryMessenger? ${_varNamePrefix}binaryMessenger; + : ${varNamePrefix}binaryMessenger = binaryMessenger, + ${varNamePrefix}messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.\$messageChannelSuffix' : ''; +final BinaryMessenger? ${varNamePrefix}binaryMessenger; '''); indent.writeln( - 'static const MessageCodec $_pigeonChannelCodec = $codecName();'); + 'static const MessageCodec $_pigeonChannelCodec = $_pigeonCodec();'); indent.newln(); indent.writeln('final String $_suffixVarName;'); indent.newln(); @@ -822,6 +851,8 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; relativeDartPath.replaceFirst(RegExp(r'^.*/lib/'), ''); indent.writeln("import 'package:$dartOutputPackageName/$path';"); } + writeGeneralCodec(generatorOptions, root, indent, + dartPackageName: dartPackageName); for (final AstHostApi api in root.apis.whereType()) { if (api.dartHostTestHandler != null) { final AstFlutterApi mockApi = AstFlutterApi( @@ -961,18 +992,14 @@ PlatformException _createConnectionError(String channelName) { final Iterable argExpressions = indexMap(parameters, (int index, NamedType type) { final String name = _getParameterName(index, type); - if (type.type.isEnum) { - return '$name${type.type.isNullable ? '?' : ''}.index'; - } else { - return name; - } + return name; }); sendArgument = '[${argExpressions.join(', ')}]'; } final String channelSuffix = addSuffixVariable ? '\$$_suffixVarName' : ''; final String constOrFinal = addSuffixVariable ? 'final' : 'const'; indent.writeln( - "$constOrFinal String ${_varNamePrefix}channelName = '$channelName$channelSuffix';"); + "$constOrFinal String ${varNamePrefix}channelName = '$channelName$channelSuffix';"); indent.writeScoped( 'final BasicMessageChannel ${varNamePrefix}channel = BasicMessageChannel(', ');', () { @@ -990,15 +1017,7 @@ PlatformException _createConnectionError(String channelName) { final String nullHandler = returnType.isNullable ? (genericCastCall.isEmpty ? '' : '?') : '!'; String returnStatement = 'return'; - if (returnType.isEnum) { - if (returnType.isNullable) { - returnStatement = - '$returnStatement ($accessor as int?) == null ? null : $returnTypeName.values[$accessor! as int]'; - } else { - returnStatement = - '$returnStatement $returnTypeName.values[$accessor! as int]'; - } - } else if (!returnType.isVoid) { + if (!returnType.isVoid) { returnStatement = '$returnStatement $nullablyTypedAccessor$nullHandler$genericCastCall'; } @@ -1094,13 +1113,10 @@ if (${varNamePrefix}replyList == null) { final String castCall = _makeGenericCastCall(arg.type); final String leftHandSide = 'final $argType? $argName'; - if (arg.type.isEnum) { - indent.writeln( - '$leftHandSide = $argsArray[$count] == null ? null : $argType.values[$argsArray[$count]! as int];'); - } else { - indent.writeln( - '$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); - } + + indent.writeln( + '$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); + if (!arg.type.isNullable) { indent.writeln('assert($argName != null,'); indent.writeln( @@ -1130,12 +1146,9 @@ if (${varNamePrefix}replyList == null) { } const String returnExpression = 'output'; - final String nullability = returnType.isNullable ? '?' : ''; - final String valueExtraction = - returnType.isEnum ? '$nullability.index' : ''; final String returnStatement = isMockHandler - ? 'return [$returnExpression$valueExtraction];' - : 'return wrapResponse(result: $returnExpression$valueExtraction);'; + ? 'return [$returnExpression];' + : 'return wrapResponse(result: $returnExpression);'; indent.writeln(returnStatement); } }, addTrailingNewline: false); @@ -1980,60 +1993,6 @@ String _escapeForDartSingleQuotedString(String raw) { .replaceAll(r"'", r"\'"); } -/// Calculates the name of the codec class that will be generated for [api]. -String _getCodecName(Api api) => '_${api.name}Codec'; - -/// Writes the codec that will be used by [api]. -/// Example: -/// -/// class FooCodec extends StandardMessageCodec {...} -void _writeCodec(Indent indent, String codecName, Api api, Root root) { - assert(getCodecClasses(api, root).isNotEmpty); - final Iterable codecClasses = getCodecClasses(api, root); - indent.newln(); - indent.write('class $codecName extends $_standardMessageCodec'); - indent.addScoped(' {', '}', () { - indent.writeln('const $codecName();'); - indent.writeln('@override'); - indent.write('void writeValue(WriteBuffer buffer, Object? value) '); - indent.addScoped('{', '}', () { - enumerate(codecClasses, (int index, final EnumeratedClass customClass) { - final String ifValue = 'if (value is ${customClass.name}) '; - if (index == 0) { - indent.write(''); - } - indent.add(ifValue); - indent.addScoped('{', '} else ', () { - indent.writeln('buffer.putUint8(${customClass.enumeration});'); - indent.writeln('writeValue(buffer, value.encode());'); - }, addTrailingNewline: false); - }); - indent.addScoped('{', '}', () { - indent.writeln('super.writeValue(buffer, value);'); - }); - }); - indent.newln(); - indent.writeln('@override'); - indent.write('Object? readValueOfType(int type, ReadBuffer buffer) '); - indent.addScoped('{', '}', () { - indent.write('switch (type) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.writeln('case ${customClass.enumeration}: '); - indent.nest(1, () { - indent.writeln( - 'return ${customClass.name}.decode(readValue(buffer)!);'); - }); - } - indent.writeln('default:'); - indent.nest(1, () { - indent.writeln('return super.readValueOfType(type, buffer);'); - }); - }); - }); - }); -} - /// Creates a Dart type where all type arguments are [Objects]. String _makeGenericTypeArguments(TypeDeclaration type) { return type.typeArguments.isNotEmpty diff --git a/packages/pigeon/lib/generator.dart b/packages/pigeon/lib/generator.dart index 3711fd28dbe..952b80e8987 100644 --- a/packages/pigeon/lib/generator.dart +++ b/packages/pigeon/lib/generator.dart @@ -95,6 +95,13 @@ abstract class StructuredGenerator extends Generator { dartPackageName: dartPackageName, ); + writeGeneralCodec( + generatorOptions, + root, + indent, + dartPackageName: dartPackageName, + ); + writeApis( generatorOptions, root, @@ -205,6 +212,14 @@ abstract class StructuredGenerator extends Generator { } } + /// Writes the custom codec to [indent]. + void writeGeneralCodec( + T generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }); + /// Writes a single data class to [indent]. void writeDataClass( T generatorOptions, diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index a02efc0fe84..415113c7ff7 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '19.0.2'; +const String pigeonVersion = '20.0.0'; /// Prefix for all local variables in methods. /// @@ -37,7 +37,7 @@ bool debugGenerators = false; /// A helper class for managing indentation, wrapping a [StringSink]. class Indent { - /// Constructor which takes a [StringSink] [Ident] will wrap. + /// Constructor which takes a [StringSink] [Indent] will wrap. Indent(this._sink); int _count = 0; @@ -381,16 +381,26 @@ Map mergeMaps( return result; } -/// A class name that is enumerated. -class EnumeratedClass { +/// A type name that is enumerated. +class EnumeratedType { /// Constructor. - EnumeratedClass(this.name, this.enumeration); + EnumeratedType(this.name, this.enumeration, this.type, + {this.associatedClass, this.associatedEnum}); - /// The name of the class. + /// The name of the type. final String name; /// The enumeration of the class. final int enumeration; + + /// The type of custom type of the enumerated type. + final CustomTypes type; + + /// The associated Class that is represented by the [EnumeratedType]. + final Class? associatedClass; + + /// The associated Enum that is represented by the [EnumeratedType]. + final Enum? associatedEnum; } /// Supported basic datatypes. @@ -410,7 +420,7 @@ const List validTypes = [ /// Custom codecs' custom types are enumerated from 255 down to this number to /// avoid collisions with the StandardMessageCodec. -const int _minimumCodecFieldKey = 128; +const int _minimumCodecFieldKey = 129; Iterable _getTypeArguments(TypeDeclaration type) sync* { for (final TypeDeclaration typeArg in type.typeArguments) { @@ -494,39 +504,42 @@ Map> getReferencedTypes( return references.map; } -/// Returns true if the concrete type cannot be determined at compile-time. -bool _isConcreteTypeAmbiguous(TypeDeclaration type) { - return (type.baseName == 'List' && type.typeArguments.isEmpty) || - (type.baseName == 'Map' && type.typeArguments.isEmpty) || - type.baseName == 'Object'; +/// All custom definable data types. +enum CustomTypes { + /// A custom Class. + customClass, + + /// A custom Enum. + customEnum, } -/// Given an [Api], return the enumerated classes that must exist in the codec +/// Return the enumerated types that must exist in the codec /// where the enumeration should be the key used in the buffer. -Iterable getCodecClasses(Api api, Root root) sync* { - final Set enumNames = root.enums.map((Enum e) => e.name).toSet(); - final Map> referencedTypes = - getReferencedTypes([api], root.classes); - final Iterable allTypeNames = - referencedTypes.keys.any(_isConcreteTypeAmbiguous) - ? root.classes.map((Class aClass) => aClass.name) - : referencedTypes.keys.map((TypeDeclaration e) => e.baseName); - final List sortedNames = allTypeNames - .where((String element) => - element != 'void' && - !validTypes.contains(element) && - !enumNames.contains(element)) - .toList(); - sortedNames.sort(); - int enumeration = _minimumCodecFieldKey; +Iterable getEnumeratedTypes(Root root) sync* { const int maxCustomClassesPerApi = 255 - _minimumCodecFieldKey; - if (sortedNames.length > maxCustomClassesPerApi) { + if (root.classes.length + root.enums.length > maxCustomClassesPerApi) { throw Exception( - "Pigeon doesn't support more than $maxCustomClassesPerApi referenced custom classes per API, try splitting up your APIs."); + "Pigeon doesn't currently support more than $maxCustomClassesPerApi referenced custom classes per file."); + } + int index = 0; + for (final Class customClass in root.classes) { + yield EnumeratedType( + customClass.name, + index + _minimumCodecFieldKey, + CustomTypes.customClass, + associatedClass: customClass, + ); + index += 1; } - for (final String name in sortedNames) { - yield EnumeratedClass(name, enumeration); - enumeration += 1; + + for (final Enum customEnum in root.enums) { + yield EnumeratedType( + customEnum.name, + index + _minimumCodecFieldKey, + CustomTypes.customEnum, + associatedEnum: customEnum, + ); + index += 1; } } @@ -685,3 +698,13 @@ class OutputFileOptions { /// Options for specified language across all file types. T languageOptions; } + +/// Converts strings to Upper Camel Case. +String toUpperCamelCase(String text) { + final RegExp separatorPattern = RegExp(r'[ _-]'); + return text.split(separatorPattern).map((String word) { + return word.isEmpty + ? '' + : word.substring(0, 1).toUpperCase() + word.substring(1); + }).join(); +} diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index f8e15bb24f9..55622995b71 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -26,7 +26,7 @@ const DocumentCommentSpecification _docCommentSpec = ); /// The standard codec for Flutter, used for any non custom codecs and extended for custom codecs. -const String _standardMessageCodec = 'StandardMessageCodec'; +const String _codecName = 'PigeonCodec'; /// Options that control how Java code will be generated. class JavaOptions { @@ -339,14 +339,7 @@ class JavaGenerator extends StructuredGenerator { 'ArrayList toListResult = new ArrayList(${classDefinition.fields.length});'); for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { - String toWriteValue = ''; - final String fieldName = field.name; - if (field.type.isEnum) { - toWriteValue = '$fieldName == null ? null : $fieldName.index'; - } else { - toWriteValue = field.name; - } - indent.writeln('toListResult.add($toWriteValue);'); + indent.writeln('toListResult.add(${field.name});'); } indent.writeln('return toListResult;'); }); @@ -373,18 +366,86 @@ class JavaGenerator extends StructuredGenerator { final String setter = _makeSetter(field); indent.writeln( 'Object $fieldVariable = ${varNamePrefix}list.get($index);'); - if (field.type.isEnum) { - indent.writeln( - '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName, field.type.isNullable)});'); - } else { - indent.writeln( - '$result.$setter(${_castObject(field, fieldVariable)});'); - } + indent + .writeln('$result.$setter(${_castObject(field, fieldVariable)});'); }); indent.writeln('return $result;'); }); } + @override + void writeGeneralCodec( + JavaOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final Iterable enumeratedTypes = getEnumeratedTypes(root); + indent.newln(); + indent.write( + 'private static class $_codecName extends StandardMessageCodec '); + indent.addScoped('{', '}', () { + indent.writeln( + 'public static final $_codecName INSTANCE = new $_codecName();'); + indent.newln(); + indent.writeln('private $_codecName() {}'); + indent.newln(); + indent.writeln('@Override'); + indent.write( + 'protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) '); + indent.addScoped('{', '}', () { + indent.write('switch (type) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in enumeratedTypes) { + indent.writeln('case (byte) ${customType.enumeration}:'); + indent.nest(1, () { + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'return ${customType.name}.fromList((ArrayList) readValue(buffer));'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeln('Object value = readValue(buffer);'); + indent.writeln( + 'return ${_intToEnum('value', customType.name, true)};'); + } + }); + } + indent.writeln('default:'); + indent.nest(1, () { + indent.writeln('return super.readValueOfType(type, buffer);'); + }); + }); + }); + indent.newln(); + indent.writeln('@Override'); + indent.write( + 'protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) '); + indent.addScoped('{', '}', () { + bool firstClass = true; + for (final EnumeratedType customType in enumeratedTypes) { + if (firstClass) { + indent.write(''); + firstClass = false; + } + indent.add('if (value instanceof ${customType.name}) '); + indent.addScoped('{', '} else ', () { + indent.writeln('stream.write(${customType.enumeration});'); + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'writeValue(stream, ((${customType.name}) value).toList());'); + } else { + indent.writeln( + 'writeValue(stream, value == null ? null : ((${customType.name}) value).index);'); + } + }, addTrailingNewline: false); + } + indent.addScoped('{', '}', () { + indent.writeln('super.writeValue(stream, value);'); + }); + }); + }); + indent.newln(); + } + /// Writes the code for a flutter [Api], [api]. /// Example: /// public static final class Foo { @@ -402,20 +463,11 @@ class JavaGenerator extends StructuredGenerator { AstFlutterApi api, { required String dartPackageName, }) { - /// Returns an argument name that can be used in a context where it is possible to collide - /// and append `.index` to enums. - String getEnumSafeArgumentExpression(int count, NamedType argument) { - if (argument.type.isEnum) { - return argument.type.isNullable - ? '${_getArgumentName(count, argument)}Arg == null ? null : ${_getArgumentName(count, argument)}Arg.index' - : '${_getArgumentName(count, argument)}Arg.index'; - } + /// Returns an argument name that can be used in a context where it is possible to collide. + String getSafeArgumentExpression(int count, NamedType argument) { return '${_getArgumentName(count, argument)}Arg'; } - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(indent, api, root); - } const List generatedMessages = [ ' Generated class from Pigeon that represents Flutter messages that can be called from Java.' ]; @@ -441,16 +493,10 @@ class JavaGenerator extends StructuredGenerator { }); indent.newln(); indent.writeln('/** Public interface for sending reply. */ '); - final String codecName = _getCodecName(api); indent.writeln('/** The codec used by ${api.name}. */'); indent.write('static @NonNull MessageCodec getCodec() '); indent.addScoped('{', '}', () { - indent.write('return '); - if (getCodecClasses(api, root).isNotEmpty) { - indent.addln('$codecName.INSTANCE;'); - } else { - indent.addln('new $_standardMessageCodec();'); - } + indent.writeln('return $_codecName.INSTANCE;'); }); for (final Method func in api.methods) { @@ -471,7 +517,7 @@ class JavaGenerator extends StructuredGenerator { final Iterable argNames = indexMap(func.parameters, _getSafeArgumentName); final Iterable enumSafeArgNames = - indexMap(func.parameters, getEnumSafeArgumentExpression); + indexMap(func.parameters, getSafeArgumentExpression); if (func.parameters.length == 1) { sendArgument = 'new ArrayList(Collections.singletonList(${enumSafeArgNames.first}))'; @@ -526,14 +572,6 @@ class JavaGenerator extends StructuredGenerator { if (func.returnType.baseName == 'int') { outputExpression = 'listReply.get(0) == null ? null : ((Number) listReply.get(0)).longValue();'; - } else if (func.returnType.isEnum) { - if (func.returnType.isNullable) { - outputExpression = - 'listReply.get(0) == null ? null : $returnType.values()[(int) listReply.get(0)];'; - } else { - outputExpression = - '$returnType.values()[(int) listReply.get(0)];'; - } } else { outputExpression = '${_cast('listReply.get(0)', javaType: returnType)};'; @@ -586,9 +624,6 @@ class JavaGenerator extends StructuredGenerator { AstHostApi api, { required String dartPackageName, }) { - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(indent, api, root); - } const List generatedMessages = [ ' Generated interface from Pigeon that represents a handler of messages from Flutter.' ]; @@ -601,16 +636,10 @@ class JavaGenerator extends StructuredGenerator { _writeInterfaceMethod(generatorOptions, root, indent, api, method); } indent.newln(); - final String codecName = _getCodecName(api); indent.writeln('/** The codec used by ${api.name}. */'); indent.write('static @NonNull MessageCodec getCodec() '); indent.addScoped('{', '}', () { - indent.write('return '); - if (getCodecClasses(api, root).isNotEmpty) { - indent.addln('$codecName.INSTANCE;'); - } else { - indent.addln('new $_standardMessageCodec();'); - } + indent.writeln('return $_codecName.INSTANCE;'); }); indent.writeln( @@ -716,7 +745,6 @@ class JavaGenerator extends StructuredGenerator { indent.nest(2, () { indent.write('(message, reply) -> '); indent.addScoped('{', '});', () { - String enumTag = ''; final String returnType = method.returnType.isVoid ? 'Void' : _javaTypeForDartType(method.returnType); @@ -738,10 +766,7 @@ class JavaGenerator extends StructuredGenerator { ? '($argName == null) ? null : $argName.longValue()' : argName; String accessor = 'args.get($index)'; - if (arg.type.isEnum) { - accessor = _intToEnum( - accessor, arg.type.baseName, arg.type.isNullable); - } else if (argType != 'Object') { + if (argType != 'Object') { accessor = _cast(accessor, javaType: argType); } indent.writeln('$argType $argName = $accessor;'); @@ -751,16 +776,11 @@ class JavaGenerator extends StructuredGenerator { if (method.isAsynchronous) { final String resultValue = method.returnType.isVoid ? 'null' : 'result'; - if (method.returnType.isEnum) { - enumTag = method.returnType.isNullable - ? ' == null ? null : $resultValue.index' - : '.index'; - } final String resultType = _getResultType(method.returnType); final String resultParam = method.returnType.isVoid ? '' : '$returnType result'; final String addResultArg = - method.returnType.isVoid ? 'null' : '$resultValue$enumTag'; + method.returnType.isVoid ? 'null' : resultValue; const String resultName = 'resultCallback'; indent.format(''' $resultType $resultName = @@ -789,13 +809,8 @@ $resultType $resultName = indent.writeln('$call;'); indent.writeln('wrapped.add(0, null);'); } else { - if (method.returnType.isEnum) { - enumTag = method.returnType.isNullable - ? ' == null ? null : output.index' - : '.index'; - } indent.writeln('$returnType output = $call;'); - indent.writeln('wrapped.add(0, output$enumTag);'); + indent.writeln('wrapped.add(0, output);'); } }); indent.add(' catch (Throwable exception) '); @@ -819,67 +834,6 @@ $resultType $resultName = }); } - /// Writes the codec class that will be used by [api]. - /// Example: - /// private static class FooCodec extends StandardMessageCodec {...} - void _writeCodec(Indent indent, Api api, Root root) { - assert(getCodecClasses(api, root).isNotEmpty); - final Iterable codecClasses = getCodecClasses(api, root); - final String codecName = _getCodecName(api); - indent.newln(); - indent.write( - 'private static class $codecName extends $_standardMessageCodec '); - indent.addScoped('{', '}', () { - indent.writeln( - 'public static final $codecName INSTANCE = new $codecName();'); - indent.newln(); - indent.writeln('private $codecName() {}'); - indent.newln(); - indent.writeln('@Override'); - indent.write( - 'protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) '); - indent.addScoped('{', '}', () { - indent.write('switch (type) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.writeln('case (byte) ${customClass.enumeration}:'); - indent.nest(1, () { - indent.writeln( - 'return ${customClass.name}.fromList((ArrayList) readValue(buffer));'); - }); - } - indent.writeln('default:'); - indent.nest(1, () { - indent.writeln('return super.readValueOfType(type, buffer);'); - }); - }); - }); - indent.newln(); - indent.writeln('@Override'); - indent.write( - 'protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) '); - indent.addScoped('{', '}', () { - bool firstClass = true; - for (final EnumeratedClass customClass in codecClasses) { - if (firstClass) { - indent.write(''); - firstClass = false; - } - indent.add('if (value instanceof ${customClass.name}) '); - indent.addScoped('{', '} else ', () { - indent.writeln('stream.write(${customClass.enumeration});'); - indent.writeln( - 'writeValue(stream, ((${customClass.name}) value).toList());'); - }, addTrailingNewline: false); - } - indent.addScoped('{', '}', () { - indent.writeln('super.writeValue(stream, value);'); - }); - }); - }); - indent.newln(); - } - void _writeResultInterfaces(Indent indent) { indent.writeln( '/** Asynchronous error handling return type for non-nullable API method returns. */'); @@ -1026,9 +980,6 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { } } -/// Calculates the name of the codec that will be generated for [api]. -String _getCodecName(Api api) => '${api.name}Codec'; - /// Converts an expression that evaluates to an nullable int to an expression /// that evaluates to a nullable enum. String _intToEnum(String expression, String enumName, bool nullable) => nullable diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index e805034ee2c..1d827aff164 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -25,6 +25,8 @@ const DocumentCommentSpecification _docCommentSpec = blockContinuationToken: _docCommentContinuation, ); +String _codecName = 'PigeonCodec'; + /// Options that control how Kotlin code will be generated. class KotlinOptions { /// Creates a [KotlinOptions] object @@ -33,6 +35,7 @@ class KotlinOptions { this.copyrightHeader, this.errorClassName, this.includeErrorClass = true, + this.fileSpecificClassNameComponent, }); /// The package where the generated class will live. @@ -50,6 +53,9 @@ class KotlinOptions { /// Kotlin file in the same directory. final bool includeErrorClass; + /// A String to augment class names to avoid cross file collisions. + final String? fileSpecificClassNameComponent; + /// Creates a [KotlinOptions] from a Map representation where: /// `x = KotlinOptions.fromMap(x.toMap())`. static KotlinOptions fromMap(Map map) { @@ -58,6 +64,8 @@ class KotlinOptions { copyrightHeader: map['copyrightHeader'] as Iterable?, errorClassName: map['errorClassName'] as String?, includeErrorClass: map['includeErrorClass'] as bool? ?? true, + fileSpecificClassNameComponent: + map['fileSpecificClassNameComponent'] as String?, ); } @@ -69,6 +77,8 @@ class KotlinOptions { if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, if (errorClassName != null) 'errorClassName': errorClassName!, 'includeErrorClass': includeErrorClass, + if (fileSpecificClassNameComponent != null) + 'fileSpecificClassNameComponent': fileSpecificClassNameComponent!, }; return result; } @@ -216,19 +226,12 @@ class KotlinGenerator extends StructuredGenerator { }) { indent.write('fun toList(): List '); indent.addScoped('{', '}', () { - indent.write('return listOf'); + indent.write('return listOf'); indent.addScoped('(', ')', () { for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { - String toWriteValue = ''; final String fieldName = field.name; - final String safeCall = field.type.isNullable ? '?' : ''; - if (field.type.isEnum) { - toWriteValue = '$fieldName$safeCall.raw'; - } else { - toWriteValue = fieldName; - } - indent.writeln('$toWriteValue,'); + indent.writeln('$fieldName,'); } }); }); @@ -254,28 +257,8 @@ class KotlinGenerator extends StructuredGenerator { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { final String listValue = '${varNamePrefix}list[$index]'; - final String fieldType = _kotlinTypeForDartType(field.type); - - if (field.type.isNullable) { - if (field.type.isEnum) { - indent.write('val ${field.name}: $fieldType? = '); - indent.add('($listValue as Int?)?.let '); - indent.addScoped('{ num ->', '}', () { - indent.writeln('$fieldType.ofRaw(num)'); - }); - } else { - indent.writeln( - 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); - } - } else { - if (field.type.isEnum) { - indent.writeln( - 'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!'); - } else { - indent.writeln( - 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); - } - } + indent.writeln( + 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); }); indent.write('return $className('); @@ -317,6 +300,75 @@ class KotlinGenerator extends StructuredGenerator { dartPackageName: dartPackageName); } + @override + void writeGeneralCodec( + KotlinOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final Iterable enumeratedTypes = getEnumeratedTypes(root); + indent.write( + 'private object ${generatorOptions.fileSpecificClassNameComponent}$_codecName : StandardMessageCodec() '); + indent.addScoped('{', '}', () { + indent.write( + 'override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? '); + indent.addScoped('{', '}', () { + indent.write('return '); + if (root.classes.isNotEmpty || root.enums.isNotEmpty) { + indent.add('when (type) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in enumeratedTypes) { + indent.write('${customType.enumeration}.toByte() -> '); + indent.addScoped('{', '}', () { + if (customType.type == CustomTypes.customClass) { + indent + .write('return (readValue(buffer) as? List)?.let '); + indent.addScoped('{', '}', () { + indent.writeln('${customType.name}.fromList(it)'); + }); + } else if (customType.type == CustomTypes.customEnum) { + indent.write('return (readValue(buffer) as Int?)?.let '); + indent.addScoped('{', '}', () { + indent.writeln('${customType.name}.ofRaw(it)'); + }); + } + }); + } + indent.writeln('else -> super.readValueOfType(type, buffer)'); + }); + } else { + indent.writeln('super.readValueOfType(type, buffer)'); + } + }); + + indent.write( + 'override fun writeValue(stream: ByteArrayOutputStream, value: Any?) '); + indent.writeScoped('{', '}', () { + if (root.classes.isNotEmpty || root.enums.isNotEmpty) { + indent.write('when (value) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in enumeratedTypes) { + indent.write('is ${customType.name} -> '); + indent.addScoped('{', '}', () { + indent.writeln('stream.write(${customType.enumeration})'); + if (customType.type == CustomTypes.customClass) { + indent.writeln('writeValue(stream, value.toList())'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeln('writeValue(stream, value.raw)'); + } + }); + } + indent.writeln('else -> super.writeValue(stream, value)'); + }); + } else { + indent.writeln('super.writeValue(stream, value)'); + } + }); + }); + indent.newln(); + } + /// Writes the code for a flutter [Api], [api]. /// Example: /// class Foo(private val binaryMessenger: BinaryMessenger) { @@ -330,11 +382,6 @@ class KotlinGenerator extends StructuredGenerator { AstFlutterApi api, { required String dartPackageName, }) { - final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; - if (isCustomCodec) { - _writeCodec(indent, api, root); - } - const List generatedMessages = [ ' Generated class from Pigeon that represents Flutter messages that can be called from Kotlin.' ]; @@ -350,11 +397,8 @@ class KotlinGenerator extends StructuredGenerator { indent.writeln('/** The codec used by $apiName. */'); indent.write('val codec: MessageCodec by lazy '); indent.addScoped('{', '}', () { - if (isCustomCodec) { - indent.writeln(_getCodecName(api)); - } else { - indent.writeln('StandardMessageCodec()'); - } + indent.writeln( + '${generatorOptions.fileSpecificClassNameComponent}$_codecName'); }); }); @@ -392,11 +436,6 @@ class KotlinGenerator extends StructuredGenerator { }) { final String apiName = api.name; - final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; - if (isCustomCodec) { - _writeCodec(indent, api, root); - } - const List generatedMessages = [ ' Generated interface from Pigeon that represents a handler of messages from Flutter.' ]; @@ -422,11 +461,8 @@ class KotlinGenerator extends StructuredGenerator { indent.writeln('/** The codec used by $apiName. */'); indent.write('val codec: MessageCodec by lazy '); indent.addScoped('{', '}', () { - if (isCustomCodec) { - indent.writeln(_getCodecName(api)); - } else { - indent.writeln('StandardMessageCodec()'); - } + indent.writeln( + '${generatorOptions.fileSpecificClassNameComponent}$_codecName'); }); indent.writeln( '/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */'); @@ -453,52 +489,6 @@ class KotlinGenerator extends StructuredGenerator { }); } - /// Writes the codec class that will be used by [api]. - /// Example: - /// private static class FooCodec extends StandardMessageCodec {...} - void _writeCodec(Indent indent, Api api, Root root) { - assert(getCodecClasses(api, root).isNotEmpty); - final Iterable codecClasses = getCodecClasses(api, root); - final String codecName = _getCodecName(api); - indent.write('private object $codecName : StandardMessageCodec() '); - indent.addScoped('{', '}', () { - indent.write( - 'override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? '); - indent.addScoped('{', '}', () { - indent.write('return when (type) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.write('${customClass.enumeration}.toByte() -> '); - indent.addScoped('{', '}', () { - indent.write('return (readValue(buffer) as? List)?.let '); - indent.addScoped('{', '}', () { - indent.writeln('${customClass.name}.fromList(it)'); - }); - }); - } - indent.writeln('else -> super.readValueOfType(type, buffer)'); - }); - }); - - indent.write( - 'override fun writeValue(stream: ByteArrayOutputStream, value: Any?) '); - indent.writeScoped('{', '}', () { - indent.write('when (value) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.write('is ${customClass.name} -> '); - indent.addScoped('{', '}', () { - indent.writeln('stream.write(${customClass.enumeration})'); - indent.writeln('writeValue(stream, value.toList())'); - }); - } - indent.writeln('else -> super.writeValue(stream, value)'); - }); - }); - }); - indent.newln(); - } - void _writeWrapResult(Indent indent) { indent.newln(); indent.write('private fun wrapResult(result: Any?): List '); @@ -693,25 +683,21 @@ class KotlinGenerator extends StructuredGenerator { : 'api.$name(${methodArguments.join(', ')})'; if (isAsynchronous) { - indent.write('$call '); final String resultType = returnType.isVoid ? 'Unit' : _nullSafeKotlinTypeForDartType(returnType); + indent.write(methodArguments.isNotEmpty ? '$call ' : 'api.$name'); indent.addScoped('{ result: Result<$resultType> ->', '}', () { indent.writeln('val error = result.exceptionOrNull()'); indent.writeScoped('if (error != null) {', '}', () { indent.writeln('reply.reply(wrapError(error))'); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { - final String enumTagNullablePrefix = - returnType.isNullable ? '?' : '!!'; - final String enumTag = - returnType.isEnum ? '$enumTagNullablePrefix.raw' : ''; if (returnType.isVoid) { indent.writeln('reply.reply(wrapResult(null))'); } else { indent.writeln('val data = result.getOrNull()'); - indent.writeln('reply.reply(wrapResult(data$enumTag))'); + indent.writeln('reply.reply(wrapResult(data))'); } }); }); @@ -719,14 +705,9 @@ class KotlinGenerator extends StructuredGenerator { indent.writeScoped('val wrapped: List = try {', '}', () { if (returnType.isVoid) { indent.writeln(call); - indent.writeln('listOf(null)'); + indent.writeln('listOf(null)'); } else { - String enumTag = ''; - if (returnType.isEnum) { - final String safeUnwrap = returnType.isNullable ? '?' : ''; - enumTag = '$safeUnwrap.raw'; - } - indent.writeln('listOf($call$enumTag)'); + indent.writeln('listOf($call)'); } }, addTrailingNewline: false); indent.add(' catch (exception: Throwable) '); @@ -819,18 +800,10 @@ class KotlinGenerator extends StructuredGenerator { if (returnType.isVoid) { indent.writeln('callback(Result.success(Unit))'); } else { - const String output = 'output'; - // Nullable enums require special handling. - if (returnType.isEnum && returnType.isNullable) { - indent.writeScoped( - 'val $output = (it[0] as Int?)?.let { num ->', '}', () { - indent.writeln('${returnType.baseName}.ofRaw(num)'); - }); - } else { - indent.writeln( - 'val $output = ${_cast(indent, 'it[0]', type: returnType)}'); - } - indent.writeln('callback(Result.success($output))'); + indent.writeln( + 'val output = ${_cast(indent, 'it[0]', type: returnType)}'); + + indent.writeln('callback(Result.success(output))'); } }); }, addTrailingNewline: false); @@ -842,9 +815,6 @@ class KotlinGenerator extends StructuredGenerator { } } -/// Calculates the name of the codec that will be generated for [api]. -String _getCodecName(Api api) => '${api.name}Codec'; - String _getErrorClassName(KotlinOptions generatorOptions) => generatorOptions.errorClassName ?? 'FlutterError'; @@ -854,11 +824,6 @@ String _getArgumentName(int count, NamedType argument) => /// Returns an argument name that can be used in a context where it is possible to collide /// and append `.index` to enums. String _getEnumSafeArgumentExpression(int count, NamedType argument) { - if (argument.type.isEnum) { - return argument.type.isNullable - ? '${_getArgumentName(count, argument)}Arg?.raw' - : '${_getArgumentName(count, argument)}Arg.raw'; - } return '${_getArgumentName(count, argument)}Arg'; } @@ -867,14 +832,7 @@ String _getSafeArgumentName(int count, NamedType argument) => '${_getArgumentName(count, argument)}Arg'; String _castForceUnwrap(String value, TypeDeclaration type, Indent indent) { - if (type.isEnum) { - final String forceUnwrap = type.isNullable ? '' : '!!'; - final String nullableConditionPrefix = - type.isNullable ? 'if ($value == null) null else ' : ''; - return '$nullableConditionPrefix${_kotlinTypeForDartType(type)}.ofRaw($value as Int)$forceUnwrap'; - } else { - return _cast(indent, value, type: type); - } + return _cast(indent, value, type: type); } /// Converts a [List] of [TypeDeclaration]s to a comma separated [String] to be @@ -947,14 +905,6 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { if (typeString == 'Int' || typeString == 'Long') { return '$variable${_castInt(type.isNullable)}'; } - if (type.isEnum) { - if (type.isNullable) { - return '($variable as Int?)?.let { num ->\n' - '${indent.str} $typeString.ofRaw(num)\n' - '${indent.str}}'; - } - return '${type.baseName}.ofRaw($variable as Int)!!'; - } return '$variable as ${_nullSafeKotlinTypeForDartType(type)}'; } diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index 5e7784bf8ba..e378fbac1c2 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -22,6 +22,7 @@ class ObjcOptions { this.headerIncludePath, this.prefix, this.copyrightHeader, + this.fileSpecificClassNameComponent, }); /// The path to the header that will get placed in the source filed (example: @@ -34,15 +35,20 @@ class ObjcOptions { /// A copyright header that will get prepended to generated code. final Iterable? copyrightHeader; + /// A String to augment class names to avoid cross file collisions. + final String? fileSpecificClassNameComponent; + /// Creates a [ObjcOptions] from a Map representation where: /// `x = ObjcOptions.fromMap(x.toMap())`. static ObjcOptions fromMap(Map map) { final Iterable? copyrightHeader = map['copyrightHeader'] as Iterable?; return ObjcOptions( - headerIncludePath: map['header'] as String?, + headerIncludePath: map['headerIncludePath'] as String?, prefix: map['prefix'] as String?, copyrightHeader: copyrightHeader?.cast(), + fileSpecificClassNameComponent: + map['fileSpecificClassNameComponent'] as String?, ); } @@ -50,9 +56,11 @@ class ObjcOptions { /// `x = ObjcOptions.fromMap(x.toMap())`. Map toMap() { final Map result = { - if (headerIncludePath != null) 'header': headerIncludePath!, + if (headerIncludePath != null) 'headerIncludePath': headerIncludePath!, if (prefix != null) 'prefix': prefix!, if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, + if (fileSpecificClassNameComponent != null) + 'fileSpecificClassNameComponent': fileSpecificClassNameComponent!, }; return result; } @@ -199,8 +207,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { Class classDefinition, { required String dartPackageName, }) { - final List classes = root.classes; - final List enums = root.enums; final String? prefix = generatorOptions.prefix; addDocumentationComments( @@ -221,8 +227,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { generatorOptions, root, classDefinition, - classes, - enums, prefix, ); indent.addln(';'); @@ -273,6 +277,18 @@ class ObjcHeaderGenerator extends StructuredGenerator { required String dartPackageName, }) {} + @override + void writeGeneralCodec( + ObjcOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + indent.writeln('$_docCommentPrefix The codec used by all APIs.'); + indent.writeln( + 'NSObject *${generatorOptions.prefix}Get${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}Codec(void);'); + } + @override void writeApis( ObjcOptions generatorOptions, @@ -293,10 +309,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { Api api, { required String dartPackageName, }) { - indent.writeln( - '$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.'); - indent.writeln( - 'NSObject *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);'); indent.newln(); final String apiName = _className(generatorOptions.prefix, api.name); addDocumentationComments( @@ -338,10 +350,6 @@ class ObjcHeaderGenerator extends StructuredGenerator { Api api, { required String dartPackageName, }) { - indent.writeln( - '$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.'); - indent.writeln( - 'NSObject *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);'); indent.newln(); final String apiName = _className(generatorOptions.prefix, api.name); addDocumentationComments( @@ -552,12 +560,12 @@ class ObjcSourceGenerator extends StructuredGenerator { Class classDefinition, { required String dartPackageName, }) { - indent.write('- (NSArray *)toList '); + indent.write('- (NSArray *)toList '); indent.addScoped('{', '}', () { indent.write('return'); indent.addScoped(' @[', '];', () { for (final NamedType field in classDefinition.fields) { - indent.writeln('${_arrayValue(field)},'); + indent.writeln('${_arrayValue(field, generatorOptions.prefix)},'); } }); }); @@ -573,24 +581,26 @@ class ObjcSourceGenerator extends StructuredGenerator { }) { final String className = _className(generatorOptions.prefix, classDefinition.name); - indent.write('+ ($className *)fromList:(NSArray *)list '); + indent.write('+ ($className *)fromList:(NSArray *)list '); indent.addScoped('{', '}', () { const String resultName = 'pigeonResult'; indent.writeln('$className *$resultName = [[$className alloc] init];'); enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final bool isEnumType = field.type.isEnum; final String valueGetter = 'GetNullableObjectAtIndex(list, $index)'; final String? primitiveExtractionMethod = _nsnumberExtractionMethod(field.type); final String ivarValueExpression; - if (primitiveExtractionMethod != null) { + if (field.type.isEnum && !field.type.isNullable) { + _writeEnumBoxToEnum( + indent, + field, + valueGetter, + prefix: generatorOptions.prefix, + ); + ivarValueExpression = 'enumBox.value'; + } else if (primitiveExtractionMethod != null) { ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; - } else if (isEnumType) { - indent.writeln('NSNumber *${field.name}AsNumber = $valueGetter;'); - indent.writeln( - '${_enumName(field.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}${field.name} = ${field.name}AsNumber == nil ? nil : [[${_enumName(field.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${field.name}AsNumber integerValue]];'); - ivarValueExpression = field.name; } else { ivarValueExpression = valueGetter; } @@ -599,21 +609,124 @@ class ObjcSourceGenerator extends StructuredGenerator { indent.writeln('return $resultName;'); }); - indent.write('+ (nullable $className *)nullableFromList:(NSArray *)list '); + indent.write( + '+ (nullable $className *)nullableFromList:(NSArray *)list '); indent.addScoped('{', '}', () { indent.writeln('return (list) ? [$className fromList:list] : nil;'); }); } - void _writeCodecAndGetter( - ObjcOptions generatorOptions, Root root, Indent indent, Api api) { - final String codecName = _getCodecName(generatorOptions.prefix, api.name); - if (getCodecClasses(api, root).isNotEmpty) { - _writeCodec(indent, codecName, generatorOptions, api, root); - indent.newln(); - } - _writeCodecGetter(indent, codecName, generatorOptions, api, root); + @override + void writeGeneralCodec( + ObjcOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + const String codecName = 'PigeonCodec'; + final Iterable codecClasses = getEnumeratedTypes(root); + final String readerWriterName = + '${generatorOptions.prefix}${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}${codecName}ReaderWriter'; + final String readerName = + '${generatorOptions.prefix}${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}${codecName}Reader'; + final String writerName = + '${generatorOptions.prefix}${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}${codecName}Writer'; + indent.writeln('@interface $readerName : FlutterStandardReader'); + indent.writeln('@end'); + indent.writeln('@implementation $readerName'); + indent.write('- (nullable id)readValueOfType:(UInt8)type '); + indent.addScoped('{', '}', () { + indent.write('switch (type) '); + indent.addScoped('{', '}', () { + for (final EnumeratedType customType in codecClasses) { + indent.writeln('case ${customType.enumeration}: '); + indent.nest(1, () { + if (customType.type == CustomTypes.customClass) { + indent.writeln( + 'return [${_className(generatorOptions.prefix, customType.name)} fromList:[self readValue]];'); + } else if (customType.type == CustomTypes.customEnum) { + indent.writeScoped('{', '}', () { + indent.writeln('NSNumber *enumAsNumber = [self readValue];'); + indent.writeln( + 'return enumAsNumber == nil ? nil : [[${_enumName(customType.name, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[enumAsNumber integerValue]];'); + }); + } + }); + } + indent.writeln('default:'); + indent.nest(1, () { + indent.writeln('return [super readValueOfType:type];'); + }); + }); + }); + indent.writeln('@end'); indent.newln(); + indent.writeln('@interface $writerName : FlutterStandardWriter'); + indent.writeln('@end'); + indent.writeln('@implementation $writerName'); + indent.write('- (void)writeValue:(id)value '); + indent.addScoped('{', '}', () { + bool firstClass = true; + for (final EnumeratedType customClass in codecClasses) { + if (firstClass) { + indent.write(''); + firstClass = false; + } + if (customClass.type == CustomTypes.customClass) { + indent.add( + 'if ([value isKindOfClass:[${_className(generatorOptions.prefix, customClass.name)} class]]) '); + indent.addScoped('{', '} else ', () { + indent.writeln('[self writeByte:${customClass.enumeration}];'); + indent.writeln('[self writeValue:[value toList]];'); + }, addTrailingNewline: false); + } else if (customClass.type == CustomTypes.customEnum) { + final String boxName = _enumName(customClass.name, + prefix: generatorOptions.prefix, box: true); + indent.add('if ([value isKindOfClass:[$boxName class]]) '); + indent.addScoped('{', '} else ', () { + indent.writeln('$boxName * box = ($boxName *)value;'); + indent.writeln('[self writeByte:${customClass.enumeration}];'); + indent.writeln( + '[self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])];'); + }, addTrailingNewline: false); + } + } + indent.addScoped('{', '}', () { + indent.writeln('[super writeValue:value];'); + }); + }); + indent.writeln('@end'); + indent.newln(); + indent.format(''' +@interface $readerWriterName : FlutterStandardReaderWriter +@end +@implementation $readerWriterName +- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { +\treturn [[$writerName alloc] initWithData:data]; +} +- (FlutterStandardReader *)readerWithData:(NSData *)data { +\treturn [[$readerName alloc] initWithData:data]; +} +@end'''); + indent.newln(); + + indent.write( + 'NSObject *${generatorOptions.prefix}Get${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}Codec(void) '); + indent.addScoped('{', '}', () { + indent + .writeln('static FlutterStandardMessageCodec *sSharedObject = nil;'); + + indent.writeln('static dispatch_once_t sPred = 0;'); + indent.write('dispatch_once(&sPred, ^'); + indent.addScoped('{', '});', () { + indent.writeln( + '$readerWriterName *readerWriter = [[$readerWriterName alloc] init];'); + indent.writeln( + 'sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];'); + }); + + indent.writeln('return sSharedObject;'); + }); } @override @@ -626,8 +739,6 @@ class ObjcSourceGenerator extends StructuredGenerator { }) { final String apiName = _className(generatorOptions.prefix, api.name); - _writeCodecAndGetter(generatorOptions, root, indent, api); - _writeExtension(indent, apiName); indent.newln(); indent.writeln('@implementation $apiName'); @@ -657,8 +768,6 @@ class ObjcSourceGenerator extends StructuredGenerator { }) { final String apiName = _className(generatorOptions.prefix, api.name); - _writeCodecAndGetter(generatorOptions, root, indent, api); - const String channelName = 'channel'; indent.write( 'void SetUp$apiName(id binaryMessenger, NSObject<$apiName> *api) '); @@ -735,7 +844,7 @@ class ObjcSourceGenerator extends StructuredGenerator { void _writeWrapError(Indent indent) { indent.format(''' -static NSArray *wrapResult(id result, FlutterError *error) { +static NSArray *wrapResult(id result, FlutterError *error) { \tif (error) { \t\treturn @[ \t\t\terror.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] @@ -747,7 +856,7 @@ static NSArray *wrapResult(id result, FlutterError *error) { void _writeGetNullableObjectAtIndex(Indent indent) { indent.format(''' -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { \tid result = array[key]; \treturn (result == [NSNull null]) ? nil : result; }'''); @@ -763,7 +872,7 @@ static FlutterError *createConnectionError(NSString *channelName) { void _writeChannelApiBinding(ObjcOptions generatorOptions, Root root, Indent indent, String apiName, Method func, String channel) { void unpackArgs(String variable) { - indent.writeln('NSArray *args = $variable;'); + indent.writeln('NSArray *args = $variable;'); int count = 0; for (final NamedType arg in func.parameters) { final String argName = _getSafeArgName(count, arg); @@ -774,16 +883,30 @@ static FlutterError *createConnectionError(NSString *channelName) { generatorOptions.prefix, arg.type, ); - if (primitiveExtractionMethod != null) { - indent.writeln( - '${objcArgType.beforeString}$argName = [$valueGetter $primitiveExtractionMethod];'); - } else if (arg.type.isEnum) { - indent.writeln('NSNumber *${argName}AsNumber = $valueGetter;'); - indent.writeln( - '${_enumName(arg.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}$argName = ${argName}AsNumber == nil ? nil : [[${_enumName(arg.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${argName}AsNumber integerValue]];'); + final String ivarValueExpression; + String beforeString = objcArgType.beforeString; + if (arg.type.isEnum && !arg.type.isNullable) { + _writeEnumBoxToEnum( + indent, + arg, + valueGetter, + prefix: generatorOptions.prefix, + ); + ivarValueExpression = 'enumBox.value'; + } else if (primitiveExtractionMethod != null) { + ivarValueExpression = '[$valueGetter $primitiveExtractionMethod]'; } else { - indent.writeln('${objcArgType.beforeString}$argName = $valueGetter;'); + if (arg.type.isEnum) { + beforeString = _enumName( + arg.type.baseName, + prefix: generatorOptions.prefix, + box: true, + suffix: ' *', + ); + } + ivarValueExpression = valueGetter; } + indent.writeln('$beforeString$argName = $ivarValueExpression;'); count++; } } @@ -808,30 +931,21 @@ static FlutterError *createConnectionError(NSString *channelName) { } else { const String callback = 'callback(wrapResult(output, error));'; String returnTypeString = '${returnType.beforeString}_Nullable output'; - const String numberOutput = 'NSNumber *output ='; - const String enumConversionExpression = - 'enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value];'; if (func.returnType.isEnum) { returnTypeString = - '${_enumName(func.returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue'; + '${_enumName(func.returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} output'; } if (func.parameters.isEmpty) { indent.writeScoped( '[api ${selectorComponents.first}:^($returnTypeString, FlutterError *_Nullable error) {', '}];', () { - if (func.returnType.isEnum) { - indent.writeln('$numberOutput $enumConversionExpression'); - } indent.writeln(callback); }); } else { indent.writeScoped( '[api $callSignature ${selectorComponents.last}:^($returnTypeString, FlutterError *_Nullable error) {', '}];', () { - if (func.returnType.isEnum) { - indent.writeln('$numberOutput $enumConversionExpression'); - } indent.writeln(callback); }); } @@ -846,9 +960,7 @@ static FlutterError *createConnectionError(NSString *channelName) { } else { if (func.returnType.isEnum) { indent.writeln( - '${_enumName(func.returnType.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)} enumBox = $call;'); - indent.writeln( - 'NSNumber *output = enumBox == nil ? nil : [NSNumber numberWithInteger:enumBox.value];'); + '${_enumName(func.returnType.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)} output = $call;'); } else { indent.writeln('${returnType.beforeString}output = $call;'); } @@ -910,8 +1022,8 @@ static FlutterError *createConnectionError(NSString *channelName) { 'initWithName:[NSString stringWithFormat:@"%@%@", @"${makeChannelName(api, func, dartPackageName)}", messageChannelSuffix]'); indent.writeln('binaryMessenger:binaryMessenger'); indent.write('codec:'); - indent - .add('${_getCodecGetterName(generatorOptions.prefix, api.name)}()'); + indent.add( + '${generatorOptions.prefix}Get${toUpperCamelCase(generatorOptions.fileSpecificClassNameComponent ?? '')}Codec()'); if (taskQueue != null) { indent.newln(); @@ -929,10 +1041,10 @@ static FlutterError *createConnectionError(NSString *channelName) { _className(languageOptions.prefix, classDefinition.name); indent.newln(); indent.writeln('@interface $className ()'); - indent.writeln('+ ($className *)fromList:(NSArray *)list;'); - indent - .writeln('+ (nullable $className *)nullableFromList:(NSArray *)list;'); - indent.writeln('- (NSArray *)toList;'); + indent.writeln('+ ($className *)fromList:(NSArray *)list;'); + indent.writeln( + '+ (nullable $className *)nullableFromList:(NSArray *)list;'); + indent.writeln('- (NSArray *)toList;'); indent.writeln('@end'); } @@ -950,8 +1062,6 @@ static FlutterError *createConnectionError(NSString *channelName) { languageOptions, root, classDefinition, - root.classes, - root.enums, languageOptions.prefix, ); indent.writeScoped(' {', '}', () { @@ -964,222 +1074,116 @@ static FlutterError *createConnectionError(NSString *channelName) { indent.writeln('return $result;'); }); } - - /// Writes the codec that will be used for encoding messages for the [api]. - /// - /// Example: - /// @interface FooHostApiCodecReader : FlutterStandardReader - /// ... - /// @interface FooHostApiCodecWriter : FlutterStandardWriter - /// ... - /// @interface FooHostApiCodecReaderWriter : FlutterStandardReaderWriter - /// ... - /// NSObject *FooHostApiCodecGetCodec(void) {...} - void _writeCodec( - Indent indent, String name, ObjcOptions options, Api api, Root root) { - assert(getCodecClasses(api, root).isNotEmpty); - final Iterable codecClasses = getCodecClasses(api, root); - final String readerWriterName = '${name}ReaderWriter'; - final String readerName = '${name}Reader'; - final String writerName = '${name}Writer'; - indent.writeln('@interface $readerName : FlutterStandardReader'); - indent.writeln('@end'); - indent.writeln('@implementation $readerName'); - indent.write('- (nullable id)readValueOfType:(UInt8)type '); - indent.addScoped('{', '}', () { - indent.write('switch (type) '); - indent.addScoped('{', '}', () { - for (final EnumeratedClass customClass in codecClasses) { - indent.writeln('case ${customClass.enumeration}: '); - indent.nest(1, () { - indent.writeln( - 'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];'); - }); - } - indent.writeln('default:'); - indent.nest(1, () { - indent.writeln('return [super readValueOfType:type];'); - }); - }); - }); - indent.writeln('@end'); - indent.newln(); - indent.writeln('@interface $writerName : FlutterStandardWriter'); - indent.writeln('@end'); - indent.writeln('@implementation $writerName'); - indent.write('- (void)writeValue:(id)value '); - indent.addScoped('{', '}', () { - bool firstClass = true; - for (final EnumeratedClass customClass in codecClasses) { - if (firstClass) { - indent.write(''); - firstClass = false; - } - indent.add( - 'if ([value isKindOfClass:[${_className(options.prefix, customClass.name)} class]]) '); - indent.addScoped('{', '} else ', () { - indent.writeln('[self writeByte:${customClass.enumeration}];'); - indent.writeln('[self writeValue:[value toList]];'); - }, addTrailingNewline: false); - } - indent.addScoped('{', '}', () { - indent.writeln('[super writeValue:value];'); - }); - }); - indent.writeln('@end'); - indent.newln(); - indent.format(''' -@interface $readerWriterName : FlutterStandardReaderWriter -@end -@implementation $readerWriterName -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { -\treturn [[$writerName alloc] initWithData:data]; } -- (FlutterStandardReader *)readerWithData:(NSData *)data { -\treturn [[$readerName alloc] initWithData:data]; -} -@end'''); - } - void _writeCodecGetter( - Indent indent, String name, ObjcOptions options, Api api, Root root) { - final String readerWriterName = '${name}ReaderWriter'; +void _writeMethod( + ObjcOptions languageOptions, + Root root, + Indent indent, + Api api, + Method func, { + required String dartPackageName, +}) { + final _ObjcType returnType = _objcTypeForDartType( + languageOptions.prefix, + func.returnType, + // Nullability is required since the return must be nil if NSError is set. + forceNullability: true, + ); + final String callbackType = + _callbackForType(func.returnType, returnType, languageOptions); - indent.write( - 'NSObject *${_getCodecGetterName(options.prefix, api.name)}(void) '); - indent.addScoped('{', '}', () { - indent - .writeln('static FlutterStandardMessageCodec *sSharedObject = nil;'); - if (getCodecClasses(api, root).isNotEmpty) { - indent.writeln('static dispatch_once_t sPred = 0;'); - indent.write('dispatch_once(&sPred, ^'); - indent.addScoped('{', '});', () { - indent.writeln( - '$readerWriterName *readerWriter = [[$readerWriterName alloc] init];'); - indent.writeln( - 'sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];'); - }); - } else { - indent.writeln( - 'sSharedObject = [FlutterStandardMessageCodec sharedInstance];'); + String argNameFunc(int count, NamedType arg) => _getSafeArgName(count, arg); + String sendArgument; + if (func.parameters.isEmpty) { + sendArgument = 'nil'; + } else { + int count = 0; + String makeVarOrNSNullExpression(NamedType arg) { + final String argName = argNameFunc(count, arg); + String varExpression = _collectionSafeExpression(argName, arg.type); + if (arg.type.isEnum) { + if (arg.type.isNullable) { + varExpression = + '${argNameFunc(count, arg)} == nil ? [NSNull null] : $argName'; + } else { + varExpression = _getEnumToEnumBox(arg, argNameFunc(count, arg), + prefix: languageOptions.prefix); + } } + count++; + return varExpression; + } - indent.writeln('return sSharedObject;'); - }); + sendArgument = + '@[${func.parameters.map(makeVarOrNSNullExpression).join(', ')}]'; } + indent.write(_makeObjcSignature( + func: func, + options: languageOptions, + returnType: 'void', + lastArgName: 'completion', + lastArgType: callbackType, + argNameFunc: argNameFunc, + )); + indent.addScoped(' {', '}', () { + indent.writeln( + 'NSString *channelName = [NSString stringWithFormat:@"%@%@", @"${makeChannelName(api, func, dartPackageName)}", _messageChannelSuffix];'); + indent.writeln('FlutterBasicMessageChannel *channel ='); - void _writeMethod( - ObjcOptions languageOptions, - Root root, - Indent indent, - Api api, - Method func, { - required String dartPackageName, - }) { - final _ObjcType returnType = _objcTypeForDartType( - languageOptions.prefix, - func.returnType, - // Nullability is required since the return must be nil if NSError is set. - forceNullability: true, - ); - final String callbackType = - _callbackForType(func.returnType, returnType, languageOptions); - - String argNameFunc(int count, NamedType arg) => _getSafeArgName(count, arg); - String sendArgument; - if (func.parameters.isEmpty) { - sendArgument = 'nil'; - } else { - int count = 0; - String makeVarOrNSNullExpression(NamedType arg) { - final String argName = argNameFunc(count, arg); - String varExpression = _collectionSafeExpression(argName, arg.type); - if (arg.type.isEnum) { - if (arg.type.isNullable) { - varExpression = - '${argNameFunc(count, arg)} == nil ? [NSNull null] : [NSNumber numberWithInteger:$argName.value]'; - } else { - varExpression = '[NSNumber numberWithInteger:$argName]'; - } - } - count++; - return varExpression; - } - - sendArgument = - '@[${func.parameters.map(makeVarOrNSNullExpression).join(', ')}]'; - } - indent.write(_makeObjcSignature( - func: func, - options: languageOptions, - returnType: 'void', - lastArgName: 'completion', - lastArgType: callbackType, - argNameFunc: argNameFunc, - )); - indent.addScoped(' {', '}', () { - indent.writeln( - 'NSString *channelName = [NSString stringWithFormat:@"%@%@", @"${makeChannelName(api, func, dartPackageName)}", _messageChannelSuffix];'); - indent.writeln('FlutterBasicMessageChannel *channel ='); + indent.nest(1, () { + indent.writeln('[FlutterBasicMessageChannel'); indent.nest(1, () { - indent.writeln('[FlutterBasicMessageChannel'); - indent.nest(1, () { - indent.writeln('messageChannelWithName:channelName'); - indent.writeln('binaryMessenger:self.binaryMessenger'); - indent.write( - 'codec:${_getCodecGetterName(languageOptions.prefix, api.name)}()'); - indent.addln('];'); - }); + indent.writeln('messageChannelWithName:channelName'); + indent.writeln('binaryMessenger:self.binaryMessenger'); + indent.write( + 'codec:${languageOptions.prefix}Get${toUpperCamelCase(languageOptions.fileSpecificClassNameComponent ?? '')}Codec()'); + indent.addln('];'); }); - final String valueOnErrorResponse = func.returnType.isVoid ? '' : 'nil, '; - indent.write( - '[channel sendMessage:$sendArgument reply:^(NSArray *reply) '); - indent.addScoped('{', '}];', () { - indent.writeScoped('if (reply != nil) {', '} ', () { - indent.writeScoped('if (reply.count > 1) {', '} ', () { - indent.writeln( - 'completion($valueOnErrorResponse[FlutterError errorWithCode:reply[0] message:reply[1] details:reply[2]]);'); - }, addTrailingNewline: false); - indent.addScoped('else {', '}', () { - const String nullCheck = - 'reply[0] == [NSNull null] ? nil : reply[0]'; - if (func.returnType.isVoid) { - indent.writeln('completion(nil);'); + }); + final String valueOnErrorResponse = func.returnType.isVoid ? '' : 'nil, '; + indent.write( + '[channel sendMessage:$sendArgument reply:^(NSArray *reply) '); + indent.addScoped('{', '}];', () { + indent.writeScoped('if (reply != nil) {', '} ', () { + indent.writeScoped('if (reply.count > 1) {', '} ', () { + indent.writeln( + 'completion($valueOnErrorResponse[FlutterError errorWithCode:reply[0] message:reply[1] details:reply[2]]);'); + }, addTrailingNewline: false); + indent.addScoped('else {', '}', () { + const String nullCheck = 'reply[0] == [NSNull null] ? nil : reply[0]'; + if (func.returnType.isVoid) { + indent.writeln('completion(nil);'); + } else { + if (func.returnType.isEnum) { + final String enumName = _enumName(func.returnType.baseName, + prefix: languageOptions.prefix, box: true); + indent.writeln('$enumName *output = $nullCheck;'); } else { - if (func.returnType.isEnum) { - final String enumName = _enumName(func.returnType.baseName, - prefix: languageOptions.prefix, box: true); - indent.writeln('NSNumber *outputAsNumber = $nullCheck;'); - indent.writeln( - '$enumName *output = outputAsNumber == nil ? nil : [[$enumName alloc] initWithValue:[outputAsNumber integerValue]];'); - } else { - indent - .writeln('${returnType.beforeString}output = $nullCheck;'); - } - indent.writeln('completion(output, nil);'); + indent.writeln('${returnType.beforeString}output = $nullCheck;'); } - }); - }, addTrailingNewline: false); - indent.addScoped('else {', '} ', () { - indent.writeln( - 'completion(${valueOnErrorResponse}createConnectionError(channelName));'); + indent.writeln('completion(output, nil);'); + } }); + }, addTrailingNewline: false); + indent.addScoped('else {', '} ', () { + indent.writeln( + 'completion(${valueOnErrorResponse}createConnectionError(channelName));'); }); }); - } + }); } /// Writes the method declaration for the initializer. /// /// Example '+ (instancetype)makeWithFoo:(NSString *)foo' void _writeObjcSourceClassInitializerDeclaration( - Indent indent, - ObjcOptions generatorOptions, - Root root, - Class classDefinition, - List classes, - List enums, - String? prefix) { + Indent indent, + ObjcOptions generatorOptions, + Root root, + Class classDefinition, + String? prefix, +) { indent.write('+ (instancetype)makeWith'); bool isFirst = true; indent.nest(2, () { @@ -1242,7 +1246,10 @@ class _ObjcType { final bool hasAsterisk; @override - String toString() => hasAsterisk ? '$baseName *' : baseName; + String toString() => + hasAsterisk ? '$baseName$listGenericTag *' : '$baseName$listGenericTag'; + + String get listGenericTag => baseName == 'NSArray' ? '' : ''; /// Returns a version of the string form that can be used directly before /// another string (e.g., a variable name) and handle spacing correctly for @@ -1333,10 +1340,14 @@ String? _nsnumberExtractionMethod( /// arguments for use in generics. /// Example: ('FOO', ['Foo', 'Bar']) -> 'FOOFoo *, FOOBar *'). String _flattenTypeArguments(String? classPrefix, List args) { - final String result = args - .map((TypeDeclaration e) => - _objcTypeForDartType(classPrefix, e).toString()) - .join(', '); + final String result = args.map((TypeDeclaration e) { + // print(e); + if (e.isEnum) { + return _enumName(e.baseName, + prefix: classPrefix, box: true, suffix: ' *'); + } + return _objcTypeForDartType(classPrefix, e).toString(); + }).join(', '); return result; } @@ -1405,15 +1416,6 @@ String _propertyTypeForDartType(TypeDeclaration type, return 'strong'; } -/// Generates the name of the codec that will be generated. -String _getCodecName(String? prefix, String className) => - '${_className(prefix, className)}Codec'; - -/// Generates the name of the function for accessing the codec instance used by -/// the api class named [className]. -String _getCodecGetterName(String? prefix, String className) => - '${_className(prefix, className)}GetCodec'; - String _capitalize(String str) => (str.isEmpty) ? '' : str[0].toUpperCase() + str.substring(1); @@ -1499,12 +1501,9 @@ String _makeObjcSignature({ /// provided [options]. void generateObjcHeader(ObjcOptions options, Root root, Indent indent) {} -String _arrayValue(NamedType field) { - if (field.type.isEnum) { - if (field.type.isNullable) { - return '(self.${field.name} == nil ? [NSNull null] : [NSNumber numberWithInteger:self.${field.name}.value])'; - } - return '@(self.${field.name})'; +String _arrayValue(NamedType field, String? prefix) { + if (field.type.isEnum && !field.type.isNullable) { + return _getEnumToEnumBox(field, 'self.${field.name}', prefix: prefix); } else { return _collectionSafeExpression( 'self.${field.name}', @@ -1569,3 +1568,21 @@ List validateObjc(ObjcOptions options, Root root) { return errors; } + +void _writeEnumBoxToEnum( + Indent indent, + NamedType field, + String valueGetter, { + String? prefix = '', +}) { + indent.writeln( + '${_enumName(field.type.baseName, prefix: prefix, box: true, suffix: ' *')}enumBox = $valueGetter;'); +} + +String _getEnumToEnumBox( + NamedType field, + String valueSetter, { + String? prefix = '', +}) { + return '[[${_enumName(field.type.baseName, prefix: prefix, box: true)} alloc] initWithValue:$valueSetter]'; +} diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 42da8b060f1..2592dd24c55 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -621,6 +621,12 @@ class ObjcGeneratorAdapter implements GeneratorAdapter { StringSink sink, PigeonOptions options, Root root, FileType fileType) { final ObjcOptions objcOptions = options.objcOptions ?? const ObjcOptions(); final ObjcOptions objcOptionsWithHeader = objcOptions.merge(ObjcOptions( + fileSpecificClassNameComponent: options.objcSourceOut + ?.split('/') + .lastOrNull + ?.split('.') + .firstOrNull ?? + '', copyrightHeader: options.copyrightHeader != null ? _lineReader( path.posix.join(options.basePath ?? '', options.copyrightHeader)) @@ -701,6 +707,8 @@ class SwiftGeneratorAdapter implements GeneratorAdapter { StringSink sink, PigeonOptions options, Root root, FileType fileType) { SwiftOptions swiftOptions = options.swiftOptions ?? const SwiftOptions(); swiftOptions = swiftOptions.merge(SwiftOptions( + fileSpecificClassNameComponent: + options.swiftOut?.split('/').lastOrNull?.split('.').firstOrNull ?? '', copyrightHeader: options.copyrightHeader != null ? _lineReader( path.posix.join(options.basePath ?? '', options.copyrightHeader)) @@ -784,6 +792,9 @@ class KotlinGeneratorAdapter implements GeneratorAdapter { kotlinOptions = kotlinOptions.merge(KotlinOptions( errorClassName: kotlinOptions.errorClassName ?? 'FlutterError', includeErrorClass: kotlinOptions.includeErrorClass, + fileSpecificClassNameComponent: + options.kotlinOut?.split('/').lastOrNull?.split('.').firstOrNull ?? + '', copyrightHeader: options.copyrightHeader != null ? _lineReader( path.posix.join(options.basePath ?? '', options.copyrightHeader)) @@ -1346,12 +1357,20 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { (Api apiDefinition) => apiDefinition.name == type.baseName, ); if (assocClass != null) { - return type.copyWithClass(assocClass); + type = type.copyWithClass(assocClass); } else if (assocEnum != null) { - return type.copyWithEnum(assocEnum); + type = type.copyWithEnum(assocEnum); } else if (assocProxyApi != null) { - return type.copyWithProxyApi(assocProxyApi); + type = type.copyWithProxyApi(assocProxyApi); } + if (type.typeArguments.isNotEmpty) { + final List newTypes = []; + for (final TypeDeclaration type in type.typeArguments) { + newTypes.add(_attachAssociatedDefinition(type)); + } + type = type.copyWithTypeArguments(newTypes); + } + return type; } @@ -1981,7 +2000,7 @@ class Pigeon { } /// Reads the file located at [path] and generates [ParseResults] by parsing - /// it. [types] optionally filters out what datatypes are actually parsed. + /// it. [types] optionally filters out what datatypes are actually parsed. /// [sdkPath] for specifying the Dart SDK path for /// [AnalysisContextCollection]. ParseResults parseFile(String inputPath, {String? sdkPath}) { @@ -2249,14 +2268,16 @@ ${_argParser.usage}'''; options = options.merge(PigeonOptions( objcOptions: (options.objcOptions ?? const ObjcOptions()).merge( ObjcOptions( - headerIncludePath: path.basename(options.objcHeaderOut!))))); + headerIncludePath: options.objcOptions?.headerIncludePath ?? + path.basename(options.objcHeaderOut!))))); } if (options.cppHeaderOut != null) { options = options.merge(PigeonOptions( cppOptions: (options.cppOptions ?? const CppOptions()).merge( CppOptions( - headerIncludePath: path.basename(options.cppHeaderOut!))))); + headerIncludePath: options.cppOptions?.headerIncludePath ?? + path.basename(options.cppHeaderOut!))))); } for (final GeneratorAdapter adapter in safeGeneratorAdapters) { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index db5701e371b..99ad77f39e7 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -19,12 +19,16 @@ class SwiftOptions { /// Creates a [SwiftOptions] object const SwiftOptions({ this.copyrightHeader, + this.fileSpecificClassNameComponent, this.errorClassName, }); /// A copyright header that will get prepended to generated code. final Iterable? copyrightHeader; + /// A String to augment class names to avoid cross file collisions. + final String? fileSpecificClassNameComponent; + /// The name of the error class used for passing custom error parameters. final String? errorClassName; @@ -33,6 +37,8 @@ class SwiftOptions { static SwiftOptions fromList(Map map) { return SwiftOptions( copyrightHeader: map['copyrightHeader'] as Iterable?, + fileSpecificClassNameComponent: + map['fileSpecificClassNameComponent'] as String?, errorClassName: map['errorClassName'] as String?, ); } @@ -42,6 +48,8 @@ class SwiftOptions { Map toMap() { final Map result = { if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!, + if (fileSpecificClassNameComponent != null) + 'fileSpecificClassNameComponent': fileSpecificClassNameComponent!, if (errorClassName != null) 'errorClassName': errorClassName!, }; return result; @@ -115,6 +123,110 @@ class SwiftGenerator extends StructuredGenerator { }); } + @override + void writeGeneralCodec( + SwiftOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final String codecName = _getCodecName(generatorOptions); + final String readerWriterName = '${codecName}ReaderWriter'; + final String readerName = '${codecName}Reader'; + final String writerName = '${codecName}Writer'; + + final Iterable allTypes = getEnumeratedTypes(root); + // Generate Reader + indent.write('private class $readerName: FlutterStandardReader '); + indent.addScoped('{', '}', () { + if (allTypes.isNotEmpty) { + indent.write('override func readValue(ofType type: UInt8) -> Any? '); + indent.addScoped('{', '}', () { + indent.write('switch type '); + indent.addScoped('{', '}', nestCount: 0, () { + for (final EnumeratedType customType in allTypes) { + indent.writeln('case ${customType.enumeration}:'); + indent.nest(1, () { + if (customType.type == CustomTypes.customEnum) { + indent.writeln('var enumResult: ${customType.name}? = nil'); + indent.writeln( + 'let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int)'); + indent.writeScoped( + 'if let enumResultAsInt = enumResultAsInt {', '}', () { + indent.writeln( + 'enumResult = ${customType.name}(rawValue: enumResultAsInt)'); + }); + indent.writeln('return enumResult'); + } else { + indent.writeln( + 'return ${customType.name}.fromList(self.readValue() as! [Any?])'); + } + }); + } + indent.writeln('default:'); + indent.nest(1, () { + indent.writeln('return super.readValue(ofType: type)'); + }); + }); + }); + } + }); + + // Generate Writer + indent.newln(); + indent.write('private class $writerName: FlutterStandardWriter '); + indent.addScoped('{', '}', () { + if (allTypes.isNotEmpty) { + indent.write('override func writeValue(_ value: Any) '); + indent.addScoped('{', '}', () { + indent.write(''); + for (final EnumeratedType customType in allTypes) { + indent.add('if let value = value as? ${customType.name} '); + indent.addScoped('{', '} else ', () { + indent.writeln('super.writeByte(${customType.enumeration})'); + if (customType.type == CustomTypes.customEnum) { + indent.writeln('super.writeValue(value.rawValue)'); + } else if (customType.type == CustomTypes.customClass) { + indent.writeln('super.writeValue(value.toList())'); + } + }, addTrailingNewline: false); + } + indent.addScoped('{', '}', () { + indent.writeln('super.writeValue(value)'); + }); + }); + } + }); + indent.newln(); + + // Generate ReaderWriter + indent + .write('private class $readerWriterName: FlutterStandardReaderWriter '); + indent.addScoped('{', '}', () { + indent.write( + 'override func reader(with data: Data) -> FlutterStandardReader '); + indent.addScoped('{', '}', () { + indent.writeln('return $readerName(data: data)'); + }); + indent.newln(); + indent.write( + 'override func writer(with data: NSMutableData) -> FlutterStandardWriter '); + indent.addScoped('{', '}', () { + indent.writeln('return $writerName(data: data)'); + }); + }); + indent.newln(); + + // Generate Codec + indent.write( + 'class $codecName: FlutterStandardMessageCodec, @unchecked Sendable '); + indent.addScoped('{', '}', () { + indent.writeln( + 'static let shared = $codecName(readerWriter: $readerWriterName())'); + }); + indent.newln(); + } + @override void writeDataClass( SwiftOptions generatorOptions, @@ -216,16 +328,7 @@ class SwiftGenerator extends StructuredGenerator { final String separator = classDefinition.fields.length > 1 ? ',' : ''; for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { - String toWriteValue = ''; - final String fieldName = field.name; - final String nullsafe = field.type.isNullable ? '?' : ''; - if (field.type.isEnum) { - toWriteValue = '$fieldName$nullsafe.rawValue'; - } else { - toWriteValue = field.name; - } - - indent.writeln('$toWriteValue$separator'); + indent.writeln('${field.name}$separator'); } }); }); @@ -249,10 +352,11 @@ class SwiftGenerator extends StructuredGenerator { (int index, final NamedType field) { final String listValue = '${varNamePrefix}list[$index]'; - _writeDecodeCasting( + _writeGenericCasting( indent: indent, value: listValue, variableName: field.name, + fieldType: _swiftTypeForDartType(field.type), type: field.type, ); }); @@ -303,11 +407,6 @@ class SwiftGenerator extends StructuredGenerator { AstFlutterApi api, { required String dartPackageName, }) { - final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; - if (isCustomCodec) { - _writeCodec(indent, api, root); - } - const List generatedComments = [ ' Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.' ]; @@ -341,15 +440,11 @@ class SwiftGenerator extends StructuredGenerator { indent.writeln( r'self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""'); }); - final String codecName = _getCodecName(api); - String codecArgumentString = ''; - if (getCodecClasses(api, root).isNotEmpty) { - codecArgumentString = ', codec: codec'; - indent.write('var codec: FlutterStandardMessageCodec '); - indent.addScoped('{', '}', () { - indent.writeln('return $codecName.shared'); - }); - } + final String codecName = _getCodecName(generatorOptions); + indent.write('var codec: $codecName '); + indent.addScoped('{', '}', () { + indent.writeln('return $codecName.shared'); + }); for (final Method func in api.methods) { addDocumentationComments( @@ -361,7 +456,6 @@ class SwiftGenerator extends StructuredGenerator { channelName: makeChannelName(api, func, dartPackageName), parameters: func.parameters, returnType: func.returnType, - codecArgumentString: codecArgumentString, swiftFunction: func.swiftFunction, ); } @@ -383,10 +477,6 @@ class SwiftGenerator extends StructuredGenerator { }) { final String apiName = api.name; - final bool isCustomCodec = getCodecClasses(api, root).isNotEmpty; - if (isCustomCodec) { - _writeCodec(indent, api, root); - } const List generatedComments = [ ' Generated protocol from Pigeon that represents a handler of messages from Flutter.' ]; @@ -414,14 +504,8 @@ class SwiftGenerator extends StructuredGenerator { '$_docCommentPrefix Generated setup class from Pigeon to handle messages through the `binaryMessenger`.'); indent.write('class ${apiName}Setup '); indent.addScoped('{', '}', () { - final String codecName = _getCodecName(api); - indent.writeln('$_docCommentPrefix The codec used by $apiName.'); - String codecArgumentString = ''; - if (getCodecClasses(api, root).isNotEmpty) { - codecArgumentString = ', codec: codec'; - indent.writeln( - 'static var codec: FlutterStandardMessageCodec { $codecName.shared }'); - } + indent.writeln( + 'static var codec: FlutterStandardMessageCodec { ${_getCodecName(generatorOptions)}.shared }'); indent.writeln( '$_docCommentPrefix Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`.'); indent.write( @@ -437,7 +521,6 @@ class SwiftGenerator extends StructuredGenerator { parameters: method.parameters, returnType: method.returnType, isAsynchronous: method.isAsynchronous, - codecArgumentString: codecArgumentString, swiftFunction: method.swiftFunction, documentationComments: method.documentationComments, ); @@ -446,104 +529,9 @@ class SwiftGenerator extends StructuredGenerator { }); } - /// Writes the codec class will be used for encoding messages for the [api]. - /// Example: - /// private class FooHostApiCodecReader: FlutterStandardReader {...} - /// private class FooHostApiCodecWriter: FlutterStandardWriter {...} - /// private class FooHostApiCodecReaderWriter: FlutterStandardReaderWriter {...} - void _writeCodec(Indent indent, Api api, Root root) { - assert(getCodecClasses(api, root).isNotEmpty); - final String codecName = _getCodecName(api); - final String readerWriterName = '${codecName}ReaderWriter'; - final String readerName = '${codecName}Reader'; - final String writerName = '${codecName}Writer'; - - // Generate Reader - indent.write('private class $readerName: FlutterStandardReader '); - indent.addScoped('{', '}', () { - if (getCodecClasses(api, root).isNotEmpty) { - indent.write('override func readValue(ofType type: UInt8) -> Any? '); - indent.addScoped('{', '}', () { - indent.write('switch type '); - indent.addScoped('{', '}', nestCount: 0, () { - for (final EnumeratedClass customClass - in getCodecClasses(api, root)) { - indent.writeln('case ${customClass.enumeration}:'); - indent.nest(1, () { - indent.writeln( - 'return ${customClass.name}.fromList(self.readValue() as! [Any?])'); - }); - } - indent.writeln('default:'); - indent.nest(1, () { - indent.writeln('return super.readValue(ofType: type)'); - }); - }); - }); - } - }); - - // Generate Writer - indent.newln(); - indent.write('private class $writerName: FlutterStandardWriter '); - indent.addScoped('{', '}', () { - if (getCodecClasses(api, root).isNotEmpty) { - indent.write('override func writeValue(_ value: Any) '); - indent.addScoped('{', '}', () { - indent.write(''); - for (final EnumeratedClass customClass - in getCodecClasses(api, root)) { - indent.add('if let value = value as? ${customClass.name} '); - indent.addScoped('{', '} else ', () { - indent.writeln('super.writeByte(${customClass.enumeration})'); - indent.writeln('super.writeValue(value.toList())'); - }, addTrailingNewline: false); - } - indent.addScoped('{', '}', () { - indent.writeln('super.writeValue(value)'); - }); - }); - } - }); - indent.newln(); - - // Generate ReaderWriter - indent - .write('private class $readerWriterName: FlutterStandardReaderWriter '); - indent.addScoped('{', '}', () { - indent.write( - 'override func reader(with data: Data) -> FlutterStandardReader '); - indent.addScoped('{', '}', () { - indent.writeln('return $readerName(data: data)'); - }); - indent.newln(); - indent.write( - 'override func writer(with data: NSMutableData) -> FlutterStandardWriter '); - indent.addScoped('{', '}', () { - indent.writeln('return $writerName(data: data)'); - }); - }); - indent.newln(); - - // Generate Codec - indent.write('class $codecName: FlutterStandardMessageCodec '); - indent.addScoped('{', '}', () { - indent.writeln( - 'static let shared = $codecName(readerWriter: $readerWriterName())'); - }); - indent.newln(); - } - String _castForceUnwrap(String value, TypeDeclaration type) { assert(!type.isVoid); - if (type.isEnum) { - String output = - '${_swiftTypeForDartType(type)}(rawValue: $value as! Int)!'; - if (type.isNullable) { - output = 'isNullish($value) ? nil : $output'; - } - return output; - } else if (type.baseName == 'Object') { + if (type.baseName == 'Object') { return value + (type.isNullable ? '' : '!'); } else if (type.baseName == 'int') { if (type.isNullable) { @@ -575,36 +563,6 @@ class SwiftGenerator extends StructuredGenerator { } } - /// Writes decode and casting code for any type. - /// - /// Optional parameters should only be used for class decoding. - void _writeDecodeCasting({ - required Indent indent, - required String value, - required String variableName, - required TypeDeclaration type, - }) { - final String fieldType = _swiftTypeForDartType(type); - if (type.isNullable && type.isEnum) { - indent.writeln('var $variableName: $fieldType? = nil'); - indent.writeln( - 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); - indent.write('if let ${variableName}RawValue = ${variableName}EnumVal '); - indent.addScoped('{', '}', () { - indent.writeln( - '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); - }); - } else { - _writeGenericCasting( - indent: indent, - value: value, - variableName: variableName, - fieldType: fieldType, - type: type, - ); - } - } - void _writeIsNullish(Indent indent) { indent.newln(); indent.write('private func isNullish(_ value: Any?) -> Bool '); @@ -708,7 +666,6 @@ private func nilOrValue(_ value: Any?) -> T? { required String channelName, required List parameters, required TypeDeclaration returnType, - required String codecArgumentString, required String? swiftFunction, }) { final String methodSignature = _getMethodSignature( @@ -723,12 +680,7 @@ private func nilOrValue(_ value: Any?) -> T? { /// Returns an argument name that can be used in a context where it is possible to collide. String getEnumSafeArgumentExpression(int count, NamedType argument) { - String enumTag = ''; - if (argument.type.isEnum) { - enumTag = argument.type.isNullable ? '?.rawValue' : '.rawValue'; - } - - return '${_getArgumentName(count, argument)}Arg$enumTag'; + return '${_getArgumentName(count, argument)}Arg'; } indent.writeScoped('$methodSignature {', '}', () { @@ -742,7 +694,7 @@ private func nilOrValue(_ value: Any?) -> T? { indent.writeln( 'let channelName: String = "$channelName\\(messageChannelSuffix)"'); indent.writeln( - 'let $channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger$codecArgumentString)'); + 'let $channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)'); indent.write('$channel.sendMessage($sendArgument) '); indent.addScoped('{ response in', '}', () { @@ -791,7 +743,6 @@ private func nilOrValue(_ value: Any?) -> T? { required Iterable parameters, required TypeDeclaration returnType, required bool isAsynchronous, - required String codecArgumentString, required String? swiftFunction, List documentationComments = const [], }) { @@ -805,7 +756,7 @@ private func nilOrValue(_ value: Any?) -> T? { final String varChannelName = '${name}Channel'; addDocumentationComments(indent, documentationComments, _docCommentSpec); indent.writeln( - 'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName\\(channelSuffix)", binaryMessenger: binaryMessenger$codecArgumentString)'); + 'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName\\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)'); indent.write('if let api = api '); indent.addScoped('{', '}', () { indent.write('$varChannelName.setMessageHandler '); @@ -851,12 +802,9 @@ private func nilOrValue(_ value: Any?) -> T? { indent.addScoped('{ result in', '}', () { indent.write('switch result '); indent.addScoped('{', '}', nestCount: 0, () { - final String nullsafe = returnType.isNullable ? '?' : ''; - final String enumTag = - returnType.isEnum ? '$nullsafe.rawValue' : ''; indent.writeln('case .success$successVariableInit:'); indent.nest(1, () { - indent.writeln('reply(wrapResult($resultName$enumTag))'); + indent.writeln('reply(wrapResult($resultName))'); }); indent.writeln('case .failure(let error):'); indent.nest(1, () { @@ -871,15 +819,8 @@ private func nilOrValue(_ value: Any?) -> T? { indent.writeln(call); indent.writeln('reply(wrapResult(nil))'); } else { - String enumTag = ''; - if (returnType.isEnum) { - enumTag = '.rawValue'; - } - enumTag = returnType.isNullable && returnType.isEnum - ? '?$enumTag' - : enumTag; indent.writeln('let result = $call'); - indent.writeln('reply(wrapResult(result$enumTag))'); + indent.writeln('reply(wrapResult(result))'); } }, addTrailingNewline: false); indent.addScoped(' catch {', '}', () { @@ -922,17 +863,22 @@ private func nilOrValue(_ value: Any?) -> T? { } /// Calculates the name of the codec that will be generated for [api]. -String _getCodecName(Api api) => '${api.name}Codec'; +String _getCodecName(SwiftOptions options) { + return '${options.fileSpecificClassNameComponent}PigeonCodec'; +} -String _getErrorClassName(SwiftOptions generatorOptions) => - generatorOptions.errorClassName ?? 'PigeonError'; +String _getErrorClassName(SwiftOptions generatorOptions) { + return generatorOptions.errorClassName ?? 'PigeonError'; +} -String _getArgumentName(int count, NamedType argument) => - argument.name.isEmpty ? 'arg$count' : argument.name; +String _getArgumentName(int count, NamedType argument) { + return argument.name.isEmpty ? 'arg$count' : argument.name; +} /// Returns an argument name that can be used in a context where it is possible to collide. -String _getSafeArgumentName(int count, NamedType argument) => - '${_getArgumentName(count, argument)}Arg'; +String _getSafeArgumentName(int count, NamedType argument) { + return '${_getArgumentName(count, argument)}Arg'; +} String _camelCase(String text) { final String pascal = text.split('_').map((String part) { diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 50f8d476014..b4dc3fdfb02 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -23,11 +23,21 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.list = const [], - this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', this.anObject = 0, + + // Lists + // This name is in a different format than the others to ensure that name + // collision with the work 'list' doesn't occur in the generated files. + required this.list, + required this.stringList, + required this.intList, + required this.doubleList, + required this.boolList, + + // Maps + required this.map, }); bool aBool; @@ -38,15 +48,21 @@ class AllTypes { Int32List a4ByteArray; Int64List a8ByteArray; Float64List aFloatArray; - // This name is in a different format than the others to ensure that name - // collision with the work 'list' doesn't occur in the generated files. - // ignore: always_specify_types, strict_raw_type - List list; - // ignore: always_specify_types, strict_raw_type - Map aMap; AnEnum anEnum; String aString; Object anObject; + + // Lists + // ignore: strict_raw_type, always_specify_types + List list; + List stringList; + List intList; + List doubleList; + List boolList; + + // Maps + // ignore: strict_raw_type, always_specify_types + Map map; } /// A class containing all supported nullable types. @@ -61,8 +77,6 @@ class AllNullableTypes { this.aNullable4ByteArray, this.aNullable8ByteArray, this.aNullableFloatArray, - this.aNullableList, - this.aNullableMap, this.nullableNestedList, this.nullableMapWithAnnotations, this.nullableMapWithObject, @@ -70,6 +84,17 @@ class AllNullableTypes { this.aNullableString, this.aNullableObject, this.allNullableTypes, + + // Lists + this.list, + this.stringList, + this.intList, + this.doubleList, + this.boolList, + this.nestedClassList, + + //Maps + this.map, ); bool? aNullableBool; @@ -80,10 +105,6 @@ class AllNullableTypes { Int32List? aNullable4ByteArray; Int64List? aNullable8ByteArray; Float64List? aNullableFloatArray; - // ignore: always_specify_types, strict_raw_type - List? aNullableList; - // ignore: always_specify_types, strict_raw_type - Map? aNullableMap; List?>? nullableNestedList; Map? nullableMapWithAnnotations; Map? nullableMapWithObject; @@ -91,6 +112,19 @@ class AllNullableTypes { String? aNullableString; Object? aNullableObject; AllNullableTypes? allNullableTypes; + + // Lists + // ignore: strict_raw_type, always_specify_types + List? list; + List? stringList; + List? intList; + List? doubleList; + List? boolList; + List? nestedClassList; + + // Maps + // ignore: strict_raw_type, always_specify_types + Map? map; } /// The primary purpose for this class is to ensure coverage of Swift structs @@ -106,14 +140,22 @@ class AllNullableTypesWithoutRecursion { this.aNullable4ByteArray, this.aNullable8ByteArray, this.aNullableFloatArray, - this.aNullableList, - this.aNullableMap, this.nullableNestedList, this.nullableMapWithAnnotations, this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, this.aNullableObject, + + // Lists + this.list, + this.stringList, + this.intList, + this.doubleList, + this.boolList, + + //Maps + this.map, ); bool? aNullableBool; @@ -124,16 +166,24 @@ class AllNullableTypesWithoutRecursion { Int32List? aNullable4ByteArray; Int64List? aNullable8ByteArray; Float64List? aNullableFloatArray; - // ignore: always_specify_types, strict_raw_type - List? aNullableList; - // ignore: always_specify_types, strict_raw_type - Map? aNullableMap; List?>? nullableNestedList; Map? nullableMapWithAnnotations; Map? nullableMapWithObject; AnEnum? aNullableEnum; String? aNullableString; Object? aNullableObject; + + // Lists + // ignore: strict_raw_type, always_specify_types + List? list; + List? stringList; + List? intList; + List? doubleList; + List? boolList; + + // Maps + // ignore: strict_raw_type, always_specify_types + Map? map; } /// A class for testing nested class handling. 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 2c8f609bf78..d0b5b600836 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 @@ -198,6 +198,45 @@ public void setAFloatArray(@NonNull double[] setterArg) { this.aFloatArray = setterArg; } + private @NonNull AnEnum anEnum; + + public @NonNull AnEnum getAnEnum() { + return anEnum; + } + + public void setAnEnum(@NonNull AnEnum setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"anEnum\" is null."); + } + this.anEnum = setterArg; + } + + private @NonNull String aString; + + public @NonNull String getAString() { + return aString; + } + + public void setAString(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"aString\" is null."); + } + this.aString = setterArg; + } + + private @NonNull Object anObject; + + public @NonNull Object getAnObject() { + return anObject; + } + + public void setAnObject(@NonNull Object setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"anObject\" is null."); + } + this.anObject = setterArg; + } + private @NonNull List list; public @NonNull List getList() { @@ -211,56 +250,69 @@ public void setList(@NonNull List setterArg) { this.list = setterArg; } - private @NonNull Map aMap; + private @NonNull List stringList; - public @NonNull Map getAMap() { - return aMap; + public @NonNull List getStringList() { + return stringList; } - public void setAMap(@NonNull Map setterArg) { + public void setStringList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"aMap\" is null."); + throw new IllegalStateException("Nonnull field \"stringList\" is null."); } - this.aMap = setterArg; + this.stringList = setterArg; } - private @NonNull AnEnum anEnum; + private @NonNull List intList; - public @NonNull AnEnum getAnEnum() { - return anEnum; + public @NonNull List getIntList() { + return intList; } - public void setAnEnum(@NonNull AnEnum setterArg) { + public void setIntList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"anEnum\" is null."); + throw new IllegalStateException("Nonnull field \"intList\" is null."); } - this.anEnum = setterArg; + this.intList = setterArg; } - private @NonNull String aString; + private @NonNull List doubleList; - public @NonNull String getAString() { - return aString; + public @NonNull List getDoubleList() { + return doubleList; } - public void setAString(@NonNull String setterArg) { + public void setDoubleList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"aString\" is null."); + throw new IllegalStateException("Nonnull field \"doubleList\" is null."); } - this.aString = setterArg; + this.doubleList = setterArg; } - private @NonNull Object anObject; + private @NonNull List boolList; - public @NonNull Object getAnObject() { - return anObject; + public @NonNull List getBoolList() { + return boolList; } - public void setAnObject(@NonNull Object setterArg) { + public void setBoolList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"anObject\" is null."); + throw new IllegalStateException("Nonnull field \"boolList\" is null."); } - this.anObject = setterArg; + this.boolList = setterArg; + } + + private @NonNull Map map; + + public @NonNull Map getMap() { + return map; + } + + public void setMap(@NonNull Map setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"map\" is null."); + } + this.map = setterArg; } /** Constructor is non-public to enforce null safety; use Builder. */ @@ -332,6 +384,30 @@ public static final class Builder { return this; } + private @Nullable AnEnum anEnum; + + @CanIgnoreReturnValue + public @NonNull Builder setAnEnum(@NonNull AnEnum setterArg) { + this.anEnum = setterArg; + return this; + } + + private @Nullable String aString; + + @CanIgnoreReturnValue + public @NonNull Builder setAString(@NonNull String setterArg) { + this.aString = setterArg; + return this; + } + + private @Nullable Object anObject; + + @CanIgnoreReturnValue + public @NonNull Builder setAnObject(@NonNull Object setterArg) { + this.anObject = setterArg; + return this; + } + private @Nullable List list; @CanIgnoreReturnValue @@ -340,35 +416,43 @@ public static final class Builder { return this; } - private @Nullable Map aMap; + private @Nullable List stringList; @CanIgnoreReturnValue - public @NonNull Builder setAMap(@NonNull Map setterArg) { - this.aMap = setterArg; + public @NonNull Builder setStringList(@NonNull List setterArg) { + this.stringList = setterArg; return this; } - private @Nullable AnEnum anEnum; + private @Nullable List intList; @CanIgnoreReturnValue - public @NonNull Builder setAnEnum(@NonNull AnEnum setterArg) { - this.anEnum = setterArg; + public @NonNull Builder setIntList(@NonNull List setterArg) { + this.intList = setterArg; return this; } - private @Nullable String aString; + private @Nullable List doubleList; @CanIgnoreReturnValue - public @NonNull Builder setAString(@NonNull String setterArg) { - this.aString = setterArg; + public @NonNull Builder setDoubleList(@NonNull List setterArg) { + this.doubleList = setterArg; return this; } - private @Nullable Object anObject; + private @Nullable List boolList; @CanIgnoreReturnValue - public @NonNull Builder setAnObject(@NonNull Object setterArg) { - this.anObject = setterArg; + public @NonNull Builder setBoolList(@NonNull List setterArg) { + this.boolList = setterArg; + return this; + } + + private @Nullable Map map; + + @CanIgnoreReturnValue + public @NonNull Builder setMap(@NonNull Map setterArg) { + this.map = setterArg; return this; } @@ -382,18 +466,22 @@ public static final class Builder { pigeonReturn.setA4ByteArray(a4ByteArray); pigeonReturn.setA8ByteArray(a8ByteArray); pigeonReturn.setAFloatArray(aFloatArray); - pigeonReturn.setList(list); - pigeonReturn.setAMap(aMap); pigeonReturn.setAnEnum(anEnum); pigeonReturn.setAString(aString); pigeonReturn.setAnObject(anObject); + pigeonReturn.setList(list); + pigeonReturn.setStringList(stringList); + pigeonReturn.setIntList(intList); + pigeonReturn.setDoubleList(doubleList); + pigeonReturn.setBoolList(boolList); + pigeonReturn.setMap(map); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(13); + ArrayList toListResult = new ArrayList(17); toListResult.add(aBool); toListResult.add(anInt); toListResult.add(anInt64); @@ -402,11 +490,15 @@ ArrayList toList() { toListResult.add(a4ByteArray); toListResult.add(a8ByteArray); toListResult.add(aFloatArray); - toListResult.add(list); - toListResult.add(aMap); - toListResult.add(anEnum == null ? null : anEnum.index); + toListResult.add(anEnum); toListResult.add(aString); toListResult.add(anObject); + toListResult.add(list); + toListResult.add(stringList); + toListResult.add(intList); + toListResult.add(doubleList); + toListResult.add(boolList); + toListResult.add(map); return toListResult; } @@ -432,16 +524,24 @@ ArrayList toList() { pigeonResult.setA8ByteArray((long[]) a8ByteArray); Object aFloatArray = __pigeon_list.get(7); pigeonResult.setAFloatArray((double[]) aFloatArray); - Object list = __pigeon_list.get(8); - pigeonResult.setList((List) list); - Object aMap = __pigeon_list.get(9); - pigeonResult.setAMap((Map) aMap); - Object anEnum = __pigeon_list.get(10); - pigeonResult.setAnEnum(AnEnum.values()[(int) anEnum]); - Object aString = __pigeon_list.get(11); + Object anEnum = __pigeon_list.get(8); + pigeonResult.setAnEnum((AnEnum) anEnum); + Object aString = __pigeon_list.get(9); pigeonResult.setAString((String) aString); - Object anObject = __pigeon_list.get(12); + Object anObject = __pigeon_list.get(10); pigeonResult.setAnObject(anObject); + Object list = __pigeon_list.get(11); + pigeonResult.setList((List) list); + Object stringList = __pigeon_list.get(12); + pigeonResult.setStringList((List) stringList); + Object intList = __pigeon_list.get(13); + pigeonResult.setIntList((List) intList); + Object doubleList = __pigeon_list.get(14); + pigeonResult.setDoubleList((List) doubleList); + Object boolList = __pigeon_list.get(15); + pigeonResult.setBoolList((List) boolList); + Object map = __pigeon_list.get(16); + pigeonResult.setMap((Map) map); return pigeonResult; } } @@ -532,26 +632,6 @@ public void setANullableFloatArray(@Nullable double[] setterArg) { this.aNullableFloatArray = setterArg; } - private @Nullable List aNullableList; - - public @Nullable List getANullableList() { - return aNullableList; - } - - public void setANullableList(@Nullable List setterArg) { - this.aNullableList = setterArg; - } - - private @Nullable Map aNullableMap; - - public @Nullable Map getANullableMap() { - return aNullableMap; - } - - public void setANullableMap(@Nullable Map setterArg) { - this.aNullableMap = setterArg; - } - private @Nullable List> nullableNestedList; public @Nullable List> getNullableNestedList() { @@ -622,6 +702,76 @@ public void setAllNullableTypes(@Nullable AllNullableTypes setterArg) { this.allNullableTypes = setterArg; } + private @Nullable List list; + + public @Nullable List getList() { + return list; + } + + public void setList(@Nullable List setterArg) { + this.list = setterArg; + } + + private @Nullable List stringList; + + public @Nullable List getStringList() { + return stringList; + } + + public void setStringList(@Nullable List setterArg) { + this.stringList = setterArg; + } + + private @Nullable List intList; + + public @Nullable List getIntList() { + return intList; + } + + public void setIntList(@Nullable List setterArg) { + this.intList = setterArg; + } + + private @Nullable List doubleList; + + public @Nullable List getDoubleList() { + return doubleList; + } + + public void setDoubleList(@Nullable List setterArg) { + this.doubleList = setterArg; + } + + private @Nullable List boolList; + + public @Nullable List getBoolList() { + return boolList; + } + + public void setBoolList(@Nullable List setterArg) { + this.boolList = setterArg; + } + + private @Nullable List nestedClassList; + + public @Nullable List getNestedClassList() { + return nestedClassList; + } + + public void setNestedClassList(@Nullable List setterArg) { + this.nestedClassList = setterArg; + } + + private @Nullable Map map; + + public @Nullable Map getMap() { + return map; + } + + public void setMap(@Nullable Map setterArg) { + this.map = setterArg; + } + public static final class Builder { private @Nullable Boolean aNullableBool; @@ -688,22 +838,6 @@ public static final class Builder { return this; } - private @Nullable List aNullableList; - - @CanIgnoreReturnValue - public @NonNull Builder setANullableList(@Nullable List setterArg) { - this.aNullableList = setterArg; - return this; - } - - private @Nullable Map aNullableMap; - - @CanIgnoreReturnValue - public @NonNull Builder setANullableMap(@Nullable Map setterArg) { - this.aNullableMap = setterArg; - return this; - } - private @Nullable List> nullableNestedList; @CanIgnoreReturnValue @@ -761,6 +895,62 @@ public static final class Builder { return this; } + private @Nullable List list; + + @CanIgnoreReturnValue + public @NonNull Builder setList(@Nullable List setterArg) { + this.list = setterArg; + return this; + } + + private @Nullable List stringList; + + @CanIgnoreReturnValue + public @NonNull Builder setStringList(@Nullable List setterArg) { + this.stringList = setterArg; + return this; + } + + private @Nullable List intList; + + @CanIgnoreReturnValue + public @NonNull Builder setIntList(@Nullable List setterArg) { + this.intList = setterArg; + return this; + } + + private @Nullable List doubleList; + + @CanIgnoreReturnValue + public @NonNull Builder setDoubleList(@Nullable List setterArg) { + this.doubleList = setterArg; + return this; + } + + private @Nullable List boolList; + + @CanIgnoreReturnValue + public @NonNull Builder setBoolList(@Nullable List setterArg) { + this.boolList = setterArg; + return this; + } + + private @Nullable List nestedClassList; + + @CanIgnoreReturnValue + public @NonNull Builder setNestedClassList(@Nullable List setterArg) { + this.nestedClassList = setterArg; + return this; + } + + private @Nullable Map map; + + @CanIgnoreReturnValue + public @NonNull Builder setMap(@Nullable Map setterArg) { + this.map = setterArg; + return this; + } + public @NonNull AllNullableTypes build() { AllNullableTypes pigeonReturn = new AllNullableTypes(); pigeonReturn.setANullableBool(aNullableBool); @@ -771,8 +961,6 @@ public static final class Builder { pigeonReturn.setANullable4ByteArray(aNullable4ByteArray); pigeonReturn.setANullable8ByteArray(aNullable8ByteArray); pigeonReturn.setANullableFloatArray(aNullableFloatArray); - pigeonReturn.setANullableList(aNullableList); - pigeonReturn.setANullableMap(aNullableMap); pigeonReturn.setNullableNestedList(nullableNestedList); pigeonReturn.setNullableMapWithAnnotations(nullableMapWithAnnotations); pigeonReturn.setNullableMapWithObject(nullableMapWithObject); @@ -780,13 +968,20 @@ public static final class Builder { pigeonReturn.setANullableString(aNullableString); pigeonReturn.setANullableObject(aNullableObject); pigeonReturn.setAllNullableTypes(allNullableTypes); + pigeonReturn.setList(list); + pigeonReturn.setStringList(stringList); + pigeonReturn.setIntList(intList); + pigeonReturn.setDoubleList(doubleList); + pigeonReturn.setBoolList(boolList); + pigeonReturn.setNestedClassList(nestedClassList); + pigeonReturn.setMap(map); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(17); + ArrayList toListResult = new ArrayList(22); toListResult.add(aNullableBool); toListResult.add(aNullableInt); toListResult.add(aNullableInt64); @@ -795,15 +990,20 @@ ArrayList toList() { toListResult.add(aNullable4ByteArray); toListResult.add(aNullable8ByteArray); toListResult.add(aNullableFloatArray); - toListResult.add(aNullableList); - toListResult.add(aNullableMap); toListResult.add(nullableNestedList); toListResult.add(nullableMapWithAnnotations); toListResult.add(nullableMapWithObject); - toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); + toListResult.add(aNullableEnum); toListResult.add(aNullableString); toListResult.add(aNullableObject); toListResult.add(allNullableTypes); + toListResult.add(list); + toListResult.add(stringList); + toListResult.add(intList); + toListResult.add(doubleList); + toListResult.add(boolList); + toListResult.add(nestedClassList); + toListResult.add(map); return toListResult; } @@ -833,25 +1033,34 @@ ArrayList toList() { pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = __pigeon_list.get(8); - pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = __pigeon_list.get(9); - pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = __pigeon_list.get(10); + Object nullableNestedList = __pigeon_list.get(8); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = __pigeon_list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(9); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = __pigeon_list.get(12); + Object nullableMapWithObject = __pigeon_list.get(10); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = __pigeon_list.get(13); - pigeonResult.setANullableEnum( - aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = __pigeon_list.get(14); + Object aNullableEnum = __pigeon_list.get(11); + pigeonResult.setANullableEnum((AnEnum) aNullableEnum); + Object aNullableString = __pigeon_list.get(12); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = __pigeon_list.get(15); + Object aNullableObject = __pigeon_list.get(13); pigeonResult.setANullableObject(aNullableObject); - Object allNullableTypes = __pigeon_list.get(16); + Object allNullableTypes = __pigeon_list.get(14); pigeonResult.setAllNullableTypes((AllNullableTypes) allNullableTypes); + Object list = __pigeon_list.get(15); + pigeonResult.setList((List) list); + Object stringList = __pigeon_list.get(16); + pigeonResult.setStringList((List) stringList); + Object intList = __pigeon_list.get(17); + pigeonResult.setIntList((List) intList); + Object doubleList = __pigeon_list.get(18); + pigeonResult.setDoubleList((List) doubleList); + Object boolList = __pigeon_list.get(19); + pigeonResult.setBoolList((List) boolList); + Object nestedClassList = __pigeon_list.get(20); + pigeonResult.setNestedClassList((List) nestedClassList); + Object map = __pigeon_list.get(21); + pigeonResult.setMap((Map) map); return pigeonResult; } } @@ -943,26 +1152,6 @@ public void setANullableFloatArray(@Nullable double[] setterArg) { this.aNullableFloatArray = setterArg; } - private @Nullable List aNullableList; - - public @Nullable List getANullableList() { - return aNullableList; - } - - public void setANullableList(@Nullable List setterArg) { - this.aNullableList = setterArg; - } - - private @Nullable Map aNullableMap; - - public @Nullable Map getANullableMap() { - return aNullableMap; - } - - public void setANullableMap(@Nullable Map setterArg) { - this.aNullableMap = setterArg; - } - private @Nullable List> nullableNestedList; public @Nullable List> getNullableNestedList() { @@ -1023,6 +1212,66 @@ public void setANullableObject(@Nullable Object setterArg) { this.aNullableObject = setterArg; } + private @Nullable List list; + + public @Nullable List getList() { + return list; + } + + public void setList(@Nullable List setterArg) { + this.list = setterArg; + } + + private @Nullable List stringList; + + public @Nullable List getStringList() { + return stringList; + } + + public void setStringList(@Nullable List setterArg) { + this.stringList = setterArg; + } + + private @Nullable List intList; + + public @Nullable List getIntList() { + return intList; + } + + public void setIntList(@Nullable List setterArg) { + this.intList = setterArg; + } + + private @Nullable List doubleList; + + public @Nullable List getDoubleList() { + return doubleList; + } + + public void setDoubleList(@Nullable List setterArg) { + this.doubleList = setterArg; + } + + private @Nullable List boolList; + + public @Nullable List getBoolList() { + return boolList; + } + + public void setBoolList(@Nullable List setterArg) { + this.boolList = setterArg; + } + + private @Nullable Map map; + + public @Nullable Map getMap() { + return map; + } + + public void setMap(@Nullable Map setterArg) { + this.map = setterArg; + } + public static final class Builder { private @Nullable Boolean aNullableBool; @@ -1089,22 +1338,6 @@ public static final class Builder { return this; } - private @Nullable List aNullableList; - - @CanIgnoreReturnValue - public @NonNull Builder setANullableList(@Nullable List setterArg) { - this.aNullableList = setterArg; - return this; - } - - private @Nullable Map aNullableMap; - - @CanIgnoreReturnValue - public @NonNull Builder setANullableMap(@Nullable Map setterArg) { - this.aNullableMap = setterArg; - return this; - } - private @Nullable List> nullableNestedList; @CanIgnoreReturnValue @@ -1154,6 +1387,54 @@ public static final class Builder { return this; } + private @Nullable List list; + + @CanIgnoreReturnValue + public @NonNull Builder setList(@Nullable List setterArg) { + this.list = setterArg; + return this; + } + + private @Nullable List stringList; + + @CanIgnoreReturnValue + public @NonNull Builder setStringList(@Nullable List setterArg) { + this.stringList = setterArg; + return this; + } + + private @Nullable List intList; + + @CanIgnoreReturnValue + public @NonNull Builder setIntList(@Nullable List setterArg) { + this.intList = setterArg; + return this; + } + + private @Nullable List doubleList; + + @CanIgnoreReturnValue + public @NonNull Builder setDoubleList(@Nullable List setterArg) { + this.doubleList = setterArg; + return this; + } + + private @Nullable List boolList; + + @CanIgnoreReturnValue + public @NonNull Builder setBoolList(@Nullable List setterArg) { + this.boolList = setterArg; + return this; + } + + private @Nullable Map map; + + @CanIgnoreReturnValue + public @NonNull Builder setMap(@Nullable Map setterArg) { + this.map = setterArg; + return this; + } + public @NonNull AllNullableTypesWithoutRecursion build() { AllNullableTypesWithoutRecursion pigeonReturn = new AllNullableTypesWithoutRecursion(); pigeonReturn.setANullableBool(aNullableBool); @@ -1164,21 +1445,25 @@ public static final class Builder { pigeonReturn.setANullable4ByteArray(aNullable4ByteArray); pigeonReturn.setANullable8ByteArray(aNullable8ByteArray); pigeonReturn.setANullableFloatArray(aNullableFloatArray); - pigeonReturn.setANullableList(aNullableList); - pigeonReturn.setANullableMap(aNullableMap); pigeonReturn.setNullableNestedList(nullableNestedList); pigeonReturn.setNullableMapWithAnnotations(nullableMapWithAnnotations); pigeonReturn.setNullableMapWithObject(nullableMapWithObject); pigeonReturn.setANullableEnum(aNullableEnum); pigeonReturn.setANullableString(aNullableString); pigeonReturn.setANullableObject(aNullableObject); + pigeonReturn.setList(list); + pigeonReturn.setStringList(stringList); + pigeonReturn.setIntList(intList); + pigeonReturn.setDoubleList(doubleList); + pigeonReturn.setBoolList(boolList); + pigeonReturn.setMap(map); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(16); + ArrayList toListResult = new ArrayList(20); toListResult.add(aNullableBool); toListResult.add(aNullableInt); toListResult.add(aNullableInt64); @@ -1187,14 +1472,18 @@ ArrayList toList() { toListResult.add(aNullable4ByteArray); toListResult.add(aNullable8ByteArray); toListResult.add(aNullableFloatArray); - toListResult.add(aNullableList); - toListResult.add(aNullableMap); toListResult.add(nullableNestedList); toListResult.add(nullableMapWithAnnotations); toListResult.add(nullableMapWithObject); - toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); + toListResult.add(aNullableEnum); toListResult.add(aNullableString); toListResult.add(aNullableObject); + toListResult.add(list); + toListResult.add(stringList); + toListResult.add(intList); + toListResult.add(doubleList); + toListResult.add(boolList); + toListResult.add(map); return toListResult; } @@ -1225,23 +1514,30 @@ ArrayList toList() { pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = __pigeon_list.get(8); - pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = __pigeon_list.get(9); - pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = __pigeon_list.get(10); + Object nullableNestedList = __pigeon_list.get(8); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = __pigeon_list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(9); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = __pigeon_list.get(12); + Object nullableMapWithObject = __pigeon_list.get(10); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = __pigeon_list.get(13); - pigeonResult.setANullableEnum( - aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = __pigeon_list.get(14); + Object aNullableEnum = __pigeon_list.get(11); + pigeonResult.setANullableEnum((AnEnum) aNullableEnum); + Object aNullableString = __pigeon_list.get(12); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = __pigeon_list.get(15); + Object aNullableObject = __pigeon_list.get(13); pigeonResult.setANullableObject(aNullableObject); + Object list = __pigeon_list.get(14); + pigeonResult.setList((List) list); + Object stringList = __pigeon_list.get(15); + pigeonResult.setStringList((List) stringList); + Object intList = __pigeon_list.get(16); + pigeonResult.setIntList((List) intList); + Object doubleList = __pigeon_list.get(17); + pigeonResult.setDoubleList((List) doubleList); + Object boolList = __pigeon_list.get(18); + pigeonResult.setBoolList((List) boolList); + Object map = __pigeon_list.get(19); + pigeonResult.setMap((Map) map); return pigeonResult; } } @@ -1399,49 +1695,27 @@ ArrayList toList() { } } - /** Asynchronous error handling return type for non-nullable API method returns. */ - public interface Result { - /** Success case callback method for handling returns. */ - void success(@NonNull T result); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } - /** Asynchronous error handling return type for nullable API method returns. */ - public interface NullableResult { - /** Success case callback method for handling returns. */ - void success(@Nullable T result); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } - /** Asynchronous error handling return type for void API method returns. */ - public interface VoidResult { - /** Success case callback method for handling returns. */ - void success(); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } + private static class PigeonCodec extends StandardMessageCodec { + public static final PigeonCodec INSTANCE = new PigeonCodec(); - private static class HostIntegrationCoreApiCodec extends StandardMessageCodec { - public static final HostIntegrationCoreApiCodec INSTANCE = new HostIntegrationCoreApiCodec(); - - private HostIntegrationCoreApiCodec() {} + private PigeonCodec() {} @Override protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { - case (byte) 128: - return AllClassesWrapper.fromList((ArrayList) readValue(buffer)); case (byte) 129: - return AllNullableTypes.fromList((ArrayList) readValue(buffer)); + return AllTypes.fromList((ArrayList) readValue(buffer)); case (byte) 130: - return AllNullableTypesWithoutRecursion.fromList((ArrayList) readValue(buffer)); + return AllNullableTypes.fromList((ArrayList) readValue(buffer)); case (byte) 131: - return AllTypes.fromList((ArrayList) readValue(buffer)); + return AllNullableTypesWithoutRecursion.fromList((ArrayList) readValue(buffer)); case (byte) 132: + return AllClassesWrapper.fromList((ArrayList) readValue(buffer)); + case (byte) 133: return TestMessage.fromList((ArrayList) readValue(buffer)); + case (byte) 134: + Object value = readValue(buffer); + return value == null ? null : AnEnum.values()[(int) value]; default: return super.readValueOfType(type, buffer); } @@ -1449,27 +1723,54 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { @Override protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof AllClassesWrapper) { - stream.write(128); - writeValue(stream, ((AllClassesWrapper) value).toList()); - } else if (value instanceof AllNullableTypes) { + if (value instanceof AllTypes) { stream.write(129); + writeValue(stream, ((AllTypes) value).toList()); + } else if (value instanceof AllNullableTypes) { + stream.write(130); writeValue(stream, ((AllNullableTypes) value).toList()); } else if (value instanceof AllNullableTypesWithoutRecursion) { - stream.write(130); - writeValue(stream, ((AllNullableTypesWithoutRecursion) value).toList()); - } else if (value instanceof AllTypes) { stream.write(131); - writeValue(stream, ((AllTypes) value).toList()); - } else if (value instanceof TestMessage) { + writeValue(stream, ((AllNullableTypesWithoutRecursion) value).toList()); + } else if (value instanceof AllClassesWrapper) { stream.write(132); + writeValue(stream, ((AllClassesWrapper) value).toList()); + } else if (value instanceof TestMessage) { + stream.write(133); writeValue(stream, ((TestMessage) value).toList()); + } else if (value instanceof AnEnum) { + stream.write(134); + writeValue(stream, value == null ? null : ((AnEnum) value).index); } else { super.writeValue(stream, value); } } } + /** Asynchronous error handling return type for non-nullable API method returns. */ + public interface Result { + /** Success case callback method for handling returns. */ + void success(@NonNull T result); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for nullable API method returns. */ + public interface NullableResult { + /** Success case callback method for handling returns. */ + void success(@Nullable T result); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for void API method returns. */ + public interface VoidResult { + /** Success case callback method for handling returns. */ + void success(); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } /** * The core interface that each host language plugin must implement in platform_test integration * tests. @@ -1725,7 +2026,7 @@ void callFlutterEchoNullableEnum( /** The codec used by HostIntegrationCoreApi. */ static @NonNull MessageCodec getCodec() { - return HostIntegrationCoreApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } /** * Sets up an instance of `HostIntegrationCoreApi` to handle messages through the @@ -2109,10 +2410,10 @@ static void setUp( (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); try { AnEnum output = api.echoEnum(anEnumArg); - wrapped.add(0, output.index); + wrapped.add(0, output); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; @@ -2594,10 +2895,10 @@ static void setUp( (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = args.get(0) == null ? null : AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); try { AnEnum output = api.echoNullableEnum(anEnumArg); - wrapped.add(0, output == null ? null : output.index); + wrapped.add(0, output); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; @@ -2960,11 +3261,11 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); Result resultCallback = new Result() { public void success(AnEnum result) { - wrapped.add(0, result.index); + wrapped.add(0, result); reply.reply(wrapped); } @@ -3437,11 +3738,11 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = args.get(0) == null ? null : AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); NullableResult resultCallback = new NullableResult() { public void success(AnEnum result) { - wrapped.add(0, result == null ? null : result.index); + wrapped.add(0, result); reply.reply(wrapped); } @@ -3957,11 +4258,11 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); Result resultCallback = new Result() { public void success(AnEnum result) { - wrapped.add(0, result.index); + wrapped.add(0, result); reply.reply(wrapped); } @@ -4214,11 +4515,11 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - AnEnum anEnumArg = args.get(0) == null ? null : AnEnum.values()[(int) args.get(0)]; + AnEnum anEnumArg = (AnEnum) args.get(0); NullableResult resultCallback = new NullableResult() { public void success(AnEnum result) { - wrapped.add(0, result == null ? null : result.index); + wrapped.add(0, result); reply.reply(wrapped); } @@ -4268,54 +4569,6 @@ public void error(Throwable error) { } } } - - private static class FlutterIntegrationCoreApiCodec extends StandardMessageCodec { - public static final FlutterIntegrationCoreApiCodec INSTANCE = - new FlutterIntegrationCoreApiCodec(); - - private FlutterIntegrationCoreApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return AllClassesWrapper.fromList((ArrayList) readValue(buffer)); - case (byte) 129: - return AllNullableTypes.fromList((ArrayList) readValue(buffer)); - case (byte) 130: - return AllNullableTypesWithoutRecursion.fromList((ArrayList) readValue(buffer)); - case (byte) 131: - return AllTypes.fromList((ArrayList) readValue(buffer)); - case (byte) 132: - return TestMessage.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof AllClassesWrapper) { - stream.write(128); - writeValue(stream, ((AllClassesWrapper) value).toList()); - } else if (value instanceof AllNullableTypes) { - stream.write(129); - writeValue(stream, ((AllNullableTypes) value).toList()); - } else if (value instanceof AllNullableTypesWithoutRecursion) { - stream.write(130); - writeValue(stream, ((AllNullableTypesWithoutRecursion) value).toList()); - } else if (value instanceof AllTypes) { - stream.write(131); - writeValue(stream, ((AllTypes) value).toList()); - } else if (value instanceof TestMessage) { - stream.write(132); - writeValue(stream, ((TestMessage) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** * The core interface that the Dart platform_test code implements for host integration tests to * call into. @@ -4339,7 +4592,7 @@ public FlutterIntegrationCoreApi( /** Public interface for sending reply. */ /** The codec used by FlutterIntegrationCoreApi. */ static @NonNull MessageCodec getCodec() { - return FlutterIntegrationCoreApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } /** * A no-op function taking no arguments and returning no value, to sanity test basic calling. @@ -4853,7 +5106,7 @@ public void echoEnum(@NonNull AnEnum anEnumArg, @NonNull Result result) BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(anEnumArg.index)), + new ArrayList(Collections.singletonList(anEnumArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -4871,7 +5124,7 @@ public void echoEnum(@NonNull AnEnum anEnumArg, @NonNull Result result) "")); } else { @SuppressWarnings("ConstantConditions") - AnEnum output = AnEnum.values()[(int) listReply.get(0)]; + AnEnum output = (AnEnum) listReply.get(0); result.success(output); } } else { @@ -5092,8 +5345,7 @@ public void echoNullableEnum( BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList( - Collections.singletonList(anEnumArg == null ? null : anEnumArg.index)), + new ArrayList(Collections.singletonList(anEnumArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -5105,8 +5357,7 @@ public void echoNullableEnum( (String) listReply.get(2))); } else { @SuppressWarnings("ConstantConditions") - AnEnum output = - listReply.get(0) == null ? null : AnEnum.values()[(int) listReply.get(0)]; + AnEnum output = (AnEnum) listReply.get(0); result.success(output); } } else { @@ -5189,7 +5440,7 @@ public interface HostTrivialApi { /** The codec used by HostTrivialApi. */ static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); + return PigeonCodec.INSTANCE; } /** Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. */ static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable HostTrivialApi api) { @@ -5240,7 +5491,7 @@ public interface HostSmallApi { /** The codec used by HostSmallApi. */ static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); + return PigeonCodec.INSTANCE; } /** Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. */ static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable HostSmallApi api) { @@ -5316,33 +5567,6 @@ public void error(Throwable error) { } } } - - private static class FlutterSmallApiCodec extends StandardMessageCodec { - public static final FlutterSmallApiCodec INSTANCE = new FlutterSmallApiCodec(); - - private FlutterSmallApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return TestMessage.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof TestMessage) { - stream.write(128); - writeValue(stream, ((TestMessage) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** * A simple API called in some unit tests. * @@ -5365,7 +5589,7 @@ public FlutterSmallApi( /** Public interface for sending reply. */ /** The codec used by FlutterSmallApi. */ static @NonNull MessageCodec getCodec() { - return FlutterSmallApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } public void echoWrappedList(@NonNull TestMessage msgArg, @NonNull Result result) { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index b15c2bfa682..c5f7857915a 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -33,13 +33,17 @@ void compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { assertArrayEquals(firstTypes.getA4ByteArray(), secondTypes.getA4ByteArray()); assertArrayEquals(firstTypes.getA8ByteArray(), secondTypes.getA8ByteArray()); assertTrue(floatArraysEqual(firstTypes.getAFloatArray(), secondTypes.getAFloatArray())); + assertEquals(firstTypes.getAnEnum(), secondTypes.getAnEnum()); + assertEquals(firstTypes.getAnObject(), secondTypes.getAnObject()); assertArrayEquals(firstTypes.getList().toArray(), secondTypes.getList().toArray()); + assertArrayEquals(firstTypes.getStringList().toArray(), secondTypes.getStringList().toArray()); + assertArrayEquals(firstTypes.getBoolList().toArray(), secondTypes.getBoolList().toArray()); + assertArrayEquals(firstTypes.getDoubleList().toArray(), secondTypes.getDoubleList().toArray()); + assertArrayEquals(firstTypes.getIntList().toArray(), secondTypes.getIntList().toArray()); assertArrayEquals( - firstTypes.getAMap().keySet().toArray(), secondTypes.getAMap().keySet().toArray()); + firstTypes.getMap().keySet().toArray(), secondTypes.getMap().keySet().toArray()); assertArrayEquals( - firstTypes.getAMap().values().toArray(), secondTypes.getAMap().values().toArray()); - assertEquals(firstTypes.getAnEnum(), secondTypes.getAnEnum()); - assertEquals(firstTypes.getAnObject(), secondTypes.getAnObject()); + firstTypes.getMap().values().toArray(), secondTypes.getMap().values().toArray()); } void compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes secondTypes) { @@ -57,18 +61,19 @@ void compareAllNullableTypes(AllNullableTypes firstTypes, AllNullableTypes secon assertTrue( floatArraysEqual( firstTypes.getANullableFloatArray(), secondTypes.getANullableFloatArray())); - assertArrayEquals( - firstTypes.getANullableList().toArray(), secondTypes.getANullableList().toArray()); - assertArrayEquals( - firstTypes.getANullableMap().keySet().toArray(), - secondTypes.getANullableMap().keySet().toArray()); - assertArrayEquals( - firstTypes.getANullableMap().values().toArray(), - secondTypes.getANullableMap().values().toArray()); assertArrayEquals( firstTypes.getNullableMapWithObject().values().toArray(), secondTypes.getNullableMapWithObject().values().toArray()); assertEquals(firstTypes.getANullableObject(), secondTypes.getANullableObject()); + assertArrayEquals(firstTypes.getList().toArray(), secondTypes.getList().toArray()); + assertArrayEquals(firstTypes.getStringList().toArray(), secondTypes.getStringList().toArray()); + assertArrayEquals(firstTypes.getBoolList().toArray(), secondTypes.getBoolList().toArray()); + assertArrayEquals(firstTypes.getDoubleList().toArray(), secondTypes.getDoubleList().toArray()); + assertArrayEquals(firstTypes.getIntList().toArray(), secondTypes.getIntList().toArray()); + assertArrayEquals( + firstTypes.getMap().keySet().toArray(), secondTypes.getMap().keySet().toArray()); + assertArrayEquals( + firstTypes.getMap().values().toArray(), secondTypes.getMap().values().toArray()); } @Test @@ -105,9 +110,13 @@ public void success(AllNullableTypes result) { assertNull(everything.getANullable4ByteArray()); assertNull(everything.getANullable8ByteArray()); assertNull(everything.getANullableFloatArray()); - assertNull(everything.getANullableList()); - assertNull(everything.getANullableMap()); assertNull(everything.getNullableMapWithObject()); + assertNull(everything.getList()); + assertNull(everything.getDoubleList()); + assertNull(everything.getIntList()); + assertNull(everything.getStringList()); + assertNull(everything.getBoolList()); + assertNull(everything.getMap()); } public void error(Throwable error) { @@ -154,10 +163,14 @@ public void hasValues() { .setA4ByteArray(new int[] {1, 2, 3, 4}) .setA8ByteArray(new long[] {1, 2, 3, 4}) .setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) - .setList(Arrays.asList(new int[] {1, 2, 3})) - .setAMap(makeMap("hello", 1234)) .setAnEnum(CoreTests.AnEnum.ONE) .setAnObject(0) + .setBoolList(Arrays.asList(new Boolean[] {true, false})) + .setDoubleList(Arrays.asList(new Double[] {0.5, 0.25, 1.5, 1.25})) + .setIntList(Arrays.asList(new Long[] {1l, 2l, 3l, 4l})) + .setList(Arrays.asList(new int[] {1, 2, 3, 4})) + .setStringList(Arrays.asList(new String[] {"string", "another one"})) + .setMap(makeMap("hello", 1234)) .build(); AllNullableTypes everything = @@ -170,10 +183,14 @@ public void hasValues() { .setANullable4ByteArray(new int[] {1, 2, 3, 4}) .setANullable8ByteArray(new long[] {1, 2, 3, 4}) .setANullableFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) - .setANullableList(Arrays.asList(new int[] {1, 2, 3})) - .setANullableMap(makeMap("hello", 1234)) .setNullableMapWithObject(makeStringMap("hello", 1234)) .setANullableObject(0) + .setBoolList(Arrays.asList(new Boolean[] {true, false})) + .setDoubleList(Arrays.asList(new Double[] {0.5, 0.25, 1.5, 1.25})) + .setIntList(Arrays.asList(new Long[] {1l, 2l, 3l, 4l})) + .setList(Arrays.asList(new int[] {1, 2, 3, 4})) + .setStringList(Arrays.asList(new String[] {"string", "another one"})) + .setMap(makeMap("hello", 1234)) .build(); BinaryMessenger binaryMessenger = mock(BinaryMessenger.class); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java index 621a8a64f83..545ab13121d 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java @@ -166,7 +166,7 @@ public void replyToMapWithValues() { assertEquals(list.get(1), "error"); assertEquals(list.get(2), Arrays.asList(1L, 2L, 3L)); assertEquals(list.get(3), reply.getRequest()); - assertEquals(list.get(4), NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); + assertEquals(list.get(4), NullFields.NullFieldsSearchReplyType.SUCCESS); } @Test diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/project.pbxproj b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/project.pbxproj index 4fced65c686..d922c88e3d4 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/project.pbxproj @@ -266,7 +266,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 33AA165E291EB8B600ECBEEB = { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 28b953fd126..d19488d45ea 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ *outputList = [binaryMessenger.codec decode:data]; XCTAssertEqualObjects(outputList[0], [NSNull null]); [expectation fulfill]; }); @@ -75,7 +75,7 @@ - (void)testAsyncFlutter2HostVoidVoid { - (void)testAsyncFlutter2HostVoidVoidError { MockBinaryMessenger *binaryMessenger = - [[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()]; + [[MockBinaryMessenger alloc] initWithCodec:FLTGetCoreTestsCodec()]; MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init]; mockHostSmallApi.voidVoidError = [FlutterError errorWithCode:@"code" message:@"message" @@ -86,7 +86,7 @@ - (void)testAsyncFlutter2HostVoidVoidError { XCTestExpectation *expectation = [self expectationWithDescription:@"voidvoid callback"]; binaryMessenger.handlers[channelName](nil, ^(NSData *data) { - NSArray *outputList = [binaryMessenger.codec decode:data]; + NSArray *outputList = [binaryMessenger.codec decode:data]; XCTAssertNotNil(outputList); XCTAssertEqualObjects(outputList[0], mockHostSmallApi.voidVoidError.code); [expectation fulfill]; @@ -96,7 +96,7 @@ - (void)testAsyncFlutter2HostVoidVoidError { - (void)testAsyncFlutter2Host { MockBinaryMessenger *binaryMessenger = - [[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()]; + [[MockBinaryMessenger alloc] initWithCodec:FLTGetCoreTestsCodec()]; MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init]; NSString *value = @"Test"; mockHostSmallApi.output = value; @@ -107,7 +107,7 @@ - (void)testAsyncFlutter2Host { NSData *inputEncoded = [binaryMessenger.codec encode:@[ value ]]; XCTestExpectation *expectation = [self expectationWithDescription:@"echo callback"]; binaryMessenger.handlers[channelName](inputEncoded, ^(NSData *data) { - NSArray *outputList = [binaryMessenger.codec decode:data]; + NSArray *outputList = [binaryMessenger.codec decode:data]; NSString *output = outputList[0]; XCTAssertEqualObjects(output, value); [expectation fulfill]; @@ -117,7 +117,7 @@ - (void)testAsyncFlutter2Host { - (void)testAsyncFlutter2HostError { MockBinaryMessenger *binaryMessenger = - [[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()]; + [[MockBinaryMessenger alloc] initWithCodec:FLTGetCoreTestsCodec()]; MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init]; SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi); NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo"; @@ -126,7 +126,7 @@ - (void)testAsyncFlutter2HostError { NSData *inputEncoded = [binaryMessenger.codec encode:@[ @"Test" ]]; XCTestExpectation *expectation = [self expectationWithDescription:@"echo callback"]; binaryMessenger.handlers[channelName](inputEncoded, ^(NSData *data) { - NSArray *outputList = [binaryMessenger.codec decode:data]; + NSArray *outputList = [binaryMessenger.codec decode:data]; XCTAssertNotNil(outputList); XCTAssertEqualObjects(outputList[0], @"hey"); XCTAssertEqualObjects(outputList[1], @"ho"); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EchoMessenger.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EchoMessenger.m index 95db64e8cee..fe925b1729d 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EchoMessenger.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EchoMessenger.m @@ -29,7 +29,7 @@ - (void)sendOnChannel:(nonnull NSString *)channel message:(NSData *_Nullable)mes - (void)sendOnChannel:(nonnull NSString *)channel message:(NSData *_Nullable)message binaryReply:(FlutterBinaryReply _Nullable)callback { - NSArray *args = [self.codec decode:message]; + NSArray *args = [self.codec decode:message]; callback([self.codec encode:args]); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EnumTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EnumTest.m index 7a3350ee9e0..a9d14641011 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EnumTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/EnumTest.m @@ -21,7 +21,7 @@ - (void)testEcho { PGNEnumStateBox *stateBox = [[PGNEnumStateBox alloc] initWithValue:PGNEnumStateError]; data.state = stateBox; EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PGNEnumApi2HostGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:PGNGetEnumCodec()]; PGNEnumApi2Flutter *api = [[PGNEnumApi2Flutter alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [api echoData:data diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.h index e05042ea27e..99bda6b508e 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.h @@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN -typedef id _Nullable (^HandlerBinaryMessengerHandler)(NSArray *_Nonnull args); +typedef id _Nullable (^HandlerBinaryMessengerHandler)(NSArray *_Nonnull args); /// A FlutterBinaryMessenger that calls a supplied method when a call is /// invoked. diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.m index 05c38f82dfe..281bfa5976a 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/HandlerBinaryMessenger.m @@ -32,7 +32,7 @@ - (void)sendOnChannel:(nonnull NSString *)channel message:(NSData *_Nullable)mes - (void)sendOnChannel:(nonnull NSString *)channel message:(NSData *_Nullable)message binaryReply:(FlutterBinaryReply _Nullable)callback { - NSArray *args = [self.codec decode:message]; + NSArray *args = [self.codec decode:message]; id result = self.handler(args); callback([self.codec encode:result]); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/ListTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/ListTest.m index 54bea7f0e78..882f3c6bedf 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/ListTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/ListTest.m @@ -22,7 +22,7 @@ - (void)testListInList { inside.testList = @[ @1, @2, @3 ]; top.testList = @[ inside ]; EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterSmallApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:FLTGetCoreTestsCodec()]; FLTFlutterSmallApi *api = [[FLTFlutterSmallApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [api echoWrappedList:top diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/MultipleArityTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/MultipleArityTest.m index 6e0541554fb..5f82547f308 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/MultipleArityTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/MultipleArityTest.m @@ -18,8 +18,8 @@ @implementation MultipleAritytest - (void)testSimple { HandlerBinaryMessenger *binaryMessenger = [[HandlerBinaryMessenger alloc] - initWithCodec:MultipleArityHostApiGetCodec() - handler:^id _Nullable(NSArray *_Nonnull args) { + initWithCodec:GetMultipleArityCodec() + handler:^id _Nullable(NSArray *_Nonnull args) { return @[ @([args[0] intValue] - [args[1] intValue]) ]; }]; MultipleArityFlutterApi *api = diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m index 48b48b61a68..d4dacda1c75 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m @@ -11,14 +11,14 @@ /////////////////////////////////////////////////////////////////////////////////////////// @interface NullFieldsSearchRequest () -+ (NullFieldsSearchRequest *)fromList:(NSArray *)list; -- (NSArray *)toList; ++ (NullFieldsSearchRequest *)fromList:(NSArray *)list; +- (NSArray *)toList; @end /////////////////////////////////////////////////////////////////////////////////////////// @interface NullFieldsSearchReply () -+ (NullFieldsSearchReply *)fromList:(NSArray *)list; -- (NSArray *)toList; ++ (NullFieldsSearchReply *)fromList:(NSArray *)list; +- (NSArray *)toList; @end /////////////////////////////////////////////////////////////////////////////////////////// @@ -39,7 +39,7 @@ - (void)testMakeWithValues { request:request type:typeWrapper]; - NSArray *indices = @[ @1, @2, @3 ]; + NSArray *indices = @[ @1, @2, @3 ]; XCTAssertEqualObjects(@"result", reply.result); XCTAssertEqualObjects(@"error", reply.error); XCTAssertEqualObjects(indices, reply.indices); @@ -66,7 +66,7 @@ - (void)testMakeReplyWithNulls { } - (void)testRequestFromListWithValues { - NSArray *list = @[ + NSArray *list = @[ @"hello", @1, ]; @@ -75,7 +75,7 @@ - (void)testRequestFromListWithValues { } - (void)testRequestFromListWithNulls { - NSArray *list = @[ + NSArray *list = @[ [NSNull null], @1, ]; @@ -84,18 +84,24 @@ - (void)testRequestFromListWithNulls { } - (void)testReplyFromListWithValues { - NSArray *indices = @[ @1, @2, @3 ]; - NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:@"hello" identifier:1]; - NullFieldsSearchReplyTypeBox *typeWrapper = [[NullFieldsSearchReplyTypeBox alloc] initWithValue:NullFieldsSearchReplyTypeSuccess]; - NullFieldsSearchReply *input = [NullFieldsSearchReply makeWithResult:@"result" - error:@"error" - indices:indices - request:request - type:typeWrapper]; - NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:[input toList]]; + NSArray *listRequest = @[ + @"hello", + @1, + ]; + NSArray *listReply = @[ + @"result", + @"error", + @[ @1, @2, @3 ], + [NullFieldsSearchRequest fromList:listRequest], + typeWrapper, + ]; + + NSArray *indices = @[ @1, @2, @3 ]; + NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:listReply]; + XCTAssertEqualObjects(@"result", reply.result); XCTAssertEqualObjects(@"error", reply.error); XCTAssertEqualObjects(indices, reply.indices); @@ -104,7 +110,7 @@ - (void)testReplyFromListWithValues { } - (void)testReplyFromListWithNulls { - NSArray *list = @[ + NSArray *list = @[ [NSNull null], [NSNull null], [NSNull null], @@ -121,13 +127,13 @@ - (void)testReplyFromListWithNulls { - (void)testRequestToListWithValuess { NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:@"hello" identifier:1]; - NSArray *list = [request toList]; + NSArray *list = [request toList]; XCTAssertEqual(@"hello", list[0]); } - (void)testRequestToListWithNulls { NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:nil identifier:1]; - NSArray *list = [request toList]; + NSArray *list = [request toList]; XCTAssertEqual([NSNull null], list[0]); } @@ -140,15 +146,13 @@ - (void)testReplyToListWithValuess { indices:@[ @1, @2, @3 ] request:[NullFieldsSearchRequest makeWithQuery:@"hello" identifier:1] type:typeWrapper]; - NSArray *list = [reply toList]; - NSArray *indices = @[ @1, @2, @3 ]; + NSArray *list = [reply toList]; + NSArray *indices = @[ @1, @2, @3 ]; XCTAssertEqualObjects(@"result", list[0]); XCTAssertEqualObjects(@"error", list[1]); XCTAssertEqualObjects(indices, list[2]); XCTAssertEqualObjects(@"hello", ((NullFieldsSearchRequest *)list[3]).query); - NSNumber *typeNumber = list[4]; - NullFieldsSearchReplyTypeBox *output = - [[NullFieldsSearchReplyTypeBox alloc] initWithValue:[typeNumber integerValue]]; + NullFieldsSearchReplyTypeBox *output = list[4]; XCTAssertEqual(typeWrapper.value, output.value); } @@ -159,7 +163,7 @@ - (void)testReplyToListWithNulls { indices:nil request:nil type:nil]; - NSArray *list = [reply toList]; + NSArray *list = [reply toList]; XCTAssertEqual([NSNull null], list[0]); XCTAssertEqual([NSNull null], list[1]); XCTAssertEqual([NSNull null], list[2]); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullableReturnsTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullableReturnsTest.m index 3cd45e6fbc4..54ee040313d 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullableReturnsTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullableReturnsTest.m @@ -35,7 +35,7 @@ @implementation NullableReturnsTest - (void)testNullableParameterWithFlutterApi { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:NullableArgHostApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetNullableReturnsCodec()]; NullableArgFlutterApi *api = [[NullableArgFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; @@ -50,12 +50,12 @@ - (void)testNullableParameterWithFlutterApi { - (void)testNullableParameterWithHostApi { MockNullableArgHostApi *api = [[MockNullableArgHostApi alloc] init]; MockBinaryMessenger *binaryMessenger = - [[MockBinaryMessenger alloc] initWithCodec:NullableArgHostApiGetCodec()]; + [[MockBinaryMessenger alloc] initWithCodec:GetNullableReturnsCodec()]; NSString *channel = @"dev.flutter.pigeon.pigeon_integration_tests.NullableArgHostApi.doit"; SetUpNullableArgHostApi(binaryMessenger, api); XCTAssertNotNil(binaryMessenger.handlers[channel]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; - NSData *arguments = [NullableArgHostApiGetCodec() encode:@[ [NSNull null] ]]; + NSData *arguments = [GetNullableReturnsCodec() encode:@[ [NSNull null] ]]; binaryMessenger.handlers[channel](arguments, ^(NSData *data) { [expectation fulfill]; }); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/PrimitiveTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/PrimitiveTest.m index 2c6b7af178f..380fc9bdc6c 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/PrimitiveTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/PrimitiveTest.m @@ -18,7 +18,7 @@ @implementation PrimitiveTest - (void)testIntPrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [api anIntValue:1 @@ -31,7 +31,7 @@ - (void)testIntPrimitive { - (void)testBoolPrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; BOOL arg = YES; @@ -46,7 +46,7 @@ - (void)testBoolPrimitive { - (void)testDoublePrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; NSInteger arg = 1.5; @@ -61,7 +61,7 @@ - (void)testDoublePrimitive { - (void)testStringPrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; NSString *arg = @"hello"; @@ -75,12 +75,12 @@ - (void)testStringPrimitive { - (void)testListPrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; - NSArray *arg = @[ @"hello" ]; + NSArray *arg = @[ @"hello" ]; [api aListValue:arg - completion:^(NSArray *_Nonnull result, FlutterError *_Nullable err) { + completion:^(NSArray *_Nonnull result, FlutterError *_Nullable err) { XCTAssertEqualObjects(arg, result); [expectation fulfill]; }]; @@ -89,7 +89,7 @@ - (void)testListPrimitive { - (void)testMapPrimitive { EchoBinaryMessenger *binaryMessenger = - [[EchoBinaryMessenger alloc] initWithCodec:PrimitiveFlutterApiGetCodec()]; + [[EchoBinaryMessenger alloc] initWithCodec:GetPrimitiveCodec()]; PrimitiveFlutterApi *api = [[PrimitiveFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; NSDictionary *arg = @{@"hello" : @1}; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m index 60220b7a859..a81c169d003 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/RunnerTests.m @@ -7,8 +7,8 @@ @import alternate_language_test_plugin; @interface ACMessageSearchReply () -+ (ACMessageSearchReply *)fromList:(NSArray *)list; -- (NSArray *)toList; ++ (ACMessageSearchReply *)fromList:(NSArray *)list; +- (NSArray *)toList; @end @interface RunnerTests : XCTestCase @@ -20,7 +20,7 @@ @implementation RunnerTests - (void)testToMapAndBack { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.result = @"foobar"; - NSArray *list = [reply toList]; + NSArray *list = [reply toList]; ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertEqual(reply.result, copy.result); } @@ -28,7 +28,7 @@ - (void)testToMapAndBack { - (void)testHandlesNull { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.result = nil; - NSArray *list = [reply toList]; + NSArray *list = [reply toList]; ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertNil(copy.result); } @@ -36,7 +36,7 @@ - (void)testHandlesNull { - (void)testHandlesNullFirst { ACMessageSearchReply *reply = [[ACMessageSearchReply alloc] init]; reply.error = @"foobar"; - NSArray *list = [reply toList]; + NSArray *list = [reply toList]; ACMessageSearchReply *copy = [ACMessageSearchReply fromList:list]; XCTAssertEqual(reply.error, copy.error); } 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 ada05bf3801..2bf7bbf26be 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 @@ -46,11 +46,15 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - list:(NSArray *)list - aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString - anObject:(id)anObject; + anObject:(id)anObject + list:(NSArray *)list + stringList:(NSArray *)stringList + intList:(NSArray *)intList + doubleList:(NSArray *)doubleList + boolList:(NSArray *)boolList + map:(NSDictionary *)map; @property(nonatomic, assign) BOOL aBool; @property(nonatomic, assign) NSInteger anInt; @property(nonatomic, assign) NSInteger anInt64; @@ -59,11 +63,15 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *list; -@property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) FLTAnEnum anEnum; @property(nonatomic, copy) NSString *aString; @property(nonatomic, strong) id anObject; +@property(nonatomic, copy) NSArray *list; +@property(nonatomic, copy) NSArray *stringList; +@property(nonatomic, copy) NSArray *intList; +@property(nonatomic, copy) NSArray *doubleList; +@property(nonatomic, copy) NSArray *boolList; +@property(nonatomic, copy) NSDictionary *map; @end /// A class containing all supported nullable types. @@ -76,8 +84,6 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations @@ -85,7 +91,14 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { aNullableEnum:(nullable FLTAnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString aNullableObject:(nullable id)aNullableObject - allNullableTypes:(nullable FLTAllNullableTypes *)allNullableTypes; + allNullableTypes:(nullable FLTAllNullableTypes *)allNullableTypes + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + nestedClassList:(nullable NSArray *)nestedClassList + map:(nullable NSDictionary *)map; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -94,8 +107,6 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable4ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable8ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullableFloatArray; -@property(nonatomic, copy, nullable) NSArray *aNullableList; -@property(nonatomic, copy, nullable) NSDictionary *aNullableMap; @property(nonatomic, copy, nullable) NSArray *> *nullableNestedList; @property(nonatomic, copy, nullable) NSDictionary *nullableMapWithAnnotations; @@ -104,6 +115,13 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, copy, nullable) NSString *aNullableString; @property(nonatomic, strong, nullable) id aNullableObject; @property(nonatomic, strong, nullable) FLTAllNullableTypes *allNullableTypes; +@property(nonatomic, copy, nullable) NSArray *list; +@property(nonatomic, copy, nullable) NSArray *stringList; +@property(nonatomic, copy, nullable) NSArray *intList; +@property(nonatomic, copy, nullable) NSArray *doubleList; +@property(nonatomic, copy, nullable) NSArray *boolList; +@property(nonatomic, copy, nullable) NSArray *nestedClassList; +@property(nonatomic, copy, nullable) NSDictionary *map; @end /// The primary purpose for this class is to ensure coverage of Swift structs @@ -118,15 +136,19 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(nullable FLTAnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString - aNullableObject:(nullable id)aNullableObject; + aNullableObject:(nullable id)aNullableObject + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + map:(nullable NSDictionary *)map; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -135,8 +157,6 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable4ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable8ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullableFloatArray; -@property(nonatomic, copy, nullable) NSArray *aNullableList; -@property(nonatomic, copy, nullable) NSDictionary *aNullableMap; @property(nonatomic, copy, nullable) NSArray *> *nullableNestedList; @property(nonatomic, copy, nullable) NSDictionary *nullableMapWithAnnotations; @@ -144,6 +164,12 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong, nullable) FLTAnEnumBox *aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; @property(nonatomic, strong, nullable) id aNullableObject; +@property(nonatomic, copy, nullable) NSArray *list; +@property(nonatomic, copy, nullable) NSArray *stringList; +@property(nonatomic, copy, nullable) NSArray *intList; +@property(nonatomic, copy, nullable) NSArray *doubleList; +@property(nonatomic, copy, nullable) NSArray *boolList; +@property(nonatomic, copy, nullable) NSDictionary *map; @end /// A class for testing nested class handling. @@ -166,12 +192,12 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { /// A data class containing a List, used in unit tests. @interface FLTTestMessage : NSObject -+ (instancetype)makeWithTestList:(nullable NSArray *)testList; -@property(nonatomic, copy, nullable) NSArray *testList; ++ (instancetype)makeWithTestList:(nullable NSArray *)testList; +@property(nonatomic, copy, nullable) NSArray *testList; @end -/// The codec used by FLTHostIntegrationCoreApi. -NSObject *FLTHostIntegrationCoreApiGetCodec(void); +/// The codec used by all APIs. +NSObject *FLTGetCoreTestsCodec(void); /// The core interface that each host language plugin must implement in /// platform_test integration tests. @@ -486,9 +512,6 @@ extern void SetUpFLTHostIntegrationCoreApiWithSuffix( id binaryMessenger, NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by FLTFlutterIntegrationCoreApi. -NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); - /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. @interface FLTFlutterIntegrationCoreApi : NSObject @@ -592,9 +615,6 @@ NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; @end -/// The codec used by FLTHostTrivialApi. -NSObject *FLTHostTrivialApiGetCodec(void); - /// An API that can be implemented for minimal, compile-only tests. @protocol FLTHostTrivialApi - (void)noopWithError:(FlutterError *_Nullable *_Nonnull)error; @@ -607,9 +627,6 @@ extern void SetUpFLTHostTrivialApiWithSuffix(id binaryMe NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by FLTHostSmallApi. -NSObject *FLTHostSmallApiGetCodec(void); - /// A simple API implemented in some unit tests. @protocol FLTHostSmallApi - (void)echoString:(NSString *)aString @@ -624,9 +641,6 @@ extern void SetUpFLTHostSmallApiWithSuffix(id binaryMess NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by FLTFlutterSmallApi. -NSObject *FLTFlutterSmallApiGetCodec(void); - /// A simple API called in some unit tests. @interface FLTFlutterSmallApi : NSObject - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; 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 92c72d59598..6dae6ff2abd 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 @@ -17,7 +17,7 @@ #error File requires ARC to be enabled. #endif -static NSArray *wrapResult(id result, FlutterError *error) { +static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] @@ -35,7 +35,7 @@ details:@""]; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } @@ -51,33 +51,33 @@ - (instancetype)initWithValue:(FLTAnEnum)value { @end @interface FLTAllTypes () -+ (FLTAllTypes *)fromList:(NSArray *)list; -+ (nullable FLTAllTypes *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (FLTAllTypes *)fromList:(NSArray *)list; ++ (nullable FLTAllTypes *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface FLTAllNullableTypes () -+ (FLTAllNullableTypes *)fromList:(NSArray *)list; -+ (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (FLTAllNullableTypes *)fromList:(NSArray *)list; ++ (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface FLTAllNullableTypesWithoutRecursion () -+ (FLTAllNullableTypesWithoutRecursion *)fromList:(NSArray *)list; -+ (nullable FLTAllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (FLTAllNullableTypesWithoutRecursion *)fromList:(NSArray *)list; ++ (nullable FLTAllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface FLTAllClassesWrapper () -+ (FLTAllClassesWrapper *)fromList:(NSArray *)list; -+ (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (FLTAllClassesWrapper *)fromList:(NSArray *)list; ++ (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface FLTTestMessage () -+ (FLTTestMessage *)fromList:(NSArray *)list; -+ (nullable FLTTestMessage *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (FLTTestMessage *)fromList:(NSArray *)list; ++ (nullable FLTTestMessage *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @implementation FLTAllTypes @@ -89,11 +89,15 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - list:(NSArray *)list - aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString - anObject:(id)anObject { + anObject:(id)anObject + list:(NSArray *)list + stringList:(NSArray *)stringList + intList:(NSArray *)intList + doubleList:(NSArray *)doubleList + boolList:(NSArray *)boolList + map:(NSDictionary *)map { FLTAllTypes *pigeonResult = [[FLTAllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -103,14 +107,18 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.list = list; - pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; pigeonResult.anObject = anObject; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.map = map; return pigeonResult; } -+ (FLTAllTypes *)fromList:(NSArray *)list { ++ (FLTAllTypes *)fromList:(NSArray *)list { FLTAllTypes *pigeonResult = [[FLTAllTypes alloc] init]; pigeonResult.aBool = [GetNullableObjectAtIndex(list, 0) boolValue]; pigeonResult.anInt = [GetNullableObjectAtIndex(list, 1) integerValue]; @@ -120,17 +128,22 @@ + (FLTAllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.list = GetNullableObjectAtIndex(list, 8); - pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; - pigeonResult.aString = GetNullableObjectAtIndex(list, 11); - pigeonResult.anObject = GetNullableObjectAtIndex(list, 12); + FLTAnEnumBox *enumBox = GetNullableObjectAtIndex(list, 8); + pigeonResult.anEnum = enumBox.value; + pigeonResult.aString = GetNullableObjectAtIndex(list, 9); + pigeonResult.anObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.list = GetNullableObjectAtIndex(list, 11); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 12); + pigeonResult.intList = GetNullableObjectAtIndex(list, 13); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 14); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 15); + pigeonResult.map = GetNullableObjectAtIndex(list, 16); return pigeonResult; } -+ (nullable FLTAllTypes *)nullableFromList:(NSArray *)list { ++ (nullable FLTAllTypes *)nullableFromList:(NSArray *)list { return (list) ? [FLTAllTypes fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ @(self.aBool), @(self.anInt), @@ -140,11 +153,15 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.list ?: [NSNull null], - self.aMap ?: [NSNull null], - @(self.anEnum), + [[FLTAnEnumBox alloc] initWithValue:self.anEnum], self.aString ?: [NSNull null], self.anObject ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -158,8 +175,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations @@ -167,7 +182,14 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullableEnum:(nullable FLTAnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString aNullableObject:(nullable id)aNullableObject - allNullableTypes:(nullable FLTAllNullableTypes *)allNullableTypes { + allNullableTypes:(nullable FLTAllNullableTypes *)allNullableTypes + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + nestedClassList:(nullable NSArray *)nestedClassList + map:(nullable NSDictionary *)map { FLTAllNullableTypes *pigeonResult = [[FLTAllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -177,8 +199,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullable4ByteArray = aNullable4ByteArray; pigeonResult.aNullable8ByteArray = aNullable8ByteArray; pigeonResult.aNullableFloatArray = aNullableFloatArray; - pigeonResult.aNullableList = aNullableList; - pigeonResult.aNullableMap = aNullableMap; pigeonResult.nullableNestedList = nullableNestedList; pigeonResult.nullableMapWithAnnotations = nullableMapWithAnnotations; pigeonResult.nullableMapWithObject = nullableMapWithObject; @@ -186,9 +206,16 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullableString = aNullableString; pigeonResult.aNullableObject = aNullableObject; pigeonResult.allNullableTypes = allNullableTypes; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.nestedClassList = nestedClassList; + pigeonResult.map = map; return pigeonResult; } -+ (FLTAllNullableTypes *)fromList:(NSArray *)list { ++ (FLTAllNullableTypes *)fromList:(NSArray *)list { FLTAllNullableTypes *pigeonResult = [[FLTAllNullableTypes alloc] init]; pigeonResult.aNullableBool = GetNullableObjectAtIndex(list, 0); pigeonResult.aNullableInt = GetNullableObjectAtIndex(list, 1); @@ -198,26 +225,26 @@ + (FLTAllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullable4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.aNullable8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aNullableFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aNullableList = GetNullableObjectAtIndex(list, 8); - pigeonResult.aNullableMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 10); - pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 11); - pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); - NSNumber *aNullableEnumAsNumber = GetNullableObjectAtIndex(list, 13); - FLTAnEnumBox *aNullableEnum = - aNullableEnumAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[aNullableEnumAsNumber integerValue]]; - pigeonResult.aNullableEnum = aNullableEnum; - pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); + pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 8); + pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 9); + pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.aNullableEnum = GetNullableObjectAtIndex(list, 11); + pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 12); + pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 13); + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 14); + pigeonResult.list = GetNullableObjectAtIndex(list, 15); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 16); + pigeonResult.intList = GetNullableObjectAtIndex(list, 17); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 18); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 19); + pigeonResult.nestedClassList = GetNullableObjectAtIndex(list, 20); + pigeonResult.map = GetNullableObjectAtIndex(list, 21); return pigeonResult; } -+ (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list { ++ (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list { return (list) ? [FLTAllNullableTypes fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.aNullableBool ?: [NSNull null], self.aNullableInt ?: [NSNull null], @@ -227,16 +254,20 @@ - (NSArray *)toList { self.aNullable4ByteArray ?: [NSNull null], self.aNullable8ByteArray ?: [NSNull null], self.aNullableFloatArray ?: [NSNull null], - self.aNullableList ?: [NSNull null], - self.aNullableMap ?: [NSNull null], self.nullableNestedList ?: [NSNull null], self.nullableMapWithAnnotations ?: [NSNull null], self.nullableMapWithObject ?: [NSNull null], - (self.aNullableEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:self.aNullableEnum.value]), + self.aNullableEnum ?: [NSNull null], self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], self.allNullableTypes ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.nestedClassList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -250,15 +281,19 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(nullable FLTAnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString - aNullableObject:(nullable id)aNullableObject { + aNullableObject:(nullable id)aNullableObject + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + map:(nullable NSDictionary *)map { FLTAllNullableTypesWithoutRecursion *pigeonResult = [[FLTAllNullableTypesWithoutRecursion alloc] init]; pigeonResult.aNullableBool = aNullableBool; @@ -269,17 +304,21 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullable4ByteArray = aNullable4ByteArray; pigeonResult.aNullable8ByteArray = aNullable8ByteArray; pigeonResult.aNullableFloatArray = aNullableFloatArray; - pigeonResult.aNullableList = aNullableList; - pigeonResult.aNullableMap = aNullableMap; pigeonResult.nullableNestedList = nullableNestedList; pigeonResult.nullableMapWithAnnotations = nullableMapWithAnnotations; pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; pigeonResult.aNullableObject = aNullableObject; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.map = map; return pigeonResult; } -+ (FLTAllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { ++ (FLTAllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { FLTAllNullableTypesWithoutRecursion *pigeonResult = [[FLTAllNullableTypesWithoutRecursion alloc] init]; pigeonResult.aNullableBool = GetNullableObjectAtIndex(list, 0); @@ -290,25 +329,24 @@ + (FLTAllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { pigeonResult.aNullable4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.aNullable8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aNullableFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aNullableList = GetNullableObjectAtIndex(list, 8); - pigeonResult.aNullableMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 10); - pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 11); - pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); - NSNumber *aNullableEnumAsNumber = GetNullableObjectAtIndex(list, 13); - FLTAnEnumBox *aNullableEnum = - aNullableEnumAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[aNullableEnumAsNumber integerValue]]; - pigeonResult.aNullableEnum = aNullableEnum; - pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); + pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 8); + pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 9); + pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.aNullableEnum = GetNullableObjectAtIndex(list, 11); + pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 12); + pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 13); + pigeonResult.list = GetNullableObjectAtIndex(list, 14); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 15); + pigeonResult.intList = GetNullableObjectAtIndex(list, 16); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 17); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 18); + pigeonResult.map = GetNullableObjectAtIndex(list, 19); return pigeonResult; } -+ (nullable FLTAllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list { ++ (nullable FLTAllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list { return (list) ? [FLTAllNullableTypesWithoutRecursion fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.aNullableBool ?: [NSNull null], self.aNullableInt ?: [NSNull null], @@ -318,15 +356,18 @@ - (NSArray *)toList { self.aNullable4ByteArray ?: [NSNull null], self.aNullable8ByteArray ?: [NSNull null], self.aNullableFloatArray ?: [NSNull null], - self.aNullableList ?: [NSNull null], - self.aNullableMap ?: [NSNull null], self.nullableNestedList ?: [NSNull null], self.nullableMapWithAnnotations ?: [NSNull null], self.nullableMapWithObject ?: [NSNull null], - (self.aNullableEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:self.aNullableEnum.value]), + self.aNullableEnum ?: [NSNull null], self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -342,17 +383,17 @@ + (instancetype)makeWithAllNullableTypes:(FLTAllNullableTypes *)allNullableTypes pigeonResult.allTypes = allTypes; return pigeonResult; } -+ (FLTAllClassesWrapper *)fromList:(NSArray *)list { ++ (FLTAllClassesWrapper *)fromList:(NSArray *)list { FLTAllClassesWrapper *pigeonResult = [[FLTAllClassesWrapper alloc] init]; pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } -+ (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { ++ (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { return (list) ? [FLTAllClassesWrapper fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.allNullableTypes ?: [NSNull null], self.allNullableTypesWithoutRecursion ?: [NSNull null], @@ -362,94 +403,102 @@ - (NSArray *)toList { @end @implementation FLTTestMessage -+ (instancetype)makeWithTestList:(nullable NSArray *)testList { ++ (instancetype)makeWithTestList:(nullable NSArray *)testList { FLTTestMessage *pigeonResult = [[FLTTestMessage alloc] init]; pigeonResult.testList = testList; return pigeonResult; } -+ (FLTTestMessage *)fromList:(NSArray *)list { ++ (FLTTestMessage *)fromList:(NSArray *)list { FLTTestMessage *pigeonResult = [[FLTTestMessage alloc] init]; pigeonResult.testList = GetNullableObjectAtIndex(list, 0); return pigeonResult; } -+ (nullable FLTTestMessage *)nullableFromList:(NSArray *)list { ++ (nullable FLTTestMessage *)nullableFromList:(NSArray *)list { return (list) ? [FLTTestMessage fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.testList ?: [NSNull null], ]; } @end -@interface FLTHostIntegrationCoreApiCodecReader : FlutterStandardReader +@interface FLTCoreTestsPigeonCodecReader : FlutterStandardReader @end -@implementation FLTHostIntegrationCoreApiCodecReader +@implementation FLTCoreTestsPigeonCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: - return [FLTAllClassesWrapper fromList:[self readValue]]; case 129: - return [FLTAllNullableTypes fromList:[self readValue]]; + return [FLTAllTypes fromList:[self readValue]]; case 130: - return [FLTAllNullableTypesWithoutRecursion fromList:[self readValue]]; + return [FLTAllNullableTypes fromList:[self readValue]]; case 131: - return [FLTAllTypes fromList:[self readValue]]; + return [FLTAllNullableTypesWithoutRecursion fromList:[self readValue]]; case 132: + return [FLTAllClassesWrapper fromList:[self readValue]]; + case 133: return [FLTTestMessage fromList:[self readValue]]; + case 134: { + NSNumber *enumAsNumber = [self readValue]; + return enumAsNumber == nil ? nil + : [[FLTAnEnumBox alloc] initWithValue:[enumAsNumber integerValue]]; + } default: return [super readValueOfType:type]; } } @end -@interface FLTHostIntegrationCoreApiCodecWriter : FlutterStandardWriter +@interface FLTCoreTestsPigeonCodecWriter : FlutterStandardWriter @end -@implementation FLTHostIntegrationCoreApiCodecWriter +@implementation FLTCoreTestsPigeonCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[FLTAllClassesWrapper class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllNullableTypes class]]) { + if ([value isKindOfClass:[FLTAllTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllNullableTypesWithoutRecursion class]]) { + } else if ([value isKindOfClass:[FLTAllNullableTypes class]]) { [self writeByte:130]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllTypes class]]) { + } else if ([value isKindOfClass:[FLTAllNullableTypesWithoutRecursion class]]) { [self writeByte:131]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTTestMessage class]]) { + } else if ([value isKindOfClass:[FLTAllClassesWrapper class]]) { [self writeByte:132]; [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[FLTTestMessage class]]) { + [self writeByte:133]; + [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[FLTAnEnumBox class]]) { + FLTAnEnumBox *box = (FLTAnEnumBox *)value; + [self writeByte:134]; + [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else { [super writeValue:value]; } } @end -@interface FLTHostIntegrationCoreApiCodecReaderWriter : FlutterStandardReaderWriter +@interface FLTCoreTestsPigeonCodecReaderWriter : FlutterStandardReaderWriter @end -@implementation FLTHostIntegrationCoreApiCodecReaderWriter +@implementation FLTCoreTestsPigeonCodecReaderWriter - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FLTHostIntegrationCoreApiCodecWriter alloc] initWithData:data]; + return [[FLTCoreTestsPigeonCodecWriter alloc] initWithData:data]; } - (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FLTHostIntegrationCoreApiCodecReader alloc] initWithData:data]; + return [[FLTCoreTestsPigeonCodecReader alloc] initWithData:data]; } @end -NSObject *FLTHostIntegrationCoreApiGetCodec(void) { +NSObject *FLTGetCoreTestsCodec(void) { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - FLTHostIntegrationCoreApiCodecReaderWriter *readerWriter = - [[FLTHostIntegrationCoreApiCodecReaderWriter alloc] init]; + FLTCoreTestsPigeonCodecReaderWriter *readerWriter = + [[FLTCoreTestsPigeonCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - void SetUpFLTHostIntegrationCoreApi(id binaryMessenger, NSObject *api) { SetUpFLTHostIntegrationCoreApiWithSuffix(binaryMessenger, api, @""); @@ -470,7 +519,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.noop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(noopWithError:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(noopWithError:)", @@ -492,14 +541,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoAllTypes:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoAllTypes:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; FLTAllTypes *output = [api echoAllTypes:arg_everything error:&error]; @@ -517,7 +566,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(throwErrorWithError:)], @@ -540,7 +589,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwErrorFromVoidWithError:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -563,7 +612,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwFlutterError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwFlutterErrorWithError:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -586,13 +635,13 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoInt:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; NSNumber *output = [api echoInt:arg_anInt error:&error]; @@ -610,14 +659,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoDouble:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; FlutterError *error; NSNumber *output = [api echoDouble:arg_aDouble error:&error]; @@ -635,13 +684,13 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoBool:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoBool:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; FlutterError *error; NSNumber *output = [api echoBool:arg_aBool error:&error]; @@ -659,14 +708,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoString:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoString:arg_aString error:&error]; @@ -684,14 +733,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoUint8List:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoUint8List:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); FlutterError *error; FlutterStandardTypedData *output = [api echoUint8List:arg_aUint8List error:&error]; @@ -709,14 +758,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoObject:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoObject:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); FlutterError *error; id output = [api echoObject:arg_anObject error:&error]; @@ -734,13 +783,13 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoList:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoList:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSArray *output = [api echoList:arg_list error:&error]; @@ -758,13 +807,13 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoMap:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSDictionary *output = [api echoMap:arg_aMap error:&error]; @@ -782,14 +831,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoClassWrapper", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoClassWrapper:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoClassWrapper:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; FLTAllClassesWrapper *output = [api echoClassWrapper:arg_wrapper error:&error]; @@ -807,17 +856,17 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoEnum:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to @selector(echoEnum:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - FLTAnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + FLTAnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + FLTAnEnum arg_anEnum = enumBox.value; FlutterError *error; - FLTAnEnumBox *enumBox = [api echoEnum:arg_anEnum error:&error]; - NSNumber *output = enumBox == nil ? nil : [NSNumber numberWithInteger:enumBox.value]; + FLTAnEnumBox *output = [api echoEnum:arg_anEnum error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -832,14 +881,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNamedDefaultString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNamedDefaultString:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNamedDefaultString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNamedDefaultString:arg_aString error:&error]; @@ -858,14 +907,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoOptionalDefaultDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoOptionalDefaultDouble:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoOptionalDefaultDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; FlutterError *error; NSNumber *output = [api echoOptionalDefaultDouble:arg_aDouble error:&error]; @@ -883,14 +932,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoRequiredInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoRequiredInt:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoRequiredInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; NSNumber *output = [api echoRequiredInt:arg_anInt error:&error]; @@ -908,14 +957,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAllNullableTypes:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAllNullableTypes:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; FLTAllNullableTypes *output = [api echoAllNullableTypes:arg_everything error:&error]; @@ -935,14 +984,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAllNullableTypesWithoutRecursion:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAllNullableTypesWithoutRecursion:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; FLTAllNullableTypesWithoutRecursion *output = @@ -963,14 +1012,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.extractNestedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(extractNestedNullableStringFrom:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(extractNestedNullableStringFrom:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api extractNestedNullableStringFrom:arg_wrapper error:&error]; @@ -990,14 +1039,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.createNestedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(createNestedObjectWithNullableString:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(createNestedObjectWithNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_nullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; FLTAllClassesWrapper *output = [api createNestedObjectWithNullableString:arg_nullableString @@ -1017,7 +1066,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.sendMultipleNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(sendMultipleNullableTypesABool: anInt:aString:error:)], @@ -1025,7 +1074,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"@selector(sendMultipleNullableTypesABool:anInt:aString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -1050,7 +1099,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.sendMultipleNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (sendMultipleNullableTypesWithoutRecursionABool:anInt:aString:error:)], @@ -1058,7 +1107,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"@selector(sendMultipleNullableTypesWithoutRecursionABool:anInt:aString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -1082,14 +1131,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableInt:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableInt:arg_aNullableInt error:&error]; @@ -1107,14 +1156,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableDouble:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableDouble = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableDouble:arg_aNullableDouble error:&error]; @@ -1132,14 +1181,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableBool:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableBool:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableBool:arg_aNullableBool error:&error]; @@ -1157,14 +1206,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableString:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNullableString:arg_aNullableString error:&error]; @@ -1182,14 +1231,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableUint8List:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableUint8List:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aNullableUint8List = GetNullableObjectAtIndex(args, 0); FlutterError *error; FlutterStandardTypedData *output = [api echoNullableUint8List:arg_aNullableUint8List @@ -1208,14 +1257,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableObject:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableObject:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_aNullableObject = GetNullableObjectAtIndex(args, 0); FlutterError *error; id output = [api echoNullableObject:arg_aNullableObject error:&error]; @@ -1233,14 +1282,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableList:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableList:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_aNullableList = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSArray *output = [api echoNullableList:arg_aNullableList error:&error]; @@ -1258,14 +1307,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableMap:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aNullableMap = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSDictionary *output = [api echoNullableMap:arg_aNullableMap error:&error]; @@ -1282,22 +1331,17 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableEnum:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableEnum:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - FLTAnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; + NSArray *args = message; + FLTAnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); FlutterError *error; - FLTAnEnumBox *enumBox = [api echoNullableEnum:arg_anEnum error:&error]; - NSNumber *output = enumBox == nil ? nil : [NSNumber numberWithInteger:enumBox.value]; + FLTAnEnumBox *output = [api echoNullableEnum:arg_anEnum error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1313,14 +1357,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoOptionalNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoOptionalNullableInt:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoOptionalNullableInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoOptionalNullableInt:arg_aNullableInt error:&error]; @@ -1339,14 +1383,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoNamedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNamedNullableString:error:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNamedNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNamedNullableString:arg_aNullableString error:&error]; @@ -1365,7 +1409,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.noopAsync", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(noopAsyncWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -1388,14 +1432,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncInt:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; [api echoAsyncInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1414,14 +1458,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncDouble:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; [api echoAsyncDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1440,14 +1484,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncBool:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; [api echoAsyncBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1466,14 +1510,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncString:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoAsyncString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -1492,14 +1536,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncUint8List:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); [api echoAsyncUint8List:arg_aUint8List completion:^(FlutterStandardTypedData *_Nullable output, @@ -1519,14 +1563,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncObject:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncObject:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); [api echoAsyncObject:arg_anObject completion:^(id _Nullable output, FlutterError *_Nullable error) { @@ -1545,14 +1589,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncList:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -1571,14 +1615,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncMap:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api echoAsyncMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -1598,19 +1642,18 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncEnum:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - FLTAnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + FLTAnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + FLTAnEnum arg_anEnum = enumBox.value; [api echoAsyncEnum:arg_anEnum - completion:^(FLTAnEnumBox *_Nullable enumValue, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; + completion:^(FLTAnEnumBox *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; }]; @@ -1626,7 +1669,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwAsyncError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncErrorWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -1650,7 +1693,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwAsyncErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncErrorFromVoidWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -1673,7 +1716,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.throwAsyncFlutterError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncFlutterErrorWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -1697,14 +1740,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncAllTypes:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncAllTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncAllTypes:arg_everything completion:^(FLTAllTypes *_Nullable output, FlutterError *_Nullable error) { @@ -1724,14 +1767,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableAllNullableTypes:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableAllNullableTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableAllNullableTypes:arg_everything completion:^(FLTAllNullableTypes *_Nullable output, @@ -1753,7 +1796,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"echoAsyncNullableAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (echoAsyncNullableAllNullableTypesWithoutRecursion:completion:)], @@ -1761,7 +1804,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"@selector(echoAsyncNullableAllNullableTypesWithoutRecursion:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableAllNullableTypesWithoutRecursion:arg_everything completion:^(FLTAllNullableTypesWithoutRecursion @@ -1782,14 +1825,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableInt:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1809,14 +1852,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableDouble:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1835,14 +1878,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableBool:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1862,14 +1905,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableString:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -1889,14 +1932,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableUint8List:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableUint8List:arg_aUint8List completion:^(FlutterStandardTypedData *_Nullable output, @@ -1917,14 +1960,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableObject:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableObject:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableObject:arg_anObject completion:^(id _Nullable output, FlutterError *_Nullable error) { @@ -1943,14 +1986,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableList:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -1969,14 +2012,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableMap:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -1996,26 +2039,20 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.echoAsyncNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableEnum:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - FLTAnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; - [api echoAsyncNullableEnum:arg_anEnum - completion:^(FLTAnEnumBox *_Nullable enumValue, - FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; - callback(wrapResult(output, error)); - }]; + NSArray *args = message; + FLTAnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); + [api + echoAsyncNullableEnum:arg_anEnum + completion:^(FLTAnEnumBox *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; }]; } else { [channel setMessageHandler:nil]; @@ -2028,7 +2065,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterNoop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterNoopWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -2050,7 +2087,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterThrowError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterThrowErrorWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -2074,7 +2111,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterThrowErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterThrowErrorFromVoidWithCompletion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @@ -2097,14 +2134,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoAllTypes:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoAllTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllTypes:arg_everything completion:^(FLTAllTypes *_Nullable output, @@ -2124,14 +2161,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoAllNullableTypes:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoAllNullableTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllNullableTypes:arg_everything completion:^(FLTAllNullableTypes *_Nullable output, @@ -2152,7 +2189,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)], @@ -2160,7 +2197,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"@selector(callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -2185,7 +2222,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"callFlutterEchoAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (callFlutterEchoAllNullableTypesWithoutRecursion:completion:)], @@ -2193,7 +2230,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"@selector(callFlutterEchoAllNullableTypesWithoutRecursion:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FLTAllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllNullableTypesWithoutRecursion:arg_everything completion:^(FLTAllNullableTypesWithoutRecursion @@ -2215,7 +2252,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"callFlutterSendMultipleNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector @@ -2226,7 +2263,7 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -2251,14 +2288,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoBool:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; [api callFlutterEchoBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2276,14 +2313,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoInt:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; [api callFlutterEchoInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2301,14 +2338,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoDouble:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; [api callFlutterEchoDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2326,14 +2363,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoString:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -2352,14 +2389,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoUint8List:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, @@ -2378,14 +2415,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoList:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -2403,14 +2440,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoMap:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -2429,20 +2466,18 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoEnum:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - FLTAnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + FLTAnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + FLTAnEnum arg_anEnum = enumBox.value; [api callFlutterEchoEnum:arg_anEnum - completion:^(FLTAnEnumBox *_Nullable enumValue, - FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; + completion:^(FLTAnEnumBox *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; }]; @@ -2458,14 +2493,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableBool:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableBool:arg_aBool completion:^(NSNumber *_Nullable output, @@ -2485,14 +2520,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableInt:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableInt:arg_anInt completion:^(NSNumber *_Nullable output, @@ -2512,14 +2547,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableDouble:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableDouble:arg_aDouble completion:^(NSNumber *_Nullable output, @@ -2539,14 +2574,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableString:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableString:arg_aString completion:^(NSString *_Nullable output, @@ -2566,14 +2601,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableUint8List:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, @@ -2593,14 +2628,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableList:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, @@ -2620,14 +2655,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableMap:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -2647,25 +2682,18 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterEchoNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableEnum:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - FLTAnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; + NSArray *args = message; + FLTAnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableEnum:arg_anEnum - completion:^(FLTAnEnumBox *_Nullable enumValue, + completion:^(FLTAnEnumBox *_Nullable output, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil - : [NSNumber numberWithInteger:enumValue.value]; callback(wrapResult(output, error)); }]; }]; @@ -2681,14 +2709,14 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM @"HostIntegrationCoreApi.callFlutterSmallApiEchoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterSmallApiEchoString:completion:)], @"FLTHostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterSmallApiEchoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterSmallApiEchoString:arg_aString completion:^(NSString *_Nullable output, @@ -2701,74 +2729,6 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM } } } -@interface FLTFlutterIntegrationCoreApiCodecReader : FlutterStandardReader -@end -@implementation FLTFlutterIntegrationCoreApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FLTAllClassesWrapper fromList:[self readValue]]; - case 129: - return [FLTAllNullableTypes fromList:[self readValue]]; - case 130: - return [FLTAllNullableTypesWithoutRecursion fromList:[self readValue]]; - case 131: - return [FLTAllTypes fromList:[self readValue]]; - case 132: - return [FLTTestMessage fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FLTFlutterIntegrationCoreApiCodecWriter : FlutterStandardWriter -@end -@implementation FLTFlutterIntegrationCoreApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FLTAllClassesWrapper class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllNullableTypes class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllNullableTypesWithoutRecursion class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTAllTypes class]]) { - [self writeByte:131]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FLTTestMessage class]]) { - [self writeByte:132]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FLTFlutterIntegrationCoreApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FLTFlutterIntegrationCoreApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FLTFlutterIntegrationCoreApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FLTFlutterIntegrationCoreApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FLTFlutterIntegrationCoreApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FLTFlutterIntegrationCoreApiCodecReaderWriter *readerWriter = - [[FLTFlutterIntegrationCoreApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - @interface FLTFlutterIntegrationCoreApi () @property(nonatomic, strong) NSObject *binaryMessenger; @property(nonatomic, strong) NSString *messageChannelSuffix; @@ -2798,7 +2758,7 @@ - (void)noopWithCompletion:(void (^)(FlutterError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2823,7 +2783,7 @@ - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2849,7 +2809,7 @@ - (void)throwErrorFromVoidWithCompletion:(void (^)(FlutterError *_Nullable))comp FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2875,7 +2835,7 @@ - (void)echoAllTypes:(FLTAllTypes *)arg_everything FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2903,7 +2863,7 @@ - (void)echoAllNullableTypes:(nullable FLTAllNullableTypes *)arg_everything FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2933,7 +2893,7 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -2966,7 +2926,7 @@ - (void)echoAllNullableTypesWithoutRecursion: FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2999,7 +2959,7 @@ - (void)sendMultipleNullableTypesWithoutRecursionABool:(nullable NSNumber *)arg_ FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -3030,7 +2990,7 @@ - (void)echoBool:(BOOL)arg_aBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_aBool) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3056,7 +3016,7 @@ - (void)echoInt:(NSInteger)arg_anInt FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_anInt) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3083,7 +3043,7 @@ - (void)echoDouble:(double)arg_aDouble FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_aDouble) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3110,7 +3070,7 @@ - (void)echoString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3138,7 +3098,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3166,7 +3126,7 @@ - (void)echoList:(NSArray *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3193,7 +3153,7 @@ - (void)echoMap:(NSDictionary *)arg_aMap FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3221,8 +3181,8 @@ - (void)echoEnum:(FLTAnEnum)arg_anEnum FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ [NSNumber numberWithInteger:arg_anEnum] ] + codec:FLTGetCoreTestsCodec()]; + [channel sendMessage:@[ [[FLTAnEnumBox alloc] initWithValue:arg_anEnum] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3230,11 +3190,7 @@ - (void)echoEnum:(FLTAnEnum)arg_anEnum message:reply[1] details:reply[2]]); } else { - NSNumber *outputAsNumber = reply[0] == [NSNull null] ? nil : reply[0]; - FLTAnEnumBox *output = - outputAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[outputAsNumber integerValue]]; + FLTAnEnumBox *output = reply[0] == [NSNull null] ? nil : reply[0]; completion(output, nil); } } else { @@ -3252,7 +3208,7 @@ - (void)echoNullableBool:(nullable NSNumber *)arg_aBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3279,7 +3235,7 @@ - (void)echoNullableInt:(nullable NSNumber *)arg_anInt FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3306,7 +3262,7 @@ - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3333,7 +3289,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3361,7 +3317,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3389,7 +3345,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3417,7 +3373,7 @@ - (void)echoNullableMap:(nullable NSDictionary *)arg_aMap FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3445,9 +3401,8 @@ - (void)echoNullableEnum:(nullable FLTAnEnumBox *)arg_anEnum FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:arg_anEnum.value] ] + codec:FLTGetCoreTestsCodec()]; + [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] : arg_anEnum ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3455,11 +3410,7 @@ - (void)echoNullableEnum:(nullable FLTAnEnumBox *)arg_anEnum message:reply[1] details:reply[2]]); } else { - NSNumber *outputAsNumber = reply[0] == [NSNull null] ? nil : reply[0]; - FLTAnEnumBox *output = - outputAsNumber == nil - ? nil - : [[FLTAnEnumBox alloc] initWithValue:[outputAsNumber integerValue]]; + FLTAnEnumBox *output = reply[0] == [NSNull null] ? nil : reply[0]; completion(output, nil); } } else { @@ -3476,7 +3427,7 @@ - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -3502,7 +3453,7 @@ - (void)echoAsyncString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterIntegrationCoreApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3521,12 +3472,6 @@ - (void)echoAsyncString:(NSString *)arg_aString } @end -NSObject *FLTHostTrivialApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - void SetUpFLTHostTrivialApi(id binaryMessenger, NSObject *api) { SetUpFLTHostTrivialApiWithSuffix(binaryMessenger, api, @""); @@ -3546,7 +3491,7 @@ void SetUpFLTHostTrivialApiWithSuffix(id binaryMessenger @"dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostTrivialApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(noopWithError:)], @"FLTHostTrivialApi api (%@) doesn't respond to @selector(noopWithError:)", api); @@ -3560,12 +3505,6 @@ void SetUpFLTHostTrivialApiWithSuffix(id binaryMessenger } } } -NSObject *FLTHostSmallApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - void SetUpFLTHostSmallApi(id binaryMessenger, NSObject *api) { SetUpFLTHostSmallApiWithSuffix(binaryMessenger, api, @""); @@ -3585,13 +3524,13 @@ void SetUpFLTHostSmallApiWithSuffix(id binaryMessenger, @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostSmallApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoString:completion:)], @"FLTHostSmallApi api (%@) doesn't respond to @selector(echoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -3609,7 +3548,7 @@ void SetUpFLTHostSmallApiWithSuffix(id binaryMessenger, @"HostSmallApi.voidVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:FLTHostSmallApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(voidVoidWithCompletion:)], @"FLTHostSmallApi api (%@) doesn't respond to @selector(voidVoidWithCompletion:)", @@ -3624,54 +3563,6 @@ void SetUpFLTHostSmallApiWithSuffix(id binaryMessenger, } } } -@interface FLTFlutterSmallApiCodecReader : FlutterStandardReader -@end -@implementation FLTFlutterSmallApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FLTTestMessage fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FLTFlutterSmallApiCodecWriter : FlutterStandardWriter -@end -@implementation FLTFlutterSmallApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FLTTestMessage class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FLTFlutterSmallApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FLTFlutterSmallApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FLTFlutterSmallApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FLTFlutterSmallApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FLTFlutterSmallApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FLTFlutterSmallApiCodecReaderWriter *readerWriter = - [[FLTFlutterSmallApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - @interface FLTFlutterSmallApi () @property(nonatomic, strong) NSObject *binaryMessenger; @property(nonatomic, strong) NSString *messageChannelSuffix; @@ -3702,7 +3593,7 @@ - (void)echoWrappedList:(FLTTestMessage *)arg_msg FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterSmallApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_msg ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3728,7 +3619,7 @@ - (void)echoString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FLTFlutterSmallApiGetCodec()]; + codec:FLTGetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index ee54d035eb6..f2b2c074755 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -46,11 +46,15 @@ typedef NS_ENUM(NSUInteger, AnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - list:(NSArray *)list - aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString - anObject:(id)anObject; + anObject:(id)anObject + list:(NSArray *)list + stringList:(NSArray *)stringList + intList:(NSArray *)intList + doubleList:(NSArray *)doubleList + boolList:(NSArray *)boolList + map:(NSDictionary *)map; @property(nonatomic, assign) BOOL aBool; @property(nonatomic, assign) NSInteger anInt; @property(nonatomic, assign) NSInteger anInt64; @@ -59,11 +63,15 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *list; -@property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; @property(nonatomic, strong) id anObject; +@property(nonatomic, copy) NSArray *list; +@property(nonatomic, copy) NSArray *stringList; +@property(nonatomic, copy) NSArray *intList; +@property(nonatomic, copy) NSArray *doubleList; +@property(nonatomic, copy) NSArray *boolList; +@property(nonatomic, copy) NSDictionary *map; @end /// A class containing all supported nullable types. @@ -76,8 +84,6 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations @@ -85,7 +91,14 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aNullableEnum:(nullable AnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString aNullableObject:(nullable id)aNullableObject - allNullableTypes:(nullable AllNullableTypes *)allNullableTypes; + allNullableTypes:(nullable AllNullableTypes *)allNullableTypes + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + nestedClassList:(nullable NSArray *)nestedClassList + map:(nullable NSDictionary *)map; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -94,8 +107,6 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable4ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable8ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullableFloatArray; -@property(nonatomic, copy, nullable) NSArray *aNullableList; -@property(nonatomic, copy, nullable) NSDictionary *aNullableMap; @property(nonatomic, copy, nullable) NSArray *> *nullableNestedList; @property(nonatomic, copy, nullable) NSDictionary *nullableMapWithAnnotations; @@ -104,6 +115,13 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, copy, nullable) NSString *aNullableString; @property(nonatomic, strong, nullable) id aNullableObject; @property(nonatomic, strong, nullable) AllNullableTypes *allNullableTypes; +@property(nonatomic, copy, nullable) NSArray *list; +@property(nonatomic, copy, nullable) NSArray *stringList; +@property(nonatomic, copy, nullable) NSArray *intList; +@property(nonatomic, copy, nullable) NSArray *doubleList; +@property(nonatomic, copy, nullable) NSArray *boolList; +@property(nonatomic, copy, nullable) NSArray *nestedClassList; +@property(nonatomic, copy, nullable) NSDictionary *map; @end /// The primary purpose for this class is to ensure coverage of Swift structs @@ -118,15 +136,19 @@ typedef NS_ENUM(NSUInteger, AnEnum) { aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(nullable AnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString - aNullableObject:(nullable id)aNullableObject; + aNullableObject:(nullable id)aNullableObject + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + map:(nullable NSDictionary *)map; @property(nonatomic, strong, nullable) NSNumber *aNullableBool; @property(nonatomic, strong, nullable) NSNumber *aNullableInt; @property(nonatomic, strong, nullable) NSNumber *aNullableInt64; @@ -135,8 +157,6 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable4ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable8ByteArray; @property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullableFloatArray; -@property(nonatomic, copy, nullable) NSArray *aNullableList; -@property(nonatomic, copy, nullable) NSDictionary *aNullableMap; @property(nonatomic, copy, nullable) NSArray *> *nullableNestedList; @property(nonatomic, copy, nullable) NSDictionary *nullableMapWithAnnotations; @@ -144,6 +164,12 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong, nullable) AnEnumBox *aNullableEnum; @property(nonatomic, copy, nullable) NSString *aNullableString; @property(nonatomic, strong, nullable) id aNullableObject; +@property(nonatomic, copy, nullable) NSArray *list; +@property(nonatomic, copy, nullable) NSArray *stringList; +@property(nonatomic, copy, nullable) NSArray *intList; +@property(nonatomic, copy, nullable) NSArray *doubleList; +@property(nonatomic, copy, nullable) NSArray *boolList; +@property(nonatomic, copy, nullable) NSDictionary *map; @end /// A class for testing nested class handling. @@ -166,12 +192,12 @@ typedef NS_ENUM(NSUInteger, AnEnum) { /// A data class containing a List, used in unit tests. @interface TestMessage : NSObject -+ (instancetype)makeWithTestList:(nullable NSArray *)testList; -@property(nonatomic, copy, nullable) NSArray *testList; ++ (instancetype)makeWithTestList:(nullable NSArray *)testList; +@property(nonatomic, copy, nullable) NSArray *testList; @end -/// The codec used by HostIntegrationCoreApi. -NSObject *HostIntegrationCoreApiGetCodec(void); +/// The codec used by all APIs. +NSObject *GetCoreTestsCodec(void); /// The core interface that each host language plugin must implement in /// platform_test integration tests. @@ -483,9 +509,6 @@ extern void SetUpHostIntegrationCoreApiWithSuffix(id bin NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by FlutterIntegrationCoreApi. -NSObject *FlutterIntegrationCoreApiGetCodec(void); - /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. @interface FlutterIntegrationCoreApi : NSObject @@ -588,9 +611,6 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; @end -/// The codec used by HostTrivialApi. -NSObject *HostTrivialApiGetCodec(void); - /// An API that can be implemented for minimal, compile-only tests. @protocol HostTrivialApi - (void)noopWithError:(FlutterError *_Nullable *_Nonnull)error; @@ -603,9 +623,6 @@ extern void SetUpHostTrivialApiWithSuffix(id binaryMesse NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by HostSmallApi. -NSObject *HostSmallApiGetCodec(void); - /// A simple API implemented in some unit tests. @protocol HostSmallApi - (void)echoString:(NSString *)aString @@ -620,9 +637,6 @@ extern void SetUpHostSmallApiWithSuffix(id binaryMesseng NSObject *_Nullable api, NSString *messageChannelSuffix); -/// The codec used by FlutterSmallApi. -NSObject *FlutterSmallApiGetCodec(void); - /// A simple API called in some unit tests. @interface FlutterSmallApi : NSObject - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index fafcbcf7d73..be3810ceae8 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -17,7 +17,7 @@ #error File requires ARC to be enabled. #endif -static NSArray *wrapResult(id result, FlutterError *error) { +static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] @@ -35,7 +35,7 @@ details:@""]; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } @@ -51,33 +51,33 @@ - (instancetype)initWithValue:(AnEnum)value { @end @interface AllTypes () -+ (AllTypes *)fromList:(NSArray *)list; -+ (nullable AllTypes *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (AllTypes *)fromList:(NSArray *)list; ++ (nullable AllTypes *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface AllNullableTypes () -+ (AllNullableTypes *)fromList:(NSArray *)list; -+ (nullable AllNullableTypes *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (AllNullableTypes *)fromList:(NSArray *)list; ++ (nullable AllNullableTypes *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface AllNullableTypesWithoutRecursion () -+ (AllNullableTypesWithoutRecursion *)fromList:(NSArray *)list; -+ (nullable AllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (AllNullableTypesWithoutRecursion *)fromList:(NSArray *)list; ++ (nullable AllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface AllClassesWrapper () -+ (AllClassesWrapper *)fromList:(NSArray *)list; -+ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (AllClassesWrapper *)fromList:(NSArray *)list; ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface TestMessage () -+ (TestMessage *)fromList:(NSArray *)list; -+ (nullable TestMessage *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (TestMessage *)fromList:(NSArray *)list; ++ (nullable TestMessage *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @implementation AllTypes @@ -89,11 +89,15 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - list:(NSArray *)list - aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString - anObject:(id)anObject { + anObject:(id)anObject + list:(NSArray *)list + stringList:(NSArray *)stringList + intList:(NSArray *)intList + doubleList:(NSArray *)doubleList + boolList:(NSArray *)boolList + map:(NSDictionary *)map { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = aBool; pigeonResult.anInt = anInt; @@ -103,14 +107,18 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.list = list; - pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; pigeonResult.anObject = anObject; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.map = map; return pigeonResult; } -+ (AllTypes *)fromList:(NSArray *)list { ++ (AllTypes *)fromList:(NSArray *)list { AllTypes *pigeonResult = [[AllTypes alloc] init]; pigeonResult.aBool = [GetNullableObjectAtIndex(list, 0) boolValue]; pigeonResult.anInt = [GetNullableObjectAtIndex(list, 1) integerValue]; @@ -120,17 +128,22 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.list = GetNullableObjectAtIndex(list, 8); - pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; - pigeonResult.aString = GetNullableObjectAtIndex(list, 11); - pigeonResult.anObject = GetNullableObjectAtIndex(list, 12); + AnEnumBox *enumBox = GetNullableObjectAtIndex(list, 8); + pigeonResult.anEnum = enumBox.value; + pigeonResult.aString = GetNullableObjectAtIndex(list, 9); + pigeonResult.anObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.list = GetNullableObjectAtIndex(list, 11); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 12); + pigeonResult.intList = GetNullableObjectAtIndex(list, 13); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 14); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 15); + pigeonResult.map = GetNullableObjectAtIndex(list, 16); return pigeonResult; } -+ (nullable AllTypes *)nullableFromList:(NSArray *)list { ++ (nullable AllTypes *)nullableFromList:(NSArray *)list { return (list) ? [AllTypes fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ @(self.aBool), @(self.anInt), @@ -140,11 +153,15 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.list ?: [NSNull null], - self.aMap ?: [NSNull null], - @(self.anEnum), + [[AnEnumBox alloc] initWithValue:self.anEnum], self.aString ?: [NSNull null], self.anObject ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -158,8 +175,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations @@ -167,7 +182,14 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullableEnum:(nullable AnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString aNullableObject:(nullable id)aNullableObject - allNullableTypes:(nullable AllNullableTypes *)allNullableTypes { + allNullableTypes:(nullable AllNullableTypes *)allNullableTypes + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + nestedClassList:(nullable NSArray *)nestedClassList + map:(nullable NSDictionary *)map { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -177,8 +199,6 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullable4ByteArray = aNullable4ByteArray; pigeonResult.aNullable8ByteArray = aNullable8ByteArray; pigeonResult.aNullableFloatArray = aNullableFloatArray; - pigeonResult.aNullableList = aNullableList; - pigeonResult.aNullableMap = aNullableMap; pigeonResult.nullableNestedList = nullableNestedList; pigeonResult.nullableMapWithAnnotations = nullableMapWithAnnotations; pigeonResult.nullableMapWithObject = nullableMapWithObject; @@ -186,9 +206,16 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullableString = aNullableString; pigeonResult.aNullableObject = aNullableObject; pigeonResult.allNullableTypes = allNullableTypes; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.nestedClassList = nestedClassList; + pigeonResult.map = map; return pigeonResult; } -+ (AllNullableTypes *)fromList:(NSArray *)list { ++ (AllNullableTypes *)fromList:(NSArray *)list { AllNullableTypes *pigeonResult = [[AllNullableTypes alloc] init]; pigeonResult.aNullableBool = GetNullableObjectAtIndex(list, 0); pigeonResult.aNullableInt = GetNullableObjectAtIndex(list, 1); @@ -198,26 +225,26 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullable4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.aNullable8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aNullableFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aNullableList = GetNullableObjectAtIndex(list, 8); - pigeonResult.aNullableMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 10); - pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 11); - pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); - NSNumber *aNullableEnumAsNumber = GetNullableObjectAtIndex(list, 13); - AnEnumBox *aNullableEnum = - aNullableEnumAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[aNullableEnumAsNumber integerValue]]; - pigeonResult.aNullableEnum = aNullableEnum; - pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); + pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 8); + pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 9); + pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.aNullableEnum = GetNullableObjectAtIndex(list, 11); + pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 12); + pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 13); + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 14); + pigeonResult.list = GetNullableObjectAtIndex(list, 15); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 16); + pigeonResult.intList = GetNullableObjectAtIndex(list, 17); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 18); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 19); + pigeonResult.nestedClassList = GetNullableObjectAtIndex(list, 20); + pigeonResult.map = GetNullableObjectAtIndex(list, 21); return pigeonResult; } -+ (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { ++ (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { return (list) ? [AllNullableTypes fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.aNullableBool ?: [NSNull null], self.aNullableInt ?: [NSNull null], @@ -227,16 +254,20 @@ - (NSArray *)toList { self.aNullable4ByteArray ?: [NSNull null], self.aNullable8ByteArray ?: [NSNull null], self.aNullableFloatArray ?: [NSNull null], - self.aNullableList ?: [NSNull null], - self.aNullableMap ?: [NSNull null], self.nullableNestedList ?: [NSNull null], self.nullableMapWithAnnotations ?: [NSNull null], self.nullableMapWithObject ?: [NSNull null], - (self.aNullableEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:self.aNullableEnum.value]), + self.aNullableEnum ?: [NSNull null], self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], self.allNullableTypes ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.nestedClassList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -250,15 +281,19 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray aNullable8ByteArray:(nullable FlutterStandardTypedData *)aNullable8ByteArray aNullableFloatArray:(nullable FlutterStandardTypedData *)aNullableFloatArray - aNullableList:(nullable NSArray *)aNullableList - aNullableMap:(nullable NSDictionary *)aNullableMap nullableNestedList:(nullable NSArray *> *)nullableNestedList nullableMapWithAnnotations: (nullable NSDictionary *)nullableMapWithAnnotations nullableMapWithObject:(nullable NSDictionary *)nullableMapWithObject aNullableEnum:(nullable AnEnumBox *)aNullableEnum aNullableString:(nullable NSString *)aNullableString - aNullableObject:(nullable id)aNullableObject { + aNullableObject:(nullable id)aNullableObject + list:(nullable NSArray *)list + stringList:(nullable NSArray *)stringList + intList:(nullable NSArray *)intList + doubleList:(nullable NSArray *)doubleList + boolList:(nullable NSArray *)boolList + map:(nullable NSDictionary *)map { AllNullableTypesWithoutRecursion *pigeonResult = [[AllNullableTypesWithoutRecursion alloc] init]; pigeonResult.aNullableBool = aNullableBool; pigeonResult.aNullableInt = aNullableInt; @@ -268,17 +303,21 @@ + (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool pigeonResult.aNullable4ByteArray = aNullable4ByteArray; pigeonResult.aNullable8ByteArray = aNullable8ByteArray; pigeonResult.aNullableFloatArray = aNullableFloatArray; - pigeonResult.aNullableList = aNullableList; - pigeonResult.aNullableMap = aNullableMap; pigeonResult.nullableNestedList = nullableNestedList; pigeonResult.nullableMapWithAnnotations = nullableMapWithAnnotations; pigeonResult.nullableMapWithObject = nullableMapWithObject; pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = aNullableString; pigeonResult.aNullableObject = aNullableObject; + pigeonResult.list = list; + pigeonResult.stringList = stringList; + pigeonResult.intList = intList; + pigeonResult.doubleList = doubleList; + pigeonResult.boolList = boolList; + pigeonResult.map = map; return pigeonResult; } -+ (AllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { ++ (AllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { AllNullableTypesWithoutRecursion *pigeonResult = [[AllNullableTypesWithoutRecursion alloc] init]; pigeonResult.aNullableBool = GetNullableObjectAtIndex(list, 0); pigeonResult.aNullableInt = GetNullableObjectAtIndex(list, 1); @@ -288,25 +327,24 @@ + (AllNullableTypesWithoutRecursion *)fromList:(NSArray *)list { pigeonResult.aNullable4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.aNullable8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aNullableFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aNullableList = GetNullableObjectAtIndex(list, 8); - pigeonResult.aNullableMap = GetNullableObjectAtIndex(list, 9); - pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 10); - pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 11); - pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 12); - NSNumber *aNullableEnumAsNumber = GetNullableObjectAtIndex(list, 13); - AnEnumBox *aNullableEnum = - aNullableEnumAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[aNullableEnumAsNumber integerValue]]; - pigeonResult.aNullableEnum = aNullableEnum; - pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); - pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); + pigeonResult.nullableNestedList = GetNullableObjectAtIndex(list, 8); + pigeonResult.nullableMapWithAnnotations = GetNullableObjectAtIndex(list, 9); + pigeonResult.nullableMapWithObject = GetNullableObjectAtIndex(list, 10); + pigeonResult.aNullableEnum = GetNullableObjectAtIndex(list, 11); + pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 12); + pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 13); + pigeonResult.list = GetNullableObjectAtIndex(list, 14); + pigeonResult.stringList = GetNullableObjectAtIndex(list, 15); + pigeonResult.intList = GetNullableObjectAtIndex(list, 16); + pigeonResult.doubleList = GetNullableObjectAtIndex(list, 17); + pigeonResult.boolList = GetNullableObjectAtIndex(list, 18); + pigeonResult.map = GetNullableObjectAtIndex(list, 19); return pigeonResult; } -+ (nullable AllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list { ++ (nullable AllNullableTypesWithoutRecursion *)nullableFromList:(NSArray *)list { return (list) ? [AllNullableTypesWithoutRecursion fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.aNullableBool ?: [NSNull null], self.aNullableInt ?: [NSNull null], @@ -316,15 +354,18 @@ - (NSArray *)toList { self.aNullable4ByteArray ?: [NSNull null], self.aNullable8ByteArray ?: [NSNull null], self.aNullableFloatArray ?: [NSNull null], - self.aNullableList ?: [NSNull null], - self.aNullableMap ?: [NSNull null], self.nullableNestedList ?: [NSNull null], self.nullableMapWithAnnotations ?: [NSNull null], self.nullableMapWithObject ?: [NSNull null], - (self.aNullableEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:self.aNullableEnum.value]), + self.aNullableEnum ?: [NSNull null], self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], + self.list ?: [NSNull null], + self.stringList ?: [NSNull null], + self.intList ?: [NSNull null], + self.doubleList ?: [NSNull null], + self.boolList ?: [NSNull null], + self.map ?: [NSNull null], ]; } @end @@ -340,17 +381,17 @@ + (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes pigeonResult.allTypes = allTypes; return pigeonResult; } -+ (AllClassesWrapper *)fromList:(NSArray *)list { ++ (AllClassesWrapper *)fromList:(NSArray *)list { AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } -+ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { ++ (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { return (list) ? [AllClassesWrapper fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.allNullableTypes ?: [NSNull null], self.allNullableTypesWithoutRecursion ?: [NSNull null], @@ -360,94 +401,102 @@ - (NSArray *)toList { @end @implementation TestMessage -+ (instancetype)makeWithTestList:(nullable NSArray *)testList { ++ (instancetype)makeWithTestList:(nullable NSArray *)testList { TestMessage *pigeonResult = [[TestMessage alloc] init]; pigeonResult.testList = testList; return pigeonResult; } -+ (TestMessage *)fromList:(NSArray *)list { ++ (TestMessage *)fromList:(NSArray *)list { TestMessage *pigeonResult = [[TestMessage alloc] init]; pigeonResult.testList = GetNullableObjectAtIndex(list, 0); return pigeonResult; } -+ (nullable TestMessage *)nullableFromList:(NSArray *)list { ++ (nullable TestMessage *)nullableFromList:(NSArray *)list { return (list) ? [TestMessage fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ self.testList ?: [NSNull null], ]; } @end -@interface HostIntegrationCoreApiCodecReader : FlutterStandardReader +@interface CoreTestsPigeonCodecReader : FlutterStandardReader @end -@implementation HostIntegrationCoreApiCodecReader +@implementation CoreTestsPigeonCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: - return [AllClassesWrapper fromList:[self readValue]]; case 129: - return [AllNullableTypes fromList:[self readValue]]; + return [AllTypes fromList:[self readValue]]; case 130: - return [AllNullableTypesWithoutRecursion fromList:[self readValue]]; + return [AllNullableTypes fromList:[self readValue]]; case 131: - return [AllTypes fromList:[self readValue]]; + return [AllNullableTypesWithoutRecursion fromList:[self readValue]]; case 132: + return [AllClassesWrapper fromList:[self readValue]]; + case 133: return [TestMessage fromList:[self readValue]]; + case 134: { + NSNumber *enumAsNumber = [self readValue]; + return enumAsNumber == nil ? nil + : [[AnEnumBox alloc] initWithValue:[enumAsNumber integerValue]]; + } default: return [super readValueOfType:type]; } } @end -@interface HostIntegrationCoreApiCodecWriter : FlutterStandardWriter +@interface CoreTestsPigeonCodecWriter : FlutterStandardWriter @end -@implementation HostIntegrationCoreApiCodecWriter +@implementation CoreTestsPigeonCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[AllClassesWrapper class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypes class]]) { + if ([value isKindOfClass:[AllTypes class]]) { [self writeByte:129]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWithoutRecursion class]]) { + } else if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:130]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllTypes class]]) { + } else if ([value isKindOfClass:[AllNullableTypesWithoutRecursion class]]) { [self writeByte:131]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[TestMessage class]]) { + } else if ([value isKindOfClass:[AllClassesWrapper class]]) { [self writeByte:132]; [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[TestMessage class]]) { + [self writeByte:133]; + [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[AnEnumBox class]]) { + AnEnumBox *box = (AnEnumBox *)value; + [self writeByte:134]; + [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; } else { [super writeValue:value]; } } @end -@interface HostIntegrationCoreApiCodecReaderWriter : FlutterStandardReaderWriter +@interface CoreTestsPigeonCodecReaderWriter : FlutterStandardReaderWriter @end -@implementation HostIntegrationCoreApiCodecReaderWriter +@implementation CoreTestsPigeonCodecReaderWriter - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[HostIntegrationCoreApiCodecWriter alloc] initWithData:data]; + return [[CoreTestsPigeonCodecWriter alloc] initWithData:data]; } - (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[HostIntegrationCoreApiCodecReader alloc] initWithData:data]; + return [[CoreTestsPigeonCodecReader alloc] initWithData:data]; } @end -NSObject *HostIntegrationCoreApiGetCodec(void) { +NSObject *GetCoreTestsCodec(void) { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - HostIntegrationCoreApiCodecReaderWriter *readerWriter = - [[HostIntegrationCoreApiCodecReaderWriter alloc] init]; + CoreTestsPigeonCodecReaderWriter *readerWriter = + [[CoreTestsPigeonCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - void SetUpHostIntegrationCoreApi(id binaryMessenger, NSObject *api) { SetUpHostIntegrationCoreApiWithSuffix(binaryMessenger, api, @""); @@ -468,7 +517,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.noop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(noopWithError:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(noopWithError:)", @@ -490,14 +539,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoAllTypes:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoAllTypes:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; AllTypes *output = [api echoAllTypes:arg_everything error:&error]; @@ -515,7 +564,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(throwErrorWithError:)], @@ -538,7 +587,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwErrorFromVoidWithError:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -561,7 +610,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwFlutterError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwFlutterErrorWithError:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -584,13 +633,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoInt:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; NSNumber *output = [api echoInt:arg_anInt error:&error]; @@ -608,13 +657,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoDouble:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; FlutterError *error; NSNumber *output = [api echoDouble:arg_aDouble error:&error]; @@ -632,13 +681,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoBool:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoBool:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; FlutterError *error; NSNumber *output = [api echoBool:arg_aBool error:&error]; @@ -656,13 +705,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoString:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoString:arg_aString error:&error]; @@ -680,14 +729,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoUint8List:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoUint8List:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); FlutterError *error; FlutterStandardTypedData *output = [api echoUint8List:arg_aUint8List error:&error]; @@ -705,13 +754,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoObject:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoObject:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); FlutterError *error; id output = [api echoObject:arg_anObject error:&error]; @@ -729,13 +778,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoList:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoList:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSArray *output = [api echoList:arg_list error:&error]; @@ -753,13 +802,13 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoMap:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSDictionary *output = [api echoMap:arg_aMap error:&error]; @@ -777,14 +826,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoClassWrapper", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoClassWrapper:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoClassWrapper:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; AllClassesWrapper *output = [api echoClassWrapper:arg_wrapper error:&error]; @@ -802,17 +851,17 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoEnum:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoEnum:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - AnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + AnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + AnEnum arg_anEnum = enumBox.value; FlutterError *error; - AnEnumBox *enumBox = [api echoEnum:arg_anEnum error:&error]; - NSNumber *output = enumBox == nil ? nil : [NSNumber numberWithInteger:enumBox.value]; + AnEnumBox *output = [api echoEnum:arg_anEnum error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -827,14 +876,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNamedDefaultString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNamedDefaultString:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNamedDefaultString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNamedDefaultString:arg_aString error:&error]; @@ -853,14 +902,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoOptionalDefaultDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoOptionalDefaultDouble:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoOptionalDefaultDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; FlutterError *error; NSNumber *output = [api echoOptionalDefaultDouble:arg_aDouble error:&error]; @@ -878,14 +927,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoRequiredInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoRequiredInt:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoRequiredInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; NSNumber *output = [api echoRequiredInt:arg_anInt error:&error]; @@ -903,14 +952,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAllNullableTypes:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAllNullableTypes:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; AllNullableTypes *output = [api echoAllNullableTypes:arg_everything error:&error]; @@ -930,14 +979,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAllNullableTypesWithoutRecursion:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAllNullableTypesWithoutRecursion:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); FlutterError *error; AllNullableTypesWithoutRecursion *output = @@ -958,14 +1007,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.extractNestedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(extractNestedNullableStringFrom:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(extractNestedNullableStringFrom:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllClassesWrapper *arg_wrapper = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api extractNestedNullableStringFrom:arg_wrapper error:&error]; @@ -985,14 +1034,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.createNestedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(createNestedObjectWithNullableString:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(createNestedObjectWithNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_nullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; AllClassesWrapper *output = [api createNestedObjectWithNullableString:arg_nullableString @@ -1012,7 +1061,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.sendMultipleNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(sendMultipleNullableTypesABool: anInt:aString:error:)], @@ -1020,7 +1069,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"@selector(sendMultipleNullableTypesABool:anInt:aString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -1045,7 +1094,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.sendMultipleNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (sendMultipleNullableTypesWithoutRecursionABool:anInt:aString:error:)], @@ -1053,7 +1102,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"@selector(sendMultipleNullableTypesWithoutRecursionABool:anInt:aString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -1077,14 +1126,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoNullableInt:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoNullableInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableInt:arg_aNullableInt error:&error]; @@ -1102,14 +1151,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableDouble:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableDouble:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableDouble = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableDouble:arg_aNullableDouble error:&error]; @@ -1127,14 +1176,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoNullableBool:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoNullableBool:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoNullableBool:arg_aNullableBool error:&error]; @@ -1152,14 +1201,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableString:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNullableString:arg_aNullableString error:&error]; @@ -1177,14 +1226,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableUint8List:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableUint8List:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aNullableUint8List = GetNullableObjectAtIndex(args, 0); FlutterError *error; FlutterStandardTypedData *output = [api echoNullableUint8List:arg_aNullableUint8List @@ -1203,14 +1252,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNullableObject:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNullableObject:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_aNullableObject = GetNullableObjectAtIndex(args, 0); FlutterError *error; id output = [api echoNullableObject:arg_aNullableObject error:&error]; @@ -1228,14 +1277,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoNullableList:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoNullableList:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_aNullableList = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSArray *output = [api echoNullableList:arg_aNullableList error:&error]; @@ -1253,14 +1302,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoNullableMap:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoNullableMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aNullableMap = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSDictionary *output = [api echoNullableMap:arg_aNullableMap error:&error]; @@ -1277,22 +1326,17 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoNullableEnum:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoNullableEnum:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - AnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; + NSArray *args = message; + AnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); FlutterError *error; - AnEnumBox *enumBox = [api echoNullableEnum:arg_anEnum error:&error]; - NSNumber *output = enumBox == nil ? nil : [NSNumber numberWithInteger:enumBox.value]; + AnEnumBox *output = [api echoNullableEnum:arg_anEnum error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1308,14 +1352,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoOptionalNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoOptionalNullableInt:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoOptionalNullableInt:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSNumber *output = [api echoOptionalNullableInt:arg_aNullableInt error:&error]; @@ -1334,14 +1378,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoNamedNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoNamedNullableString:error:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoNamedNullableString:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 0); FlutterError *error; NSString *output = [api echoNamedNullableString:arg_aNullableString error:&error]; @@ -1360,7 +1404,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.noopAsync", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(noopAsyncWithCompletion:)], @@ -1383,14 +1427,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoAsyncInt:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoAsyncInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; [api echoAsyncInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1409,14 +1453,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncDouble:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; [api echoAsyncDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1435,14 +1479,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncBool:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; [api echoAsyncBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1461,14 +1505,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncString:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoAsyncString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -1487,14 +1531,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncUint8List:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); [api echoAsyncUint8List:arg_aUint8List completion:^(FlutterStandardTypedData *_Nullable output, @@ -1514,14 +1558,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncObject:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncObject:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); [api echoAsyncObject:arg_anObject completion:^(id _Nullable output, FlutterError *_Nullable error) { @@ -1540,14 +1584,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncList:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -1566,14 +1610,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector(echoAsyncMap:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoAsyncMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api echoAsyncMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -1593,19 +1637,18 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncEnum:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - AnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + AnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + AnEnum arg_anEnum = enumBox.value; [api echoAsyncEnum:arg_anEnum - completion:^(AnEnumBox *_Nullable enumValue, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; + completion:^(AnEnumBox *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; }]; @@ -1621,7 +1664,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwAsyncError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncErrorWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -1645,7 +1688,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwAsyncErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncErrorFromVoidWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -1668,7 +1711,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.throwAsyncFlutterError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(throwAsyncFlutterErrorWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -1692,14 +1735,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncAllTypes:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncAllTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncAllTypes:arg_everything completion:^(AllTypes *_Nullable output, FlutterError *_Nullable error) { @@ -1719,14 +1762,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableAllNullableTypes:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableAllNullableTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableAllNullableTypes:arg_everything completion:^(AllNullableTypes *_Nullable output, @@ -1748,7 +1791,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"echoAsyncNullableAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (echoAsyncNullableAllNullableTypesWithoutRecursion:completion:)], @@ -1756,7 +1799,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"@selector(echoAsyncNullableAllNullableTypesWithoutRecursion:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableAllNullableTypesWithoutRecursion:arg_everything completion:^(AllNullableTypesWithoutRecursion @@ -1777,14 +1820,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableInt:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1804,14 +1847,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableDouble:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1830,14 +1873,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableBool:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -1857,14 +1900,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableString:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -1884,14 +1927,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableUint8List:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_aUint8List = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableUint8List:arg_aUint8List completion:^(FlutterStandardTypedData *_Nullable output, @@ -1912,14 +1955,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableObject", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableObject:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableObject:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; id arg_anObject = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableObject:arg_anObject completion:^(id _Nullable output, FlutterError *_Nullable error) { @@ -1938,14 +1981,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableList:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -1964,14 +2007,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableMap:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api echoAsyncNullableMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -1991,26 +2034,19 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.echoAsyncNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoAsyncNullableEnum:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(echoAsyncNullableEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - AnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; - [api - echoAsyncNullableEnum:arg_anEnum - completion:^(AnEnumBox *_Nullable enumValue, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; - callback(wrapResult(output, error)); - }]; + NSArray *args = message; + AnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); + [api echoAsyncNullableEnum:arg_anEnum + completion:^(AnEnumBox *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; }]; } else { [channel setMessageHandler:nil]; @@ -2023,7 +2059,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterNoop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterNoopWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -2045,7 +2081,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterThrowError", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterThrowErrorWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -2069,7 +2105,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterThrowErrorFromVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterThrowErrorFromVoidWithCompletion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @@ -2092,14 +2128,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoAllTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoAllTypes:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoAllTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllTypes:arg_everything completion:^(AllTypes *_Nullable output, FlutterError *_Nullable error) { @@ -2118,14 +2154,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoAllNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoAllNullableTypes:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoAllNullableTypes:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypes *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllNullableTypes:arg_everything completion:^(AllNullableTypes *_Nullable output, @@ -2146,7 +2182,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)], @@ -2154,7 +2190,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"@selector(callFlutterSendMultipleNullableTypesABool:anInt:aString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -2179,7 +2215,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"callFlutterEchoAllNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector (callFlutterEchoAllNullableTypesWithoutRecursion:completion:)], @@ -2187,7 +2223,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"@selector(callFlutterEchoAllNullableTypesWithoutRecursion:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; AllNullableTypesWithoutRecursion *arg_everything = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoAllNullableTypesWithoutRecursion:arg_everything completion:^(AllNullableTypesWithoutRecursion @@ -2209,7 +2245,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"callFlutterSendMultipleNullableTypesWithoutRecursion", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert( [api respondsToSelector:@selector @@ -2220,7 +2256,7 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aNullableBool = GetNullableObjectAtIndex(args, 0); NSNumber *arg_aNullableInt = GetNullableObjectAtIndex(args, 1); NSString *arg_aNullableString = GetNullableObjectAtIndex(args, 2); @@ -2245,14 +2281,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoBool:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; BOOL arg_aBool = [GetNullableObjectAtIndex(args, 0) boolValue]; [api callFlutterEchoBool:arg_aBool completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2270,14 +2306,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoInt:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSInteger arg_anInt = [GetNullableObjectAtIndex(args, 0) integerValue]; [api callFlutterEchoInt:arg_anInt completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2295,14 +2331,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoDouble:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; double arg_aDouble = [GetNullableObjectAtIndex(args, 0) doubleValue]; [api callFlutterEchoDouble:arg_aDouble completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { @@ -2320,14 +2356,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoString:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -2346,14 +2382,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoUint8List:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, @@ -2372,14 +2408,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoList:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { @@ -2397,14 +2433,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoMap:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -2423,19 +2459,18 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoEnum:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - AnEnum arg_anEnum = [GetNullableObjectAtIndex(args, 0) integerValue]; + NSArray *args = message; + AnEnumBox *enumBox = GetNullableObjectAtIndex(args, 0); + AnEnum arg_anEnum = enumBox.value; [api callFlutterEchoEnum:arg_anEnum - completion:^(AnEnumBox *_Nullable enumValue, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil : [NSNumber numberWithInteger:enumValue.value]; + completion:^(AnEnumBox *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; }]; @@ -2451,14 +2486,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableBool", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableBool:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableBool:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aBool = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableBool:arg_aBool completion:^(NSNumber *_Nullable output, @@ -2478,14 +2513,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableInt", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableInt:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableInt:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_anInt = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableInt:arg_anInt completion:^(NSNumber *_Nullable output, @@ -2505,14 +2540,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableDouble", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableDouble:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableDouble:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSNumber *arg_aDouble = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableDouble:arg_aDouble completion:^(NSNumber *_Nullable output, @@ -2532,14 +2567,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableString:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableString:arg_aString completion:^(NSString *_Nullable output, @@ -2559,14 +2594,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableUint8List", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableUint8List:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableUint8List:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, @@ -2586,14 +2621,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableList", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableList:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableList:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSArray *arg_list = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, @@ -2613,14 +2648,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableMap", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableMap:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableMap:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSDictionary *arg_aMap = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableMap:arg_aMap completion:^(NSDictionary *_Nullable output, @@ -2640,25 +2675,18 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterEchoNullableEnum", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterEchoNullableEnum:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterEchoNullableEnum:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_anEnumAsNumber = GetNullableObjectAtIndex(args, 0); - AnEnumBox *arg_anEnum = - arg_anEnumAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[arg_anEnumAsNumber integerValue]]; + NSArray *args = message; + AnEnumBox *arg_anEnum = GetNullableObjectAtIndex(args, 0); [api callFlutterEchoNullableEnum:arg_anEnum - completion:^(AnEnumBox *_Nullable enumValue, + completion:^(AnEnumBox *_Nullable output, FlutterError *_Nullable error) { - NSNumber *output = - enumValue == nil ? nil - : [NSNumber numberWithInteger:enumValue.value]; callback(wrapResult(output, error)); }]; }]; @@ -2674,14 +2702,14 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess @"HostIntegrationCoreApi.callFlutterSmallApiEchoString", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(callFlutterSmallApiEchoString:completion:)], @"HostIntegrationCoreApi api (%@) doesn't respond to " @"@selector(callFlutterSmallApiEchoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api callFlutterSmallApiEchoString:arg_aString completion:^(NSString *_Nullable output, @@ -2694,74 +2722,6 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess } } } -@interface FlutterIntegrationCoreApiCodecReader : FlutterStandardReader -@end -@implementation FlutterIntegrationCoreApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [AllClassesWrapper fromList:[self readValue]]; - case 129: - return [AllNullableTypes fromList:[self readValue]]; - case 130: - return [AllNullableTypesWithoutRecursion fromList:[self readValue]]; - case 131: - return [AllTypes fromList:[self readValue]]; - case 132: - return [TestMessage fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FlutterIntegrationCoreApiCodecWriter : FlutterStandardWriter -@end -@implementation FlutterIntegrationCoreApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[AllClassesWrapper class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypes class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWithoutRecursion class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllTypes class]]) { - [self writeByte:131]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[TestMessage class]]) { - [self writeByte:132]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FlutterIntegrationCoreApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FlutterIntegrationCoreApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FlutterIntegrationCoreApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FlutterIntegrationCoreApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FlutterIntegrationCoreApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FlutterIntegrationCoreApiCodecReaderWriter *readerWriter = - [[FlutterIntegrationCoreApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - @interface FlutterIntegrationCoreApi () @property(nonatomic, strong) NSObject *binaryMessenger; @property(nonatomic, strong) NSString *messageChannelSuffix; @@ -2791,7 +2751,7 @@ - (void)noopWithCompletion:(void (^)(FlutterError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2816,7 +2776,7 @@ - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2842,7 +2802,7 @@ - (void)throwErrorFromVoidWithCompletion:(void (^)(FlutterError *_Nullable))comp FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2868,7 +2828,7 @@ - (void)echoAllTypes:(AllTypes *)arg_everything FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2896,7 +2856,7 @@ - (void)echoAllNullableTypes:(nullable AllNullableTypes *)arg_everything FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2926,7 +2886,7 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -2958,7 +2918,7 @@ - (void)echoAllNullableTypesWithoutRecursion: FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2991,7 +2951,7 @@ - (void)echoAllNullableTypesWithoutRecursion: FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -3022,7 +2982,7 @@ - (void)echoBool:(BOOL)arg_aBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_aBool) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3048,7 +3008,7 @@ - (void)echoInt:(NSInteger)arg_anInt FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_anInt) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3075,7 +3035,7 @@ - (void)echoDouble:(double)arg_aDouble FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ @(arg_aDouble) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3102,7 +3062,7 @@ - (void)echoString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3130,7 +3090,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3158,7 +3118,7 @@ - (void)echoList:(NSArray *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3185,7 +3145,7 @@ - (void)echoMap:(NSDictionary *)arg_aMap FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3213,8 +3173,8 @@ - (void)echoEnum:(AnEnum)arg_anEnum FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ [NSNumber numberWithInteger:arg_anEnum] ] + codec:GetCoreTestsCodec()]; + [channel sendMessage:@[ [[AnEnumBox alloc] initWithValue:arg_anEnum] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3222,11 +3182,7 @@ - (void)echoEnum:(AnEnum)arg_anEnum message:reply[1] details:reply[2]]); } else { - NSNumber *outputAsNumber = reply[0] == [NSNull null] ? nil : reply[0]; - AnEnumBox *output = - outputAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[outputAsNumber integerValue]]; + AnEnumBox *output = reply[0] == [NSNull null] ? nil : reply[0]; completion(output, nil); } } else { @@ -3244,7 +3200,7 @@ - (void)echoNullableBool:(nullable NSNumber *)arg_aBool FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3271,7 +3227,7 @@ - (void)echoNullableInt:(nullable NSNumber *)arg_anInt FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3298,7 +3254,7 @@ - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3325,7 +3281,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3353,7 +3309,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3381,7 +3337,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_list FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3409,7 +3365,7 @@ - (void)echoNullableMap:(nullable NSDictionary *)arg_aMap FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3437,9 +3393,8 @@ - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] - : [NSNumber numberWithInteger:arg_anEnum.value] ] + codec:GetCoreTestsCodec()]; + [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] : arg_anEnum ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3447,11 +3402,7 @@ - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum message:reply[1] details:reply[2]]); } else { - NSNumber *outputAsNumber = reply[0] == [NSNull null] ? nil : reply[0]; - AnEnumBox *output = - outputAsNumber == nil - ? nil - : [[AnEnumBox alloc] initWithValue:[outputAsNumber integerValue]]; + AnEnumBox *output = reply[0] == [NSNull null] ? nil : reply[0]; completion(output, nil); } } else { @@ -3468,7 +3419,7 @@ - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -3494,7 +3445,7 @@ - (void)echoAsyncString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3513,12 +3464,6 @@ - (void)echoAsyncString:(NSString *)arg_aString } @end -NSObject *HostTrivialApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - void SetUpHostTrivialApi(id binaryMessenger, NSObject *api) { SetUpHostTrivialApiWithSuffix(binaryMessenger, api, @""); @@ -3537,7 +3482,7 @@ void SetUpHostTrivialApiWithSuffix(id binaryMessenger, @"dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostTrivialApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(noopWithError:)], @"HostTrivialApi api (%@) doesn't respond to @selector(noopWithError:)", api); @@ -3551,12 +3496,6 @@ void SetUpHostTrivialApiWithSuffix(id binaryMessenger, } } } -NSObject *HostSmallApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - void SetUpHostSmallApi(id binaryMessenger, NSObject *api) { SetUpHostSmallApiWithSuffix(binaryMessenger, api, @""); } @@ -3574,12 +3513,12 @@ void SetUpHostSmallApiWithSuffix(id binaryMessenger, @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostSmallApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(echoString:completion:)], @"HostSmallApi api (%@) doesn't respond to @selector(echoString:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; NSString *arg_aString = GetNullableObjectAtIndex(args, 0); [api echoString:arg_aString completion:^(NSString *_Nullable output, FlutterError *_Nullable error) { @@ -3597,7 +3536,7 @@ void SetUpHostSmallApiWithSuffix(id binaryMessenger, @"HostSmallApi.voidVoid", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:HostSmallApiGetCodec()]; + codec:GetCoreTestsCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(voidVoidWithCompletion:)], @"HostSmallApi api (%@) doesn't respond to @selector(voidVoidWithCompletion:)", @@ -3612,54 +3551,6 @@ void SetUpHostSmallApiWithSuffix(id binaryMessenger, } } } -@interface FlutterSmallApiCodecReader : FlutterStandardReader -@end -@implementation FlutterSmallApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [TestMessage fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FlutterSmallApiCodecWriter : FlutterStandardWriter -@end -@implementation FlutterSmallApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[TestMessage class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FlutterSmallApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FlutterSmallApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FlutterSmallApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FlutterSmallApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FlutterSmallApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FlutterSmallApiCodecReaderWriter *readerWriter = - [[FlutterSmallApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - @interface FlutterSmallApi () @property(nonatomic, strong) NSObject *binaryMessenger; @property(nonatomic, strong) NSString *messageChannelSuffix; @@ -3690,7 +3581,7 @@ - (void)echoWrappedList:(TestMessage *)arg_msg FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_msg ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -3716,7 +3607,7 @@ - (void)echoString:(NSString *)arg_aString FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + codec:GetCoreTestsCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { 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 85484362b3a..d108f4892f0 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 @@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'generated.dart'; +import 'src/generated/core_tests.gen.dart'; const int _biggerThanBigInt = 3000000000; const int _regularInt = 42; @@ -49,10 +50,14 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(allTypesOne.a4ByteArray, allTypesTwo.a4ByteArray); expect(allTypesOne.a8ByteArray, allTypesTwo.a8ByteArray); expect(allTypesOne.aFloatArray, allTypesTwo.aFloatArray); - expect(listEquals(allTypesOne.list, allTypesTwo.list), true); - expect(mapEquals(allTypesOne.aMap, allTypesTwo.aMap), true); expect(allTypesOne.anEnum, allTypesTwo.anEnum); expect(allTypesOne.anObject, allTypesTwo.anObject); + expect(listEquals(allTypesOne.list, allTypesTwo.list), true); + expect(listEquals(allTypesOne.stringList, allTypesTwo.stringList), true); + expect(listEquals(allTypesOne.boolList, allTypesTwo.boolList), true); + expect(listEquals(allTypesOne.doubleList, allTypesTwo.doubleList), true); + expect(listEquals(allTypesOne.intList, allTypesTwo.intList), true); + expect(mapEquals(allTypesOne.map, allTypesTwo.map), true); } void compareAllNullableTypes(AllNullableTypes? allNullableTypesOne, @@ -78,14 +83,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { allNullableTypesTwo.aNullable8ByteArray); expect(allNullableTypesOne.aNullableFloatArray, allNullableTypesTwo.aNullableFloatArray); - expect( - listEquals(allNullableTypesOne.aNullableList, - allNullableTypesTwo.aNullableList), - true); - expect( - mapEquals( - allNullableTypesOne.aNullableMap, allNullableTypesTwo.aNullableMap), - true); expect(allNullableTypesOne.nullableNestedList?.length, allNullableTypesTwo.nullableNestedList?.length); // TODO(stuartmorgan): Enable this once the Dart types are fixed; see @@ -108,6 +105,30 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { allNullableTypesOne.aNullableEnum, allNullableTypesTwo.aNullableEnum); compareAllNullableTypes(allNullableTypesOne.allNullableTypes, allNullableTypesTwo.allNullableTypes); + expect( + listEquals(allNullableTypesOne.list, allNullableTypesTwo.list), true); + expect( + listEquals( + allNullableTypesOne.stringList, allNullableTypesTwo.stringList), + true); + expect( + listEquals(allNullableTypesOne.boolList, allNullableTypesTwo.boolList), + true); + expect( + listEquals( + allNullableTypesOne.doubleList, allNullableTypesTwo.doubleList), + true); + expect(listEquals(allNullableTypesOne.intList, allNullableTypesTwo.intList), + true); + expect(allNullableTypesOne.nestedClassList?.length, + allNullableTypesTwo.nestedClassList?.length); + for (int i = 0; + i < (allNullableTypesOne.nestedClassList?.length ?? 0); + i++) { + compareAllNullableTypes(allNullableTypesOne.nestedClassList?[i], + allNullableTypesTwo.nestedClassList?[i]); + } + expect(mapEquals(allNullableTypesOne.map, allNullableTypesTwo.map), true); } void compareAllNullableTypesWithoutRecursion( @@ -134,14 +155,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { allNullableTypesTwo.aNullable8ByteArray); expect(allNullableTypesOne.aNullableFloatArray, allNullableTypesTwo.aNullableFloatArray); - expect( - listEquals(allNullableTypesOne.aNullableList, - allNullableTypesTwo.aNullableList), - true); - expect( - mapEquals( - allNullableTypesOne.aNullableMap, allNullableTypesTwo.aNullableMap), - true); expect(allNullableTypesOne.nullableNestedList?.length, allNullableTypesTwo.nullableNestedList?.length); // TODO(stuartmorgan): Enable this once the Dart types are fixed; see @@ -162,6 +175,22 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { allNullableTypesTwo.aNullableObject); expect( allNullableTypesOne.aNullableEnum, allNullableTypesTwo.aNullableEnum); + expect( + listEquals(allNullableTypesOne.list, allNullableTypesTwo.list), true); + expect( + listEquals( + allNullableTypesOne.stringList, allNullableTypesTwo.stringList), + true); + expect( + listEquals(allNullableTypesOne.boolList, allNullableTypesTwo.boolList), + true); + expect( + listEquals( + allNullableTypesOne.doubleList, allNullableTypesTwo.doubleList), + true); + expect(listEquals(allNullableTypesOne.intList, allNullableTypesTwo.intList), + true); + expect(mapEquals(allNullableTypesOne.map, allNullableTypesTwo.map), true); } void compareAllClassesWrapper( @@ -180,6 +209,54 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { compareAllTypes(wrapperOne.allTypes, wrapperTwo.allTypes); } + final Map map = { + 'a': 1, + 'b': 2.0, + 'c': 'three', + 'd': false, + 'e': null + }; + + final List list = [ + 'Thing 1', + 2, + true, + 3.14, + null, + ]; + + final List stringList = [ + 'Thing 1', + '2', + 'true', + '3.14', + null, + ]; + + final List intList = [ + 1, + 2, + 3, + 4, + null, + ]; + + final List doubleList = [ + 1, + 2.99999, + 3, + 3.14, + null, + ]; + + final List boolList = [ + true, + false, + true, + false, + null, + ]; + final AllTypes genericAllTypes = AllTypes( aBool: true, anInt: _regularInt, @@ -190,16 +267,14 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { a4ByteArray: Int32List.fromList([4, 5, 6]), a8ByteArray: Int64List.fromList([7, 8, 9]), aFloatArray: Float64List.fromList([2.71828, _doublePi]), - list: ['Thing 1', 2, true, 3.14, null], - aMap: { - 'a': 1, - 'b': 2.0, - 'c': 'three', - 'd': false, - 'e': null - }, anEnum: AnEnum.fortyTwo, anObject: 1, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map, ); final AllNullableTypes genericAllNullableTypes = AllNullableTypes( @@ -212,14 +287,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { aNullable4ByteArray: Int32List.fromList([4, 5, 6]), aNullable8ByteArray: Int64List.fromList([7, 8, 9]), aNullableFloatArray: Float64List.fromList([2.71828, _doublePi]), - aNullableList: ['Thing 1', 2, true, 3.14, null], - aNullableMap: { - 'a': 1, - 'b': 2.0, - 'c': 'three', - 'd': false, - 'e': null - }, nullableNestedList: >[ [true, false], [false, true] @@ -228,8 +295,20 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { nullableMapWithObject: {}, aNullableEnum: AnEnum.fourHundredTwentyTwo, aNullableObject: 0, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map, ); + final List allNullableTypesList = [ + genericAllNullableTypes, + AllNullableTypes(), + null, + ]; + final AllNullableTypes recursiveAllNullableTypes = AllNullableTypes( aNullableBool: true, aNullableInt: _regularInt, @@ -240,14 +319,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { aNullable4ByteArray: Int32List.fromList([4, 5, 6]), aNullable8ByteArray: Int64List.fromList([7, 8, 9]), aNullableFloatArray: Float64List.fromList([2.71828, _doublePi]), - aNullableList: ['Thing 1', 2, true, 3.14, null], - aNullableMap: { - 'a': 1, - 'b': 2.0, - 'c': 'three', - 'd': false, - 'e': null - }, nullableNestedList: >[ [true, false], [false, true] @@ -257,6 +328,13 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { aNullableEnum: AnEnum.fourHundredTwentyTwo, aNullableObject: 0, allNullableTypes: genericAllNullableTypes, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + nestedClassList: allNullableTypesList, + map: map, ); final AllNullableTypesWithoutRecursion @@ -271,14 +349,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { aNullable4ByteArray: Int32List.fromList([4, 5, 6]), aNullable8ByteArray: Int64List.fromList([7, 8, 9]), aNullableFloatArray: Float64List.fromList([2.71828, _doublePi]), - aNullableList: ['Thing 1', 2, true, 3.14, null], - aNullableMap: { - 'a': 1, - 'b': 2.0, - 'c': 'three', - 'd': false, - 'e': null - }, nullableNestedList: >[ [true, false], [false, true] @@ -287,6 +357,12 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { nullableMapWithObject: {}, aNullableEnum: AnEnum.fourHundredTwentyTwo, aNullableObject: 0, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map, ); group('Host sync API tests', () { @@ -330,7 +406,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); final AllNullableTypes nullableListTypes = - AllNullableTypes(aNullableList: ['String', null]); + AllNullableTypes(list: ['String', null]); final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); @@ -343,7 +419,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); final AllNullableTypes nullableListTypes = AllNullableTypes( - aNullableMap: {'String': 'string', 'null': null}); + map: {'String': 'string', 'null': null}); final AllNullableTypes? echoNullFilledClass = await api.echoAllNullableTypes(nullableListTypes); @@ -385,7 +461,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final AllNullableTypesWithoutRecursion nullableListTypes = AllNullableTypesWithoutRecursion( - aNullableList: ['String', null]); + list: ['String', null], + ); final AllNullableTypesWithoutRecursion? echoNullFilledClass = await api.echoAllNullableTypesWithoutRecursion(nullableListTypes); @@ -400,10 +477,9 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); final AllNullableTypesWithoutRecursion nullableListTypes = - AllNullableTypesWithoutRecursion(aNullableMap: { - 'String': 'string', - 'null': null - }); + AllNullableTypesWithoutRecursion( + map: {'String': 'string', 'null': null}, + ); final AllNullableTypesWithoutRecursion? echoNullFilledClass = await api.echoAllNullableTypesWithoutRecursion(nullableListTypes); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart index 461683120ce..e9e063126c1 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart @@ -19,6 +19,10 @@ PlatformException _createConnectionError(String channelName) { ); } +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); +} + class BackgroundApi2Host { /// Constructor for [BackgroundApi2Host]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -30,8 +34,7 @@ class BackgroundApi2Host { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; 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 2f24cdcb2ca..e192a84ceea 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 @@ -49,11 +49,15 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.list = const [], - this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', this.anObject = 0, + required this.list, + required this.stringList, + required this.intList, + required this.doubleList, + required this.boolList, + required this.map, }); bool aBool; @@ -72,16 +76,24 @@ class AllTypes { Float64List aFloatArray; - List list; - - Map aMap; - AnEnum anEnum; String aString; Object anObject; + List list; + + List stringList; + + List intList; + + List doubleList; + + List boolList; + + Map map; + Object encode() { return [ aBool, @@ -92,11 +104,15 @@ class AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - list, - aMap, - anEnum.index, + anEnum, aString, anObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ]; } @@ -111,11 +127,15 @@ class AllTypes { a4ByteArray: result[5]! as Int32List, a8ByteArray: result[6]! as Int64List, aFloatArray: result[7]! as Float64List, - list: result[8]! as List, - aMap: result[9]! as Map, - anEnum: AnEnum.values[result[10]! as int], - aString: result[11]! as String, - anObject: result[12]!, + anEnum: result[8]! as AnEnum, + aString: result[9]! as String, + anObject: result[10]!, + list: result[11]! as List, + stringList: (result[12] as List?)!.cast(), + intList: (result[13] as List?)!.cast(), + doubleList: (result[14] as List?)!.cast(), + boolList: (result[15] as List?)!.cast(), + map: result[16]! as Map, ); } } @@ -131,8 +151,6 @@ class AllNullableTypes { this.aNullable4ByteArray, this.aNullable8ByteArray, this.aNullableFloatArray, - this.aNullableList, - this.aNullableMap, this.nullableNestedList, this.nullableMapWithAnnotations, this.nullableMapWithObject, @@ -140,6 +158,13 @@ class AllNullableTypes { this.aNullableString, this.aNullableObject, this.allNullableTypes, + this.list, + this.stringList, + this.intList, + this.doubleList, + this.boolList, + this.nestedClassList, + this.map, }); bool? aNullableBool; @@ -158,10 +183,6 @@ class AllNullableTypes { Float64List? aNullableFloatArray; - List? aNullableList; - - Map? aNullableMap; - List?>? nullableNestedList; Map? nullableMapWithAnnotations; @@ -176,6 +197,20 @@ class AllNullableTypes { AllNullableTypes? allNullableTypes; + List? list; + + List? stringList; + + List? intList; + + List? doubleList; + + List? boolList; + + List? nestedClassList; + + Map? map; + Object encode() { return [ aNullableBool, @@ -186,15 +221,20 @@ class AllNullableTypes { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.index, + aNullableEnum, aNullableString, aNullableObject, allNullableTypes, + list, + stringList, + intList, + doubleList, + boolList, + nestedClassList, + map, ]; } @@ -209,18 +249,23 @@ class AllNullableTypes { aNullable4ByteArray: result[5] as Int32List?, aNullable8ByteArray: result[6] as Int64List?, aNullableFloatArray: result[7] as Float64List?, - aNullableList: result[8] as List?, - aNullableMap: result[9] as Map?, - nullableNestedList: (result[10] as List?)?.cast?>(), + nullableNestedList: (result[8] as List?)?.cast?>(), nullableMapWithAnnotations: - (result[11] as Map?)?.cast(), + (result[9] as Map?)?.cast(), nullableMapWithObject: - (result[12] as Map?)?.cast(), - aNullableEnum: - result[13] != null ? AnEnum.values[result[13]! as int] : null, - aNullableString: result[14] as String?, - aNullableObject: result[15], - allNullableTypes: result[16] as AllNullableTypes?, + (result[10] as Map?)?.cast(), + aNullableEnum: result[11] as AnEnum?, + aNullableString: result[12] as String?, + aNullableObject: result[13], + allNullableTypes: result[14] as AllNullableTypes?, + list: result[15] as List?, + stringList: (result[16] as List?)?.cast(), + intList: (result[17] as List?)?.cast(), + doubleList: (result[18] as List?)?.cast(), + boolList: (result[19] as List?)?.cast(), + nestedClassList: + (result[20] as List?)?.cast(), + map: result[21] as Map?, ); } } @@ -238,14 +283,18 @@ class AllNullableTypesWithoutRecursion { this.aNullable4ByteArray, this.aNullable8ByteArray, this.aNullableFloatArray, - this.aNullableList, - this.aNullableMap, this.nullableNestedList, this.nullableMapWithAnnotations, this.nullableMapWithObject, this.aNullableEnum, this.aNullableString, this.aNullableObject, + this.list, + this.stringList, + this.intList, + this.doubleList, + this.boolList, + this.map, }); bool? aNullableBool; @@ -264,10 +313,6 @@ class AllNullableTypesWithoutRecursion { Float64List? aNullableFloatArray; - List? aNullableList; - - Map? aNullableMap; - List?>? nullableNestedList; Map? nullableMapWithAnnotations; @@ -280,6 +325,18 @@ class AllNullableTypesWithoutRecursion { Object? aNullableObject; + List? list; + + List? stringList; + + List? intList; + + List? doubleList; + + List? boolList; + + Map? map; + Object encode() { return [ aNullableBool, @@ -290,14 +347,18 @@ class AllNullableTypesWithoutRecursion { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.index, + aNullableEnum, aNullableString, aNullableObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ]; } @@ -312,17 +373,20 @@ class AllNullableTypesWithoutRecursion { aNullable4ByteArray: result[5] as Int32List?, aNullable8ByteArray: result[6] as Int64List?, aNullableFloatArray: result[7] as Float64List?, - aNullableList: result[8] as List?, - aNullableMap: result[9] as Map?, - nullableNestedList: (result[10] as List?)?.cast?>(), + nullableNestedList: (result[8] as List?)?.cast?>(), nullableMapWithAnnotations: - (result[11] as Map?)?.cast(), + (result[9] as Map?)?.cast(), nullableMapWithObject: - (result[12] as Map?)?.cast(), - aNullableEnum: - result[13] != null ? AnEnum.values[result[13]! as int] : null, - aNullableString: result[14] as String?, - aNullableObject: result[15], + (result[10] as Map?)?.cast(), + aNullableEnum: result[11] as AnEnum?, + aNullableString: result[12] as String?, + aNullableObject: result[13], + list: result[14] as List?, + stringList: (result[15] as List?)?.cast(), + intList: (result[16] as List?)?.cast(), + doubleList: (result[17] as List?)?.cast(), + boolList: (result[18] as List?)?.cast(), + map: result[19] as Map?, ); } } @@ -386,25 +450,28 @@ class TestMessage { } } -class _HostIntegrationCoreApiCodec extends StandardMessageCodec { - const _HostIntegrationCoreApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllClassesWrapper) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is AllNullableTypes) { + if (value is AllTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWithoutRecursion) { + } else if (value is AllNullableTypes) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is AllTypes) { + } else if (value is AllNullableTypesWithoutRecursion) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is TestMessage) { + } else if (value is AllClassesWrapper) { buffer.putUint8(132); writeValue(buffer, value.encode()); + } else if (value is TestMessage) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is AnEnum) { + buffer.putUint8(134); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -413,16 +480,19 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return AllClassesWrapper.decode(readValue(buffer)!); case 129: - return AllNullableTypes.decode(readValue(buffer)!); + return AllTypes.decode(readValue(buffer)!); case 130: - return AllNullableTypesWithoutRecursion.decode(readValue(buffer)!); + return AllNullableTypes.decode(readValue(buffer)!); case 131: - return AllTypes.decode(readValue(buffer)!); + return AllNullableTypesWithoutRecursion.decode(readValue(buffer)!); case 132: + return AllClassesWrapper.decode(readValue(buffer)!); + case 133: return TestMessage.decode(readValue(buffer)!); + case 134: + final int? value = readValue(buffer) as int?; + return value == null ? null : AnEnum.values[value]; default: return super.readValueOfType(type, buffer); } @@ -442,8 +512,7 @@ class HostIntegrationCoreApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _HostIntegrationCoreApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -860,7 +929,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -875,7 +944,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?)!; } } @@ -1358,7 +1427,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum?.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1368,9 +1437,7 @@ class HostIntegrationCoreApi { details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?); } } @@ -1702,7 +1769,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1717,7 +1784,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?)!; } } @@ -2092,7 +2159,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum?.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2102,9 +2169,7 @@ class HostIntegrationCoreApi { details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?); } } @@ -2538,7 +2603,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2553,7 +2618,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?)!; } } @@ -2738,7 +2803,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([anEnum?.index]) as List?; + await __pigeon_channel.send([anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2748,9 +2813,7 @@ class HostIntegrationCoreApi { details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : AnEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as AnEnum?); } } @@ -2784,54 +2847,10 @@ class HostIntegrationCoreApi { } } -class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec { - const _FlutterIntegrationCoreApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllClassesWrapper) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is AllNullableTypes) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWithoutRecursion) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else if (value is AllTypes) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is TestMessage) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return AllClassesWrapper.decode(readValue(buffer)!); - case 129: - return AllNullableTypes.decode(readValue(buffer)!); - case 130: - return AllNullableTypesWithoutRecursion.decode(readValue(buffer)!); - case 131: - return AllTypes.decode(readValue(buffer)!); - case 132: - return TestMessage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. abstract class FlutterIntegrationCoreApi { - static const MessageCodec pigeonChannelCodec = - _FlutterIntegrationCoreApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. @@ -3347,13 +3366,12 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum was null.'); final List args = (message as List?)!; - final AnEnum? arg_anEnum = - args[0] == null ? null : AnEnum.values[args[0]! as int]; + final AnEnum? arg_anEnum = (args[0] as AnEnum?); assert(arg_anEnum != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum was null, expected non-null AnEnum.'); try { final AnEnum output = api.echoEnum(arg_anEnum!); - return wrapResponse(result: output.index); + return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); } catch (e) { @@ -3560,11 +3578,10 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum was null.'); final List args = (message as List?)!; - final AnEnum? arg_anEnum = - args[0] == null ? null : AnEnum.values[args[0]! as int]; + final AnEnum? arg_anEnum = (args[0] as AnEnum?); try { final AnEnum? output = api.echoNullableEnum(arg_anEnum); - return wrapResponse(result: output?.index); + return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); } catch (e) { @@ -3639,8 +3656,7 @@ class HostTrivialApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -3681,8 +3697,7 @@ class HostSmallApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -3740,33 +3755,9 @@ class HostSmallApi { } } -class _FlutterSmallApiCodec extends StandardMessageCodec { - const _FlutterSmallApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is TestMessage) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return TestMessage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// A simple API called in some unit tests. abstract class FlutterSmallApi { - static const MessageCodec pigeonChannelCodec = - _FlutterSmallApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); TestMessage echoWrappedList(TestMessage msg); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart index 374f272c358..e2ca92672ed 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart @@ -56,25 +56,28 @@ class DataWithEnum { Object encode() { return [ - state?.index, + state, ]; } static DataWithEnum decode(Object result) { result as List; return DataWithEnum( - state: result[0] != null ? EnumState.values[result[0]! as int] : null, + state: result[0] as EnumState?, ); } } -class _EnumApi2HostCodec extends StandardMessageCodec { - const _EnumApi2HostCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is DataWithEnum) { - buffer.putUint8(128); + buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is EnumState) { + buffer.putUint8(130); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -83,8 +86,11 @@ class _EnumApi2HostCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return DataWithEnum.decode(readValue(buffer)!); + case 130: + final int? value = readValue(buffer) as int?; + return value == null ? null : EnumState.values[value]; default: return super.readValueOfType(type, buffer); } @@ -103,7 +109,7 @@ class EnumApi2Host { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = _EnumApi2HostCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -138,33 +144,9 @@ class EnumApi2Host { } } -class _EnumApi2FlutterCodec extends StandardMessageCodec { - const _EnumApi2FlutterCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is DataWithEnum) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return DataWithEnum.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// This comment is to test api documentation comments. abstract class EnumApi2Flutter { - static const MessageCodec pigeonChannelCodec = - _EnumApi2FlutterCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// This comment is to test method documentation comments. DataWithEnum echo(DataWithEnum data); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart index b37dffb2557..61e4b97a5fe 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart @@ -108,22 +108,22 @@ class FlutterSearchReplies { } } -class _ApiCodec extends StandardMessageCodec { - const _ApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is FlutterSearchReplies) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is FlutterSearchReply) { + if (value is FlutterSearchRequest) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is FlutterSearchRequest) { + } else if (value is FlutterSearchReply) { buffer.putUint8(130); writeValue(buffer, value.encode()); } else if (value is FlutterSearchRequests) { buffer.putUint8(131); writeValue(buffer, value.encode()); + } else if (value is FlutterSearchReplies) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -132,14 +132,14 @@ class _ApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return FlutterSearchReplies.decode(readValue(buffer)!); case 129: - return FlutterSearchReply.decode(readValue(buffer)!); - case 130: return FlutterSearchRequest.decode(readValue(buffer)!); + case 130: + return FlutterSearchReply.decode(readValue(buffer)!); case 131: return FlutterSearchRequests.decode(readValue(buffer)!); + case 132: + return FlutterSearchReplies.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -156,7 +156,7 @@ class Api { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = _ApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart index c4f744b5fb8..fb7e65c9483 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart @@ -103,7 +103,7 @@ class MessageSearchReply { return [ result, error, - state?.index, + state, ]; } @@ -112,9 +112,7 @@ class MessageSearchReply { return MessageSearchReply( result: result[0] as String?, error: result[1] as String?, - state: result[2] != null - ? MessageRequestState.values[result[2]! as int] - : null, + state: result[2] as MessageRequestState?, ); } } @@ -142,16 +140,22 @@ class MessageNested { } } -class _MessageApiCodec extends StandardMessageCodec { - const _MessageApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { + if (value is MessageSearchRequest) { buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is MessageSearchReply) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is MessageNested) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is MessageRequestState) { + buffer.putUint8(132); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -160,10 +164,15 @@ class _MessageApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return MessageSearchReply.decode(readValue(buffer)!); case 129: return MessageSearchRequest.decode(readValue(buffer)!); + case 130: + return MessageSearchReply.decode(readValue(buffer)!); + case 131: + return MessageNested.decode(readValue(buffer)!); + case 132: + final int? value = readValue(buffer) as int?; + return value == null ? null : MessageRequestState.values[value]; default: return super.readValueOfType(type, buffer); } @@ -184,7 +193,7 @@ class MessageApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = _MessageApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -246,39 +255,6 @@ class MessageApi { } } -class _MessageNestedApiCodec extends StandardMessageCodec { - const _MessageNestedApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageNested) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchReply) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageNested.decode(readValue(buffer)!); - case 129: - return MessageSearchReply.decode(readValue(buffer)!); - case 130: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// This comment is to test api documentation comments. class MessageNestedApi { /// Constructor for [MessageNestedApi]. The [binaryMessenger] named argument is @@ -291,8 +267,7 @@ class MessageNestedApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _MessageNestedApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -329,38 +304,9 @@ class MessageNestedApi { } } -class _MessageFlutterSearchApiCodec extends StandardMessageCodec { - const _MessageFlutterSearchApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageSearchReply.decode(readValue(buffer)!); - case 129: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// This comment is to test api documentation comments. abstract class MessageFlutterSearchApi { - static const MessageCodec pigeonChannelCodec = - _MessageFlutterSearchApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// This comment is to test method documentation comments. MessageSearchReply search(MessageSearchRequest request); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart index 61bd5d14094..33b984077af 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart @@ -30,6 +30,10 @@ List wrapResponse( return [error.code, error.message, error.details]; } +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); +} + class MultipleArityHostApi { /// Constructor for [MultipleArityHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -41,8 +45,7 @@ class MultipleArityHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -77,8 +80,7 @@ class MultipleArityHostApi { } abstract class MultipleArityFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); int subtract(int x, int y); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart index 8f3560363e0..c9c7fe5a638 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart @@ -107,7 +107,7 @@ class NonNullFieldSearchReply { error, indices, extraData, - type.index, + type, ]; } @@ -118,24 +118,27 @@ class NonNullFieldSearchReply { error: result[1]! as String, indices: (result[2] as List?)!.cast(), extraData: result[3]! as ExtraData, - type: ReplyType.values[result[4]! as int], + type: result[4]! as ReplyType, ); } } -class _NonNullFieldHostApiCodec extends StandardMessageCodec { - const _NonNullFieldHostApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is ExtraData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NonNullFieldSearchReply) { + if (value is NonNullFieldSearchRequest) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is NonNullFieldSearchRequest) { + } else if (value is ExtraData) { buffer.putUint8(130); writeValue(buffer, value.encode()); + } else if (value is NonNullFieldSearchReply) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is ReplyType) { + buffer.putUint8(132); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -144,12 +147,15 @@ class _NonNullFieldHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return ExtraData.decode(readValue(buffer)!); case 129: - return NonNullFieldSearchReply.decode(readValue(buffer)!); - case 130: return NonNullFieldSearchRequest.decode(readValue(buffer)!); + case 130: + return ExtraData.decode(readValue(buffer)!); + case 131: + return NonNullFieldSearchReply.decode(readValue(buffer)!); + case 132: + final int? value = readValue(buffer) as int?; + return value == null ? null : ReplyType.values[value]; default: return super.readValueOfType(type, buffer); } @@ -167,8 +173,7 @@ class NonNullFieldHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _NonNullFieldHostApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -203,42 +208,8 @@ class NonNullFieldHostApi { } } -class _NonNullFieldFlutterApiCodec extends StandardMessageCodec { - const _NonNullFieldFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is ExtraData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NonNullFieldSearchReply) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is NonNullFieldSearchRequest) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return ExtraData.decode(readValue(buffer)!); - case 129: - return NonNullFieldSearchReply.decode(readValue(buffer)!); - case 130: - return NonNullFieldSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - abstract class NonNullFieldFlutterApi { - static const MessageCodec pigeonChannelCodec = - _NonNullFieldFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); NonNullFieldSearchReply search(NonNullFieldSearchRequest request); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart index 3af44e61683..578a7c28c31 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart @@ -86,7 +86,7 @@ class NullFieldsSearchReply { error, indices, request, - type?.index, + type, ]; } @@ -97,23 +97,24 @@ class NullFieldsSearchReply { error: result[1] as String?, indices: (result[2] as List?)?.cast(), request: result[3] as NullFieldsSearchRequest?, - type: result[4] != null - ? NullFieldsSearchReplyType.values[result[4]! as int] - : null, + type: result[4] as NullFieldsSearchReplyType?, ); } } -class _NullFieldsHostApiCodec extends StandardMessageCodec { - const _NullFieldsHostApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is NullFieldsSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NullFieldsSearchRequest) { + if (value is NullFieldsSearchRequest) { buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is NullFieldsSearchReply) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is NullFieldsSearchReplyType) { + buffer.putUint8(131); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -122,10 +123,13 @@ class _NullFieldsHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return NullFieldsSearchReply.decode(readValue(buffer)!); case 129: return NullFieldsSearchRequest.decode(readValue(buffer)!); + case 130: + return NullFieldsSearchReply.decode(readValue(buffer)!); + case 131: + final int? value = readValue(buffer) as int?; + return value == null ? null : NullFieldsSearchReplyType.values[value]; default: return super.readValueOfType(type, buffer); } @@ -143,8 +147,7 @@ class NullFieldsHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _NullFieldsHostApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -178,37 +181,8 @@ class NullFieldsHostApi { } } -class _NullFieldsFlutterApiCodec extends StandardMessageCodec { - const _NullFieldsFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NullFieldsSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NullFieldsSearchRequest) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NullFieldsSearchReply.decode(readValue(buffer)!); - case 129: - return NullFieldsSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - abstract class NullFieldsFlutterApi { - static const MessageCodec pigeonChannelCodec = - _NullFieldsFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); NullFieldsSearchReply search(NullFieldsSearchRequest request); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart index 39348701f18..72ea0ae7363 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart @@ -30,6 +30,10 @@ List wrapResponse( return [error.code, error.message, error.details]; } +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); +} + class NullableReturnHostApi { /// Constructor for [NullableReturnHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -41,8 +45,7 @@ class NullableReturnHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -72,8 +75,7 @@ class NullableReturnHostApi { } abstract class NullableReturnFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); int? doit(); @@ -120,8 +122,7 @@ class NullableArgHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -156,8 +157,7 @@ class NullableArgHostApi { } abstract class NullableArgFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); int? doit(int? x); @@ -208,8 +208,7 @@ class NullableCollectionReturnHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -239,8 +238,7 @@ class NullableCollectionReturnHostApi { } abstract class NullableCollectionReturnFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); List? doit(); @@ -287,8 +285,7 @@ class NullableCollectionArgHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -323,8 +320,7 @@ class NullableCollectionArgHostApi { } abstract class NullableCollectionArgFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); List doit(List? x); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart index 846d67e6099..8ac914eb6fa 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart @@ -30,6 +30,10 @@ List wrapResponse( return [error.code, error.message, error.details]; } +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); +} + class PrimitiveHostApi { /// Constructor for [PrimitiveHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -41,8 +45,7 @@ class PrimitiveHostApi { messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; @@ -310,8 +313,7 @@ class PrimitiveHostApi { } abstract class PrimitiveFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); int anInt(int value); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 3e3e4b51bc1..97dbbc67559 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -379,7 +379,7 @@ class _PigeonInstanceManagerApi { } } -class _PigeonProxyApiBaseCodec extends StandardMessageCodec { +class _PigeonProxyApiBaseCodec extends _PigeonCodec { const _PigeonProxyApiBaseCodec(this.instanceManager); final PigeonInstanceManager instanceManager; @override @@ -410,6 +410,30 @@ enum ProxyApiTestEnum { three, } +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is ProxyApiTestEnum) { + buffer.putUint8(129); + writeValue(buffer, value.index); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 129: + final int? value = readValue(buffer) as int?; + return value == null ? null : ProxyApiTestEnum.values[value]; + default: + return super.readValueOfType(type, buffer); + } + } +} + /// The core ProxyApi test class that each supported host language must /// implement in platform_tests integration tests. class ProxyApiTestClass extends ProxyApiSuperClass @@ -504,7 +528,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass aUint8List, aList, aMap, - anEnum.index, + anEnum, aProxyApi, aNullableBool, aNullableInt, @@ -513,7 +537,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass aNullableUint8List, aNullableList, aNullableMap, - aNullableEnum?.index, + aNullableEnum, aNullableProxyApi, boolParam, intParam, @@ -522,7 +546,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass aUint8ListParam, listParam, mapParam, - enumParam.index, + enumParam, proxyApiParam, nullableBoolParam, nullableIntParam, @@ -531,7 +555,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass nullableUint8ListParam, nullableListParam, nullableMapParam, - nullableEnumParam?.index, + nullableEnumParam, nullableProxyApiParam ]) as List?; if (__pigeon_replyList == null) { @@ -1399,8 +1423,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[7] as Map?)?.cast(); assert(arg_aMap != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null Map.'); - final ProxyApiTestEnum? arg_anEnum = - args[8] == null ? null : ProxyApiTestEnum.values[args[8]! as int]; + final ProxyApiTestEnum? arg_anEnum = (args[8] as ProxyApiTestEnum?); assert(arg_anEnum != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance was null, expected non-null ProxyApiTestEnum.'); final ProxyApiSuperClass? arg_aProxyApi = @@ -1416,9 +1439,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[15] as List?)?.cast(); final Map? arg_aNullableMap = (args[16] as Map?)?.cast(); - final ProxyApiTestEnum? arg_aNullableEnum = args[17] == null - ? null - : ProxyApiTestEnum.values[args[17]! as int]; + final ProxyApiTestEnum? arg_aNullableEnum = + (args[17] as ProxyApiTestEnum?); final ProxyApiSuperClass? arg_aNullableProxyApi = (args[18] as ProxyApiSuperClass?); try { @@ -1911,15 +1933,14 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[0] as ProxyApiTestClass?); assert(arg_pigeon_instance != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null ProxyApiTestClass.'); - final ProxyApiTestEnum? arg_anEnum = - args[1] == null ? null : ProxyApiTestEnum.values[args[1]! as int]; + final ProxyApiTestEnum? arg_anEnum = (args[1] as ProxyApiTestEnum?); assert(arg_anEnum != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum was null, expected non-null ProxyApiTestEnum.'); try { final ProxyApiTestEnum? output = (flutterEchoEnum ?? arg_pigeon_instance!.flutterEchoEnum) ?.call(arg_pigeon_instance!, arg_anEnum!); - return wrapResponse(result: output?.index); + return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); } catch (e) { @@ -2216,13 +2237,12 @@ class ProxyApiTestClass extends ProxyApiSuperClass (args[0] as ProxyApiTestClass?); assert(arg_pigeon_instance != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum was null, expected non-null ProxyApiTestClass.'); - final ProxyApiTestEnum? arg_anEnum = - args[1] == null ? null : ProxyApiTestEnum.values[args[1]! as int]; + final ProxyApiTestEnum? arg_anEnum = (args[1] as ProxyApiTestEnum?); try { final ProxyApiTestEnum? output = (flutterEchoNullableEnum ?? arg_pigeon_instance!.flutterEchoNullableEnum) ?.call(arg_pigeon_instance!, arg_anEnum); - return wrapResponse(result: output?.index); + return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); } catch (e) { @@ -2869,8 +2889,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([this, anEnum.index]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2885,7 +2905,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?)!; } } @@ -3163,7 +3183,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = await __pigeon_channel - .send([this, aNullableEnum?.index]) as List?; + .send([this, aNullableEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -3173,9 +3193,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?); } } @@ -3515,8 +3533,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([this, anEnum.index]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -3531,7 +3549,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?)!; } } @@ -3859,8 +3877,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([this, anEnum?.index]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -3870,9 +3888,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?); } } @@ -4362,8 +4378,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([this, anEnum.index]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -4378,7 +4394,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass message: 'Host platform returned null value for non-null return value.', ); } else { - return ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?)!; } } @@ -4621,8 +4637,8 @@ class ProxyApiTestClass extends ProxyApiSuperClass pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([this, anEnum?.index]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([this, anEnum]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -4632,9 +4648,7 @@ class ProxyApiTestClass extends ProxyApiSuperClass details: __pigeon_replyList[2], ); } else { - return (__pigeon_replyList[0] as int?) == null - ? null - : ProxyApiTestEnum.values[__pigeon_replyList[0]! as int]; + return (__pigeon_replyList[0] as ProxyApiTestEnum?); } } diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/generated_dart_test_code_test.dart similarity index 95% rename from packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart rename to packages/pigeon/platform_tests/shared_test_plugin_code/test/generated_dart_test_code_test.dart index a0632cf3486..27e622c597e 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/generated_dart_test_code_test.dart @@ -44,7 +44,7 @@ void main() { test('simple', () async { final MessageNestedApi api = MessageNestedApi(); final MockNested mock = MockNested(); - TestNestedApi.setup(mock); + TestNestedApi.setUp(mock); final MessageSearchReply reply = await api.search(MessageNested()..request = null); expect(mock.didCall, true); @@ -54,7 +54,7 @@ void main() { test('nested', () async { final MessageApi api = MessageApi(); final Mock mock = Mock(); - TestHostApi.setup(mock); + TestHostApi.setUp(mock); final MessageSearchReply reply = await api.search(MessageSearchRequest()..query = 'foo'); expect(mock.log, ['search']); @@ -64,7 +64,7 @@ void main() { test('no-arg calls', () async { final MessageApi api = MessageApi(); final Mock mock = Mock(); - TestHostApi.setup(mock); + TestHostApi.setUp(mock); await api.initialize(); expect(mock.log, ['initialize']); }); @@ -73,7 +73,7 @@ void main() { 'calling methods with null', () async { final Mock mock = Mock(); - TestHostApi.setup(mock); + TestHostApi.setUp(mock); expect( await const BasicMessageChannel( 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize', diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart index aa0ecb02424..5192bebc3f1 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart @@ -134,7 +134,7 @@ void main() { 'error', [1, 2, 3], request, - NullFieldsSearchReplyType.success.index, + NullFieldsSearchReplyType.success, ]); }); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart index ff3a3d9c89a..27add325337 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart @@ -4,7 +4,7 @@ // // Autogenerated from Pigeon, 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: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers // ignore_for_file: avoid_relative_lib_imports import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -14,16 +14,22 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_test_plugin_code/src/generated/message.gen.dart'; -class _TestHostApiCodec extends StandardMessageCodec { - const _TestHostApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { + if (value is MessageSearchRequest) { buffer.putUint8(129); writeValue(buffer, value.encode()); + } else if (value is MessageSearchReply) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is MessageNested) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is MessageRequestState) { + buffer.putUint8(132); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -32,10 +38,15 @@ class _TestHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return MessageSearchReply.decode(readValue(buffer)!); case 129: return MessageSearchRequest.decode(readValue(buffer)!); + case 130: + return MessageSearchReply.decode(readValue(buffer)!); + case 131: + return MessageNested.decode(readValue(buffer)!); + case 132: + final int? value = readValue(buffer) as int?; + return value == null ? null : MessageRequestState.values[value]; default: return super.readValueOfType(type, buffer); } @@ -48,7 +59,7 @@ class _TestHostApiCodec extends StandardMessageCodec { abstract class TestHostApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestHostApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// This comment is to test documentation comments. /// @@ -58,36 +69,50 @@ abstract class TestHostApi { /// This comment is to test method documentation comments. MessageSearchReply search(MessageSearchRequest request); - static void setup(TestHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setUp( + TestHostApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize', - codec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, + .setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { - // ignore message - api.initialize(); - return []; + try { + api.initialize(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search', - codec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, + .setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search was null.'); @@ -96,70 +121,51 @@ abstract class TestHostApi { (args[0] as MessageSearchRequest?); assert(arg_request != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search was null, expected non-null MessageSearchRequest.'); - final MessageSearchReply output = api.search(arg_request!); - return [output]; + try { + final MessageSearchReply output = api.search(arg_request!); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } } } -class _TestNestedApiCodec extends StandardMessageCodec { - const _TestNestedApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageNested) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchReply) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageNested.decode(readValue(buffer)!); - case 129: - return MessageSearchReply.decode(readValue(buffer)!); - case 130: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// This comment is to test api documentation comments. abstract class TestNestedApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestNestedApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// This comment is to test method documentation comments. /// /// This comment also tests multiple line comments. MessageSearchReply search(MessageNested nested); - static void setup(TestNestedApi? api, {BinaryMessenger? binaryMessenger}) { + static void setUp( + TestNestedApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search', - codec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, + .setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search was null.'); @@ -167,8 +173,15 @@ abstract class TestNestedApi { final MessageNested? arg_nested = (args[0] as MessageNested?); assert(arg_nested != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search was null, expected non-null MessageNested.'); - final MessageSearchReply output = api.search(arg_nested!); - return [output]; + try { + final MessageSearchReply output = api.search(arg_nested!); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } 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 3668ec94738..f90b5119611 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 @@ -64,11 +64,15 @@ data class AllTypes( val a4ByteArray: IntArray, val a8ByteArray: LongArray, val aFloatArray: DoubleArray, - val list: List, - val aMap: Map, val anEnum: AnEnum, val aString: String, - val anObject: Any + val anObject: Any, + val list: List, + val stringList: List, + val intList: List, + val doubleList: List, + val boolList: List, + val map: Map ) { companion object { @Suppress("LocalVariableName") @@ -81,11 +85,15 @@ data class AllTypes( val a4ByteArray = __pigeon_list[5] as IntArray val a8ByteArray = __pigeon_list[6] as LongArray val aFloatArray = __pigeon_list[7] as DoubleArray - val list = __pigeon_list[8] as List - val aMap = __pigeon_list[9] as Map - val anEnum = AnEnum.ofRaw(__pigeon_list[10] as Int)!! - val aString = __pigeon_list[11] as String - val anObject = __pigeon_list[12] as Any + val anEnum = __pigeon_list[8] as AnEnum + val aString = __pigeon_list[9] as String + val anObject = __pigeon_list[10] as Any + val list = __pigeon_list[11] as List + val stringList = __pigeon_list[12] as List + val intList = __pigeon_list[13] as List + val doubleList = __pigeon_list[14] as List + val boolList = __pigeon_list[15] as List + val map = __pigeon_list[16] as Map return AllTypes( aBool, anInt, @@ -95,16 +103,20 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - list, - aMap, anEnum, aString, - anObject) + anObject, + list, + stringList, + intList, + doubleList, + boolList, + map) } } fun toList(): List { - return listOf( + return listOf( aBool, anInt, anInt64, @@ -113,11 +125,15 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - list, - aMap, - anEnum.raw, + anEnum, aString, anObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ) } } @@ -136,15 +152,20 @@ data class AllNullableTypes( val aNullable4ByteArray: IntArray? = null, val aNullable8ByteArray: LongArray? = null, val aNullableFloatArray: DoubleArray? = null, - val aNullableList: List? = null, - val aNullableMap: Map? = null, val nullableNestedList: List?>? = null, val nullableMapWithAnnotations: Map? = null, val nullableMapWithObject: Map? = null, val aNullableEnum: AnEnum? = null, val aNullableString: String? = null, val aNullableObject: Any? = null, - val allNullableTypes: AllNullableTypes? = null + val allNullableTypes: AllNullableTypes? = null, + val list: List? = null, + val stringList: List? = null, + val intList: List? = null, + val doubleList: List? = null, + val boolList: List? = null, + val nestedClassList: List? = null, + val map: Map? = null ) { companion object { @Suppress("LocalVariableName") @@ -159,15 +180,20 @@ data class AllNullableTypes( val aNullable4ByteArray = __pigeon_list[5] as IntArray? val aNullable8ByteArray = __pigeon_list[6] as LongArray? val aNullableFloatArray = __pigeon_list[7] as DoubleArray? - val aNullableList = __pigeon_list[8] as List? - val aNullableMap = __pigeon_list[9] as Map? - val nullableNestedList = __pigeon_list[10] as List?>? - val nullableMapWithAnnotations = __pigeon_list[11] as Map? - val nullableMapWithObject = __pigeon_list[12] as Map? - val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } - val aNullableString = __pigeon_list[14] as String? - val aNullableObject = __pigeon_list[15] - val allNullableTypes = __pigeon_list[16] as AllNullableTypes? + val nullableNestedList = __pigeon_list[8] as List?>? + val nullableMapWithAnnotations = __pigeon_list[9] as Map? + val nullableMapWithObject = __pigeon_list[10] as Map? + val aNullableEnum = __pigeon_list[11] as AnEnum? + val aNullableString = __pigeon_list[12] as String? + val aNullableObject = __pigeon_list[13] + val allNullableTypes = __pigeon_list[14] as AllNullableTypes? + val list = __pigeon_list[15] as List? + val stringList = __pigeon_list[16] as List? + val intList = __pigeon_list[17] as List? + val doubleList = __pigeon_list[18] as List? + val boolList = __pigeon_list[19] as List? + val nestedClassList = __pigeon_list[20] as List? + val map = __pigeon_list[21] as Map? return AllNullableTypes( aNullableBool, aNullableInt, @@ -177,20 +203,25 @@ data class AllNullableTypes( aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString, aNullableObject, - allNullableTypes) + allNullableTypes, + list, + stringList, + intList, + doubleList, + boolList, + nestedClassList, + map) } } fun toList(): List { - return listOf( + return listOf( aNullableBool, aNullableInt, aNullableInt64, @@ -199,15 +230,20 @@ data class AllNullableTypes( aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.raw, + aNullableEnum, aNullableString, aNullableObject, allNullableTypes, + list, + stringList, + intList, + doubleList, + boolList, + nestedClassList, + map, ) } } @@ -227,14 +263,18 @@ data class AllNullableTypesWithoutRecursion( val aNullable4ByteArray: IntArray? = null, val aNullable8ByteArray: LongArray? = null, val aNullableFloatArray: DoubleArray? = null, - val aNullableList: List? = null, - val aNullableMap: Map? = null, val nullableNestedList: List?>? = null, val nullableMapWithAnnotations: Map? = null, val nullableMapWithObject: Map? = null, val aNullableEnum: AnEnum? = null, val aNullableString: String? = null, - val aNullableObject: Any? = null + val aNullableObject: Any? = null, + val list: List? = null, + val stringList: List? = null, + val intList: List? = null, + val doubleList: List? = null, + val boolList: List? = null, + val map: Map? = null ) { companion object { @Suppress("LocalVariableName") @@ -249,14 +289,18 @@ data class AllNullableTypesWithoutRecursion( val aNullable4ByteArray = __pigeon_list[5] as IntArray? val aNullable8ByteArray = __pigeon_list[6] as LongArray? val aNullableFloatArray = __pigeon_list[7] as DoubleArray? - val aNullableList = __pigeon_list[8] as List? - val aNullableMap = __pigeon_list[9] as Map? - val nullableNestedList = __pigeon_list[10] as List?>? - val nullableMapWithAnnotations = __pigeon_list[11] as Map? - val nullableMapWithObject = __pigeon_list[12] as Map? - val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } - val aNullableString = __pigeon_list[14] as String? - val aNullableObject = __pigeon_list[15] + val nullableNestedList = __pigeon_list[8] as List?>? + val nullableMapWithAnnotations = __pigeon_list[9] as Map? + val nullableMapWithObject = __pigeon_list[10] as Map? + val aNullableEnum = __pigeon_list[11] as AnEnum? + val aNullableString = __pigeon_list[12] as String? + val aNullableObject = __pigeon_list[13] + val list = __pigeon_list[14] as List? + val stringList = __pigeon_list[15] as List? + val intList = __pigeon_list[16] as List? + val doubleList = __pigeon_list[17] as List? + val boolList = __pigeon_list[18] as List? + val map = __pigeon_list[19] as Map? return AllNullableTypesWithoutRecursion( aNullableBool, aNullableInt, @@ -266,19 +310,23 @@ data class AllNullableTypesWithoutRecursion( aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString, - aNullableObject) + aNullableObject, + list, + stringList, + intList, + doubleList, + boolList, + map) } } fun toList(): List { - return listOf( + return listOf( aNullableBool, aNullableInt, aNullableInt64, @@ -287,14 +335,18 @@ data class AllNullableTypesWithoutRecursion( aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.raw, + aNullableEnum, aNullableString, aNullableObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ) } } @@ -324,7 +376,7 @@ data class AllClassesWrapper( } fun toList(): List { - return listOf( + return listOf( allNullableTypes, allNullableTypesWithoutRecursion, allTypes, @@ -348,58 +400,65 @@ data class TestMessage(val testList: List? = null) { } fun toList(): List { - return listOf( + return listOf( testList, ) } } -private object HostIntegrationCoreApiCodec : StandardMessageCodec() { +private object CoreTestsPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { AllClassesWrapper.fromList(it) } - } 129.toByte() -> { - return (readValue(buffer) as? List)?.let { AllNullableTypes.fromList(it) } + return (readValue(buffer) as? List)?.let { AllTypes.fromList(it) } } 130.toByte() -> { + return (readValue(buffer) as? List)?.let { AllNullableTypes.fromList(it) } + } + 131.toByte() -> { return (readValue(buffer) as? List)?.let { AllNullableTypesWithoutRecursion.fromList(it) } } - 131.toByte() -> { - return (readValue(buffer) as? List)?.let { AllTypes.fromList(it) } - } 132.toByte() -> { + return (readValue(buffer) as? List)?.let { AllClassesWrapper.fromList(it) } + } + 133.toByte() -> { return (readValue(buffer) as? List)?.let { TestMessage.fromList(it) } } + 134.toByte() -> { + return (readValue(buffer) as Int?)?.let { AnEnum.ofRaw(it) } + } else -> super.readValueOfType(type, buffer) } } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { - is AllClassesWrapper -> { - stream.write(128) + is AllTypes -> { + stream.write(129) writeValue(stream, value.toList()) } is AllNullableTypes -> { - stream.write(129) + stream.write(130) writeValue(stream, value.toList()) } is AllNullableTypesWithoutRecursion -> { - stream.write(130) + stream.write(131) writeValue(stream, value.toList()) } - is AllTypes -> { - stream.write(131) + is AllClassesWrapper -> { + stream.write(132) writeValue(stream, value.toList()) } is TestMessage -> { - stream.write(132) + stream.write(133) writeValue(stream, value.toList()) } + is AnEnum -> { + stream.write(134) + writeValue(stream, value.raw) + } else -> super.writeValue(stream, value) } } @@ -630,11 +689,12 @@ interface HostIntegrationCoreApi { companion object { /** The codec used by HostIntegrationCoreApi. */ - val codec: MessageCodec by lazy { HostIntegrationCoreApiCodec } + val codec: MessageCodec by lazy { CoreTestsPigeonCodec } /** * Sets up an instance of `HostIntegrationCoreApi` to handle messages through the * `binaryMessenger`. */ + @JvmOverloads fun setUp( binaryMessenger: BinaryMessenger, api: HostIntegrationCoreApi?, @@ -653,7 +713,7 @@ interface HostIntegrationCoreApi { val wrapped: List = try { api.noop() - listOf(null) + listOf(null) } catch (exception: Throwable) { wrapError(exception) } @@ -675,7 +735,7 @@ interface HostIntegrationCoreApi { val everythingArg = args[0] as AllTypes val wrapped: List = try { - listOf(api.echoAllTypes(everythingArg)) + listOf(api.echoAllTypes(everythingArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -695,7 +755,7 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { _, reply -> val wrapped: List = try { - listOf(api.throwError()) + listOf(api.throwError()) } catch (exception: Throwable) { wrapError(exception) } @@ -716,7 +776,7 @@ interface HostIntegrationCoreApi { val wrapped: List = try { api.throwErrorFromVoid() - listOf(null) + listOf(null) } catch (exception: Throwable) { wrapError(exception) } @@ -736,7 +796,7 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { _, reply -> val wrapped: List = try { - listOf(api.throwFlutterError()) + listOf(api.throwFlutterError()) } catch (exception: Throwable) { wrapError(exception) } @@ -758,7 +818,7 @@ interface HostIntegrationCoreApi { val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } val wrapped: List = try { - listOf(api.echoInt(anIntArg)) + listOf(api.echoInt(anIntArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -780,7 +840,7 @@ interface HostIntegrationCoreApi { val aDoubleArg = args[0] as Double val wrapped: List = try { - listOf(api.echoDouble(aDoubleArg)) + listOf(api.echoDouble(aDoubleArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -802,7 +862,7 @@ interface HostIntegrationCoreApi { val aBoolArg = args[0] as Boolean val wrapped: List = try { - listOf(api.echoBool(aBoolArg)) + listOf(api.echoBool(aBoolArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -824,7 +884,7 @@ interface HostIntegrationCoreApi { val aStringArg = args[0] as String val wrapped: List = try { - listOf(api.echoString(aStringArg)) + listOf(api.echoString(aStringArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -846,7 +906,7 @@ interface HostIntegrationCoreApi { val aUint8ListArg = args[0] as ByteArray val wrapped: List = try { - listOf(api.echoUint8List(aUint8ListArg)) + listOf(api.echoUint8List(aUint8ListArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -868,7 +928,7 @@ interface HostIntegrationCoreApi { val anObjectArg = args[0] as Any val wrapped: List = try { - listOf(api.echoObject(anObjectArg)) + listOf(api.echoObject(anObjectArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -890,7 +950,7 @@ interface HostIntegrationCoreApi { val listArg = args[0] as List val wrapped: List = try { - listOf(api.echoList(listArg)) + listOf(api.echoList(listArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -912,7 +972,7 @@ interface HostIntegrationCoreApi { val aMapArg = args[0] as Map val wrapped: List = try { - listOf(api.echoMap(aMapArg)) + listOf(api.echoMap(aMapArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -934,7 +994,7 @@ interface HostIntegrationCoreApi { val wrapperArg = args[0] as AllClassesWrapper val wrapped: List = try { - listOf(api.echoClassWrapper(wrapperArg)) + listOf(api.echoClassWrapper(wrapperArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -953,10 +1013,10 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = AnEnum.ofRaw(args[0] as Int)!! + val anEnumArg = args[0] as AnEnum val wrapped: List = try { - listOf(api.echoEnum(anEnumArg).raw) + listOf(api.echoEnum(anEnumArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -978,7 +1038,7 @@ interface HostIntegrationCoreApi { val aStringArg = args[0] as String val wrapped: List = try { - listOf(api.echoNamedDefaultString(aStringArg)) + listOf(api.echoNamedDefaultString(aStringArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1000,7 +1060,7 @@ interface HostIntegrationCoreApi { val aDoubleArg = args[0] as Double val wrapped: List = try { - listOf(api.echoOptionalDefaultDouble(aDoubleArg)) + listOf(api.echoOptionalDefaultDouble(aDoubleArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1022,7 +1082,7 @@ interface HostIntegrationCoreApi { val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } val wrapped: List = try { - listOf(api.echoRequiredInt(anIntArg)) + listOf(api.echoRequiredInt(anIntArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1044,7 +1104,7 @@ interface HostIntegrationCoreApi { val everythingArg = args[0] as AllNullableTypes? val wrapped: List = try { - listOf(api.echoAllNullableTypes(everythingArg)) + listOf(api.echoAllNullableTypes(everythingArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1066,7 +1126,7 @@ interface HostIntegrationCoreApi { val everythingArg = args[0] as AllNullableTypesWithoutRecursion? val wrapped: List = try { - listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) + listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1088,7 +1148,7 @@ interface HostIntegrationCoreApi { val wrapperArg = args[0] as AllClassesWrapper val wrapped: List = try { - listOf(api.extractNestedNullableString(wrapperArg)) + listOf(api.extractNestedNullableString(wrapperArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1110,7 +1170,7 @@ interface HostIntegrationCoreApi { val nullableStringArg = args[0] as String? val wrapped: List = try { - listOf(api.createNestedNullableString(nullableStringArg)) + listOf(api.createNestedNullableString(nullableStringArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1135,7 +1195,7 @@ interface HostIntegrationCoreApi { val aNullableStringArg = args[2] as String? val wrapped: List = try { - listOf( + listOf( api.sendMultipleNullableTypes( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) } catch (exception: Throwable) { @@ -1162,7 +1222,7 @@ interface HostIntegrationCoreApi { val aNullableStringArg = args[2] as String? val wrapped: List = try { - listOf( + listOf( api.sendMultipleNullableTypesWithoutRecursion( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) } catch (exception: Throwable) { @@ -1187,7 +1247,7 @@ interface HostIntegrationCoreApi { args[0].let { num -> if (num is Int) num.toLong() else num as Long? } val wrapped: List = try { - listOf(api.echoNullableInt(aNullableIntArg)) + listOf(api.echoNullableInt(aNullableIntArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1209,7 +1269,7 @@ interface HostIntegrationCoreApi { val aNullableDoubleArg = args[0] as Double? val wrapped: List = try { - listOf(api.echoNullableDouble(aNullableDoubleArg)) + listOf(api.echoNullableDouble(aNullableDoubleArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1231,7 +1291,7 @@ interface HostIntegrationCoreApi { val aNullableBoolArg = args[0] as Boolean? val wrapped: List = try { - listOf(api.echoNullableBool(aNullableBoolArg)) + listOf(api.echoNullableBool(aNullableBoolArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1253,7 +1313,7 @@ interface HostIntegrationCoreApi { val aNullableStringArg = args[0] as String? val wrapped: List = try { - listOf(api.echoNullableString(aNullableStringArg)) + listOf(api.echoNullableString(aNullableStringArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1275,7 +1335,7 @@ interface HostIntegrationCoreApi { val aNullableUint8ListArg = args[0] as ByteArray? val wrapped: List = try { - listOf(api.echoNullableUint8List(aNullableUint8ListArg)) + listOf(api.echoNullableUint8List(aNullableUint8ListArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1297,7 +1357,7 @@ interface HostIntegrationCoreApi { val aNullableObjectArg = args[0] val wrapped: List = try { - listOf(api.echoNullableObject(aNullableObjectArg)) + listOf(api.echoNullableObject(aNullableObjectArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1319,7 +1379,7 @@ interface HostIntegrationCoreApi { val aNullableListArg = args[0] as List? val wrapped: List = try { - listOf(api.echoNullableList(aNullableListArg)) + listOf(api.echoNullableList(aNullableListArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1341,7 +1401,7 @@ interface HostIntegrationCoreApi { val aNullableMapArg = args[0] as Map? val wrapped: List = try { - listOf(api.echoNullableMap(aNullableMapArg)) + listOf(api.echoNullableMap(aNullableMapArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1360,10 +1420,10 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = if (args[0] == null) null else AnEnum.ofRaw(args[0] as Int) + val anEnumArg = args[0] as AnEnum? val wrapped: List = try { - listOf(api.echoNullableEnum(anEnumArg)?.raw) + listOf(api.echoNullableEnum(anEnumArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1386,7 +1446,7 @@ interface HostIntegrationCoreApi { args[0].let { num -> if (num is Int) num.toLong() else num as Long? } val wrapped: List = try { - listOf(api.echoOptionalNullableInt(aNullableIntArg)) + listOf(api.echoOptionalNullableInt(aNullableIntArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1408,7 +1468,7 @@ interface HostIntegrationCoreApi { val aNullableStringArg = args[0] as String? val wrapped: List = try { - listOf(api.echoNamedNullableString(aNullableStringArg)) + listOf(api.echoNamedNullableString(aNullableStringArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -1426,7 +1486,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.noopAsync() { result: Result -> + api.noopAsync { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1640,14 +1700,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = AnEnum.ofRaw(args[0] as Int)!! + val anEnumArg = args[0] as AnEnum api.echoAsyncEnum(anEnumArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) } else { val data = result.getOrNull() - reply.reply(wrapResult(data!!.raw)) + reply.reply(wrapResult(data)) } } } @@ -1663,7 +1723,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.throwAsyncError() { result: Result -> + api.throwAsyncError { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1685,7 +1745,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.throwAsyncErrorFromVoid() { result: Result -> + api.throwAsyncErrorFromVoid { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1706,7 +1766,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.throwAsyncFlutterError() { result: Result -> + api.throwAsyncFlutterError { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1995,14 +2055,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = if (args[0] == null) null else AnEnum.ofRaw(args[0] as Int) + val anEnumArg = args[0] as AnEnum? api.echoAsyncNullableEnum(anEnumArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) } else { val data = result.getOrNull() - reply.reply(wrapResult(data?.raw)) + reply.reply(wrapResult(data)) } } } @@ -2018,7 +2078,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.callFlutterNoop() { result: Result -> + api.callFlutterNoop { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2039,7 +2099,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.callFlutterThrowError() { result: Result -> + api.callFlutterThrowError { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2061,7 +2121,7 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.callFlutterThrowErrorFromVoid() { result: Result -> + api.callFlutterThrowErrorFromVoid { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2383,14 +2443,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = AnEnum.ofRaw(args[0] as Int)!! + val anEnumArg = args[0] as AnEnum api.callFlutterEchoEnum(anEnumArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) } else { val data = result.getOrNull() - reply.reply(wrapResult(data!!.raw)) + reply.reply(wrapResult(data)) } } } @@ -2575,14 +2635,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anEnumArg = if (args[0] == null) null else AnEnum.ofRaw(args[0] as Int) + val anEnumArg = args[0] as AnEnum? api.callFlutterEchoNullableEnum(anEnumArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) } else { val data = result.getOrNull() - reply.reply(wrapResult(data?.raw)) + reply.reply(wrapResult(data)) } } } @@ -2617,58 +2677,6 @@ interface HostIntegrationCoreApi { } } } - -private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { AllClassesWrapper.fromList(it) } - } - 129.toByte() -> { - return (readValue(buffer) as? List)?.let { AllNullableTypes.fromList(it) } - } - 130.toByte() -> { - return (readValue(buffer) as? List)?.let { - AllNullableTypesWithoutRecursion.fromList(it) - } - } - 131.toByte() -> { - return (readValue(buffer) as? List)?.let { AllTypes.fromList(it) } - } - 132.toByte() -> { - return (readValue(buffer) as? List)?.let { TestMessage.fromList(it) } - } - else -> super.readValueOfType(type, buffer) - } - } - - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is AllClassesWrapper -> { - stream.write(128) - writeValue(stream, value.toList()) - } - is AllNullableTypes -> { - stream.write(129) - writeValue(stream, value.toList()) - } - is AllNullableTypesWithoutRecursion -> { - stream.write(130) - writeValue(stream, value.toList()) - } - is AllTypes -> { - stream.write(131) - writeValue(stream, value.toList()) - } - is TestMessage -> { - stream.write(132) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) - } - } -} - /** * The core interface that the Dart platform_test code implements for host integration tests to call * into. @@ -2681,7 +2689,7 @@ class FlutterIntegrationCoreApi( ) { companion object { /** The codec used by FlutterIntegrationCoreApi. */ - val codec: MessageCodec by lazy { FlutterIntegrationCoreApiCodec } + val codec: MessageCodec by lazy { CoreTestsPigeonCodec } } /** A no-op function taking no arguments and returning no value, to sanity test basic calling. */ fun noop(callback: (Result) -> Unit) { @@ -3082,7 +3090,7 @@ class FlutterIntegrationCoreApi( val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(anEnumArg.raw)) { + channel.send(listOf(anEnumArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3094,7 +3102,7 @@ class FlutterIntegrationCoreApi( "Flutter api returned null value for non-null return value.", ""))) } else { - val output = AnEnum.ofRaw(it[0] as Int)!! + val output = it[0] as AnEnum callback(Result.success(output)) } } else { @@ -3252,12 +3260,12 @@ class FlutterIntegrationCoreApi( val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(anEnumArg?.raw)) { + channel.send(listOf(anEnumArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { - val output = (it[0] as Int?)?.let { num -> AnEnum.ofRaw(num) } + val output = it[0] as AnEnum? callback(Result.success(output)) } } else { @@ -3325,8 +3333,9 @@ interface HostTrivialApi { companion object { /** The codec used by HostTrivialApi. */ - val codec: MessageCodec by lazy { StandardMessageCodec() } + val codec: MessageCodec by lazy { CoreTestsPigeonCodec } /** Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. */ + @JvmOverloads fun setUp( binaryMessenger: BinaryMessenger, api: HostTrivialApi?, @@ -3345,7 +3354,7 @@ interface HostTrivialApi { val wrapped: List = try { api.noop() - listOf(null) + listOf(null) } catch (exception: Throwable) { wrapError(exception) } @@ -3370,8 +3379,9 @@ interface HostSmallApi { companion object { /** The codec used by HostSmallApi. */ - val codec: MessageCodec by lazy { StandardMessageCodec() } + val codec: MessageCodec by lazy { CoreTestsPigeonCodec } /** Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. */ + @JvmOverloads fun setUp( binaryMessenger: BinaryMessenger, api: HostSmallApi?, @@ -3411,7 +3421,7 @@ interface HostSmallApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.voidVoid() { result: Result -> + api.voidVoid { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -3427,28 +3437,6 @@ interface HostSmallApi { } } } - -private object FlutterSmallApiCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { TestMessage.fromList(it) } - } - else -> super.readValueOfType(type, buffer) - } - } - - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is TestMessage -> { - stream.write(128) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) - } - } -} - /** * A simple API called in some unit tests. * @@ -3460,7 +3448,7 @@ class FlutterSmallApi( ) { companion object { /** The codec used by FlutterSmallApi. */ - val codec: MessageCodec by lazy { FlutterSmallApiCodec } + val codec: MessageCodec by lazy { CoreTestsPigeonCodec } } fun echoWrappedList(msgArg: TestMessage, callback: (Result) -> Unit) { diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index 97236e316bb..43ed1282d12 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -13,18 +13,18 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { private var flutterSmallApiOne: FlutterSmallApi? = null private var flutterSmallApiTwo: FlutterSmallApi? = null - override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { + override fun onAttachedToEngine(binding: FlutterPluginBinding) { HostIntegrationCoreApi.setUp(binding.binaryMessenger, this) - val testSuffixApiOne: TestPluginWithSuffix = TestPluginWithSuffix() + val testSuffixApiOne = TestPluginWithSuffix() testSuffixApiOne.setUp(binding, "suffixOne") - val testSuffixApiTwo: TestPluginWithSuffix = TestPluginWithSuffix() + val testSuffixApiTwo = TestPluginWithSuffix() testSuffixApiTwo.setUp(binding, "suffixTwo") flutterApi = FlutterIntegrationCoreApi(binding.binaryMessenger) flutterSmallApiOne = FlutterSmallApi(binding.binaryMessenger, "suffixOne") flutterSmallApiTwo = FlutterSmallApi(binding.binaryMessenger, "suffixTwo") } - override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {} + override fun onDetachedFromEngine(binding: FlutterPluginBinding) {} // HostIntegrationCoreApi @@ -298,15 +298,15 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun callFlutterNoop(callback: (Result) -> Unit) { - flutterApi!!.noop() { callback(Result.success(Unit)) } + flutterApi!!.noop { callback(Result.success(Unit)) } } override fun callFlutterThrowError(callback: (Result) -> Unit) { - flutterApi!!.throwError() { result -> callback(result) } + flutterApi!!.throwError { result -> callback(result) } } override fun callFlutterThrowErrorFromVoid(callback: (Result) -> Unit) { - flutterApi!!.throwErrorFromVoid() { result -> callback(result) } + flutterApi!!.throwErrorFromVoid { result -> callback(result) } } override fun callFlutterEchoAllTypes(everything: AllTypes, callback: (Result) -> Unit) { @@ -375,6 +375,7 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun callFlutterEchoEnum(anEnum: AnEnum, callback: (Result) -> Unit) { + // callback(Result.success(anEnum)) flutterApi!!.echoEnum(anEnum) { echo -> callback(echo) } } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index 2560efb65b2..56e0111d63f 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -9,10 +9,14 @@ import io.mockk.every import io.mockk.mockk import java.nio.ByteBuffer import java.util.ArrayList -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Test -internal class AllDatatypesTest : TestCase() { +internal class AllDatatypesTest { + fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?) { assertEquals(firstTypes == null, secondTypes == null) if (firstTypes == null || secondTypes == null) { @@ -21,19 +25,26 @@ internal class AllDatatypesTest : TestCase() { assertEquals(firstTypes.aBool, secondTypes.aBool) assertEquals(firstTypes.anInt, secondTypes.anInt) assertEquals(firstTypes.anInt64, secondTypes.anInt64) - assertEquals(firstTypes.aDouble, secondTypes.aDouble) + assertEquals(firstTypes.aDouble, secondTypes.aDouble, 0.0) assertEquals(firstTypes.aString, secondTypes.aString) assertTrue(firstTypes.aByteArray.contentEquals(secondTypes.aByteArray)) assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray)) assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray)) assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray)) - assertEquals(firstTypes.list, secondTypes.list) - assertEquals(firstTypes.aMap, secondTypes.aMap) assertEquals(firstTypes.anEnum, secondTypes.anEnum) assertEquals(firstTypes.anObject, secondTypes.anObject) + assertEquals(firstTypes.list, secondTypes.list) + assertEquals(firstTypes.boolList, secondTypes.boolList) + assertEquals(firstTypes.doubleList, secondTypes.doubleList) + assertEquals(firstTypes.intList, secondTypes.intList) + assertEquals(firstTypes.stringList, secondTypes.stringList) + assertEquals(firstTypes.map, secondTypes.map) } - fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?) { + private fun compareAllNullableTypes( + firstTypes: AllNullableTypes?, + secondTypes: AllNullableTypes? + ) { assertEquals(firstTypes == null, secondTypes == null) if (firstTypes == null || secondTypes == null) { return @@ -46,10 +57,14 @@ internal class AllDatatypesTest : TestCase() { assertTrue(firstTypes.aNullable4ByteArray.contentEquals(secondTypes.aNullable4ByteArray)) assertTrue(firstTypes.aNullable8ByteArray.contentEquals(secondTypes.aNullable8ByteArray)) assertTrue(firstTypes.aNullableFloatArray.contentEquals(secondTypes.aNullableFloatArray)) - assertEquals(firstTypes.aNullableList, secondTypes.aNullableList) - assertEquals(firstTypes.aNullableMap, secondTypes.aNullableMap) assertEquals(firstTypes.nullableMapWithObject, secondTypes.nullableMapWithObject) assertEquals(firstTypes.aNullableObject, secondTypes.aNullableObject) + assertEquals(firstTypes.list, secondTypes.list) + assertEquals(firstTypes.boolList, secondTypes.boolList) + assertEquals(firstTypes.doubleList, secondTypes.doubleList) + assertEquals(firstTypes.intList, secondTypes.intList) + assertEquals(firstTypes.stringList, secondTypes.stringList) + assertEquals(firstTypes.map, secondTypes.map) } @Test @@ -71,22 +86,9 @@ internal class AllDatatypesTest : TestCase() { } var didCall = false - api.echoAllNullableTypes(everything) { + api.echoAllNullableTypes(everything) { result -> didCall = true - val output = - (it.getOrNull())?.let { - assertNull(it.aNullableBool) - assertNull(it.aNullableInt) - assertNull(it.aNullableDouble) - assertNull(it.aNullableString) - assertNull(it.aNullableByteArray) - assertNull(it.aNullable4ByteArray) - assertNull(it.aNullable8ByteArray) - assertNull(it.aNullableFloatArray) - assertNull(it.aNullableList) - assertNull(it.aNullableMap) - assertNull(it.nullableMapWithObject) - } + val output = (result.getOrNull())?.let { compareAllNullableTypes(it, everything) } assertNotNull(output) } @@ -105,11 +107,14 @@ internal class AllDatatypesTest : TestCase() { aNullable4ByteArray = intArrayOf(1, 2, 3, 4), aNullable8ByteArray = longArrayOf(1, 2, 3, 4), aNullableFloatArray = doubleArrayOf(0.5, 0.25, 1.5, 1.25), - aNullableList = listOf(1, 2, 3), - aNullableMap = mapOf("hello" to 1234), nullableMapWithObject = mapOf("hello" to 1234), aNullableObject = 0, - ) + list = listOf(1, 2, 3), + stringList = listOf("string", "another one"), + boolList = listOf(true, false), + intList = listOf(1, 2), + doubleList = listOf(1.1, 2.2), + map = mapOf("hello" to 1234)) val binaryMessenger = mockk() val api = FlutterIntegrationCoreApi(binaryMessenger) @@ -161,6 +166,11 @@ internal class AllDatatypesTest : TestCase() { null, null, null, + null, + null, + null, + null, + null, null) val everything2 = AllNullableTypes.fromList(list2) diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt index d42c62fefcb..8de43ad15fb 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AsyncHandlersTest.kt @@ -10,10 +10,14 @@ import io.mockk.mockk import io.mockk.slot import io.mockk.verify import java.nio.ByteBuffer -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Test -internal class AsyncHandlersTest : TestCase() { +internal class AsyncHandlersTest { + @Test fun testAsyncHost2Flutter() { val binaryMessenger = mockk() @@ -56,7 +60,6 @@ internal class AsyncHandlersTest : TestCase() { val handlerSlot = slot() val input = "Test" - val output = input val channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo" every { @@ -67,7 +70,7 @@ internal class AsyncHandlersTest : TestCase() { every { api.echo(any(), any()) } answers { val callback = arg<(Result) -> Unit>(1) - callback(Result.success(output)) + callback(Result.success(input)) } HostSmallApi.setUp(binaryMessenger, api) @@ -80,7 +83,7 @@ internal class AsyncHandlersTest : TestCase() { it?.rewind() @Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as MutableList? assertNotNull(wrapped) - wrapped?.let { assertEquals(output, wrapped.first()) } + wrapped?.let { assertEquals(input, wrapped.first()) } } verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) } @@ -88,7 +91,7 @@ internal class AsyncHandlersTest : TestCase() { } @Test - fun asyncFlutter2HostVoidVoid() { + fun testAsyncFlutter2HostVoidVoid() { val binaryMessenger = mockk() val api = mockk() diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt index 1117a8a3a1e..acdc6192c01 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/EnumTest.kt @@ -11,10 +11,13 @@ import io.mockk.slot import io.mockk.verify import java.nio.ByteBuffer import java.util.ArrayList -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue import org.junit.Test -internal class EnumTest : TestCase() { +internal class EnumTest { + @Test fun testEchoHost() { val binaryMessenger = mockk() diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/ListTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/ListTest.kt index 923cc3b90e6..cab26d56a52 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/ListTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/ListTest.kt @@ -9,10 +9,12 @@ import io.mockk.every import io.mockk.mockk import java.nio.ByteBuffer import java.util.ArrayList -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Test -class ListTest : TestCase() { +class ListTest { + @Test fun testListInList() { val binaryMessenger = mockk() diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt index 27925a308ae..789c944eb48 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/MultipleArityTests.kt @@ -10,10 +10,13 @@ import io.mockk.mockk import io.mockk.slot import java.nio.ByteBuffer import java.util.ArrayList -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue import org.junit.Test -class MultipleArityTests : TestCase() { +class MultipleArityTests { + @Test fun testSimpleHost() { val binaryMessenger = mockk() diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NonNullFieldsTests.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NonNullFieldsTests.kt index c5357af1b72..6e867760a08 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NonNullFieldsTests.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NonNullFieldsTests.kt @@ -4,10 +4,11 @@ package com.example.test_plugin -import junit.framework.TestCase +import org.junit.Assert.assertEquals import org.junit.Test -class NonNullFieldsTests : TestCase() { +class NonNullFieldsTests { + @Test fun testMake() { val request = NonNullFieldSearchRequest("hello") diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt index a1f6b52558b..78c85ba91d8 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/NullableReturnsTest.kt @@ -9,10 +9,13 @@ import io.mockk.every import io.mockk.mockk import io.mockk.slot import io.mockk.verify -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue import org.junit.Test -class NullableReturnsTest : TestCase() { +class NullableReturnsTest { + @Test fun testNullableParameterHost() { val binaryMessenger = mockk(relaxed = true) diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt index a883b6b0325..047c5b3c219 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/PrimitiveTest.kt @@ -9,10 +9,13 @@ import io.mockk.every import io.mockk.mockk import io.mockk.slot import io.mockk.verify -import junit.framework.TestCase +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue import org.junit.Test -class PrimitiveTest : TestCase() { +class PrimitiveTest { + @Test fun testIntPrimitiveHost() { val binaryMessenger = mockk(relaxed = true) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 7e1380f00a5..58761a450d7 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ (codec: FlutterIntegrationCoreApiCodec.shared) + let binaryMessenger = MockBinaryMessenger(codec: CoreTestsPigeonCodec.shared) binaryMessenger.result = value let flutterApi = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift index 391ace5d914..60683ff236f 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift @@ -21,7 +21,7 @@ extension DataWithEnum: Equatable { class EnumTests: XCTestCase { func testEchoHost() throws { - let binaryMessenger = MockBinaryMessenger(codec: EnumApi2HostCodec.shared) + let binaryMessenger = MockBinaryMessenger(codec: EnumPigeonCodec.shared) EnumApi2HostSetup.setUp(binaryMessenger: binaryMessenger, api: MockEnumApi2Host()) let channelName = "dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo" XCTAssertNotNil(binaryMessenger.handlers[channelName]) @@ -44,7 +44,7 @@ class EnumTests: XCTestCase { func testEchoFlutter() throws { let data = DataWithEnum(state: .error) - let binaryMessenger = EchoBinaryMessenger(codec: EnumApi2HostCodec.shared) + let binaryMessenger = EchoBinaryMessenger(codec: EnumPigeonCodec.shared) let api = EnumApi2Flutter(binaryMessenger: binaryMessenger) let expectation = XCTestExpectation(description: "callback") diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/ListTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/ListTests.swift index 4fc7de6b96e..fa56f7231ff 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/ListTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/ListTests.swift @@ -11,7 +11,7 @@ class ListTests: XCTestCase { func testListInList() throws { let inside = TestMessage(testList: [1, 2, 3]) let top = TestMessage(testList: [inside]) - let binaryMessenger = EchoBinaryMessenger(codec: FlutterSmallApiCodec.shared) + let binaryMessenger = EchoBinaryMessenger(codec: CoreTestsPigeonCodec.shared) let api = FlutterSmallApi(binaryMessenger: binaryMessenger) let expectation = XCTestExpectation(description: "callback") diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift index f42933b2391..6994a6703bf 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/MultipleArityTests.swift @@ -16,7 +16,7 @@ class MockMultipleArityHostApi: MultipleArityHostApi { class MultipleArityTests: XCTestCase { var codec = FlutterStandardMessageCodec.sharedInstance() func testSimpleHost() throws { - let binaryMessenger = MockBinaryMessenger(codec: EnumApi2HostCodec.shared) + let binaryMessenger = MockBinaryMessenger(codec: EnumPigeonCodec.shared) MultipleArityHostApiSetup.setUp( binaryMessenger: binaryMessenger, api: MockMultipleArityHostApi()) let channelName = "dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract" 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 c54100d2db4..2b95f040b48 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 @@ -94,11 +94,15 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var list: [Any?] - var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any + var list: [Any?] + var stringList: [String?] + var intList: [Int64?] + var doubleList: [Double?] + var boolList: [Bool?] + var map: [AnyHashable: Any?] // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { @@ -112,11 +116,15 @@ struct AllTypes { let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData - let list = __pigeon_list[8] as! [Any?] - let aMap = __pigeon_list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! - let aString = __pigeon_list[11] as! String - let anObject = __pigeon_list[12]! + let anEnum = __pigeon_list[8] as! AnEnum + let aString = __pigeon_list[9] as! String + let anObject = __pigeon_list[10]! + let list = __pigeon_list[11] as! [Any?] + let stringList = __pigeon_list[12] as! [String?] + let intList = __pigeon_list[13] as! [Int64?] + let doubleList = __pigeon_list[14] as! [Double?] + let boolList = __pigeon_list[15] as! [Bool?] + let map = __pigeon_list[16] as! [AnyHashable: Any?] return AllTypes( aBool: aBool, @@ -127,11 +135,15 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - list: list, - aMap: aMap, anEnum: anEnum, aString: aString, - anObject: anObject + anObject: anObject, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map ) } func toList() -> [Any?] { @@ -144,11 +156,15 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - list, - aMap, - anEnum.rawValue, + anEnum, aString, anObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ] } } @@ -166,15 +182,20 @@ class AllNullableTypes { aNullable4ByteArray: FlutterStandardTypedData? = nil, aNullable8ByteArray: FlutterStandardTypedData? = nil, aNullableFloatArray: FlutterStandardTypedData? = nil, - aNullableList: [Any?]? = nil, - aNullableMap: [AnyHashable: Any?]? = nil, nullableNestedList: [[Bool?]?]? = nil, nullableMapWithAnnotations: [String?: String?]? = nil, nullableMapWithObject: [String?: Any?]? = nil, aNullableEnum: AnEnum? = nil, aNullableString: String? = nil, aNullableObject: Any? = nil, - allNullableTypes: AllNullableTypes? = nil + allNullableTypes: AllNullableTypes? = nil, + list: [Any?]? = nil, + stringList: [String?]? = nil, + intList: [Int64?]? = nil, + doubleList: [Double?]? = nil, + boolList: [Bool?]? = nil, + nestedClassList: [AllNullableTypes?]? = nil, + map: [AnyHashable: Any?]? = nil ) { self.aNullableBool = aNullableBool self.aNullableInt = aNullableInt @@ -184,8 +205,6 @@ class AllNullableTypes { self.aNullable4ByteArray = aNullable4ByteArray self.aNullable8ByteArray = aNullable8ByteArray self.aNullableFloatArray = aNullableFloatArray - self.aNullableList = aNullableList - self.aNullableMap = aNullableMap self.nullableNestedList = nullableNestedList self.nullableMapWithAnnotations = nullableMapWithAnnotations self.nullableMapWithObject = nullableMapWithObject @@ -193,6 +212,13 @@ class AllNullableTypes { self.aNullableString = aNullableString self.aNullableObject = aNullableObject self.allNullableTypes = allNullableTypes + self.list = list + self.stringList = stringList + self.intList = intList + self.doubleList = doubleList + self.boolList = boolList + self.nestedClassList = nestedClassList + self.map = map } var aNullableBool: Bool? var aNullableInt: Int64? @@ -202,8 +228,6 @@ class AllNullableTypes { var aNullable4ByteArray: FlutterStandardTypedData? var aNullable8ByteArray: FlutterStandardTypedData? var aNullableFloatArray: FlutterStandardTypedData? - var aNullableList: [Any?]? - var aNullableMap: [AnyHashable: Any?]? var nullableNestedList: [[Bool?]?]? var nullableMapWithAnnotations: [String?: String?]? var nullableMapWithObject: [String?: Any?]? @@ -211,6 +235,13 @@ class AllNullableTypes { var aNullableString: String? var aNullableObject: Any? var allNullableTypes: AllNullableTypes? + var list: [Any?]? + var stringList: [String?]? + var intList: [Int64?]? + var doubleList: [Double?]? + var boolList: [Bool?]? + var nestedClassList: [AllNullableTypes?]? + var map: [AnyHashable: Any?]? // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { @@ -230,19 +261,20 @@ class AllNullableTypes { let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) - let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) - var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) - if let aNullableEnumRawValue = aNullableEnumEnumVal { - aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! - } - let aNullableString: String? = nilOrValue(__pigeon_list[14]) - let aNullableObject: Any? = __pigeon_list[15] - let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[8]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[9]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[10]) + let aNullableEnum: AnEnum? = nilOrValue(__pigeon_list[11]) + let aNullableString: String? = nilOrValue(__pigeon_list[12]) + let aNullableObject: Any? = __pigeon_list[13] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[14]) + let list: [Any?]? = nilOrValue(__pigeon_list[15]) + let stringList: [String?]? = nilOrValue(__pigeon_list[16]) + let intList: [Int64?]? = nilOrValue(__pigeon_list[17]) + let doubleList: [Double?]? = nilOrValue(__pigeon_list[18]) + let boolList: [Bool?]? = nilOrValue(__pigeon_list[19]) + let nestedClassList: [AllNullableTypes?]? = nilOrValue(__pigeon_list[20]) + let map: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[21]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -253,15 +285,20 @@ class AllNullableTypes { aNullable4ByteArray: aNullable4ByteArray, aNullable8ByteArray: aNullable8ByteArray, aNullableFloatArray: aNullableFloatArray, - aNullableList: aNullableList, - aNullableMap: aNullableMap, nullableNestedList: nullableNestedList, nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, aNullableString: aNullableString, aNullableObject: aNullableObject, - allNullableTypes: allNullableTypes + allNullableTypes: allNullableTypes, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + nestedClassList: nestedClassList, + map: map ) } func toList() -> [Any?] { @@ -274,15 +311,20 @@ class AllNullableTypes { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.rawValue, + aNullableEnum, aNullableString, aNullableObject, allNullableTypes, + list, + stringList, + intList, + doubleList, + boolList, + nestedClassList, + map, ] } } @@ -301,14 +343,18 @@ struct AllNullableTypesWithoutRecursion { var aNullable4ByteArray: FlutterStandardTypedData? = nil var aNullable8ByteArray: FlutterStandardTypedData? = nil var aNullableFloatArray: FlutterStandardTypedData? = nil - var aNullableList: [Any?]? = nil - var aNullableMap: [AnyHashable: Any?]? = nil var nullableNestedList: [[Bool?]?]? = nil var nullableMapWithAnnotations: [String?: String?]? = nil var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil var aNullableObject: Any? = nil + var list: [Any?]? = nil + var stringList: [String?]? = nil + var intList: [Int64?]? = nil + var doubleList: [Double?]? = nil + var boolList: [Bool?]? = nil + var map: [AnyHashable: Any?]? = nil // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { @@ -328,18 +374,18 @@ struct AllNullableTypesWithoutRecursion { let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) - let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) - var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) - if let aNullableEnumRawValue = aNullableEnumEnumVal { - aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! - } - let aNullableString: String? = nilOrValue(__pigeon_list[14]) - let aNullableObject: Any? = __pigeon_list[15] + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[8]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[9]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[10]) + let aNullableEnum: AnEnum? = nilOrValue(__pigeon_list[11]) + let aNullableString: String? = nilOrValue(__pigeon_list[12]) + let aNullableObject: Any? = __pigeon_list[13] + let list: [Any?]? = nilOrValue(__pigeon_list[14]) + let stringList: [String?]? = nilOrValue(__pigeon_list[15]) + let intList: [Int64?]? = nilOrValue(__pigeon_list[16]) + let doubleList: [Double?]? = nilOrValue(__pigeon_list[17]) + let boolList: [Bool?]? = nilOrValue(__pigeon_list[18]) + let map: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[19]) return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -350,14 +396,18 @@ struct AllNullableTypesWithoutRecursion { aNullable4ByteArray: aNullable4ByteArray, aNullable8ByteArray: aNullable8ByteArray, aNullableFloatArray: aNullableFloatArray, - aNullableList: aNullableList, - aNullableMap: aNullableMap, nullableNestedList: nullableNestedList, nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, aNullableString: aNullableString, - aNullableObject: aNullableObject + aNullableObject: aNullableObject, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map ) } func toList() -> [Any?] { @@ -370,14 +420,18 @@ struct AllNullableTypesWithoutRecursion { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.rawValue, + aNullableEnum, aNullableString, aNullableObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ] } } @@ -436,62 +490,70 @@ struct TestMessage { ] } } - -private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { +private class CoreTestsPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllTypes.fromList(self.readValue() as! [Any?]) case 130: - return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 131: - return AllTypes.fromList(self.readValue() as! [Any?]) + return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) case 132: + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) + case 133: return TestMessage.fromList(self.readValue() as! [Any?]) + case 134: + var enumResult: AnEnum? = nil + let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int) + if let enumResultAsInt = enumResultAsInt { + enumResult = AnEnum(rawValue: enumResultAsInt) + } + return enumResult default: return super.readValue(ofType: type) } } } -private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { +private class CoreTestsPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllClassesWrapper { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { + if let value = value as? AllTypes { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWithoutRecursion { + } else if let value = value as? AllNullableTypes { super.writeByte(130) super.writeValue(value.toList()) - } else if let value = value as? AllTypes { + } else if let value = value as? AllNullableTypesWithoutRecursion { super.writeByte(131) super.writeValue(value.toList()) - } else if let value = value as? TestMessage { + } else if let value = value as? AllClassesWrapper { super.writeByte(132) super.writeValue(value.toList()) + } else if let value = value as? TestMessage { + super.writeByte(133) + super.writeValue(value.toList()) + } else if let value = value as? AnEnum { + super.writeByte(134) + super.writeValue(value.rawValue) } else { super.writeValue(value) } } } -private class HostIntegrationCoreApiCodecReaderWriter: FlutterStandardReaderWriter { +private class CoreTestsPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return HostIntegrationCoreApiCodecReader(data: data) + return CoreTestsPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return HostIntegrationCoreApiCodecWriter(data: data) + return CoreTestsPigeonCodecWriter(data: data) } } -class HostIntegrationCoreApiCodec: FlutterStandardMessageCodec { - static let shared = HostIntegrationCoreApiCodec( - readerWriter: HostIntegrationCoreApiCodecReaderWriter()) +class CoreTestsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = CoreTestsPigeonCodec(readerWriter: CoreTestsPigeonCodecReaderWriter()) } /// The core interface that each host language plugin must implement in @@ -687,8 +749,7 @@ protocol HostIntegrationCoreApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostIntegrationCoreApiSetup { - /// The codec used by HostIntegrationCoreApi. - static var codec: FlutterStandardMessageCodec { HostIntegrationCoreApiCodec.shared } + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostIntegrationCoreApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostIntegrationCoreApi?, @@ -962,10 +1023,10 @@ class HostIntegrationCoreApiSetup { if let api = api { echoEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum do { let result = try api.echo(anEnumArg) - reply(wrapResult(result.rawValue)) + reply(wrapResult(result)) } catch { reply(wrapError(error)) } @@ -1317,10 +1378,10 @@ class HostIntegrationCoreApiSetup { if let api = api { echoNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) do { let result = try api.echoNullable(anEnumArg) - reply(wrapResult(result?.rawValue)) + reply(wrapResult(result)) } catch { reply(wrapError(error)) } @@ -1564,11 +1625,11 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum api.echoAsync(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -1875,11 +1936,11 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) api.echoAsyncNullable(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res?.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2202,11 +2263,11 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum api.callFlutterEcho(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2364,11 +2425,11 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) api.callFlutterNullableEcho(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res?.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2399,63 +2460,6 @@ class HostIntegrationCoreApiSetup { } } } -private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return AllClassesWrapper.fromList(self.readValue() as! [Any?]) - case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) - case 130: - return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) - case 131: - return AllTypes.fromList(self.readValue() as! [Any?]) - case 132: - return TestMessage.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? AllClassesWrapper { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { - super.writeByte(129) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWithoutRecursion { - super.writeByte(130) - super.writeValue(value.toList()) - } else if let value = value as? AllTypes { - super.writeByte(131) - super.writeValue(value.toList()) - } else if let value = value as? TestMessage { - super.writeByte(132) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class FlutterIntegrationCoreApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return FlutterIntegrationCoreApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FlutterIntegrationCoreApiCodecWriter(data: data) - } -} - -class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { - static let shared = FlutterIntegrationCoreApiCodec( - readerWriter: FlutterIntegrationCoreApiCodecReaderWriter()) -} - /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. /// @@ -2550,8 +2554,8 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { self.binaryMessenger = binaryMessenger self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return FlutterIntegrationCoreApiCodec.shared + var codec: CoreTestsPigeonCodec { + return CoreTestsPigeonCodec.shared } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. @@ -2976,7 +2980,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in + channel.sendMessage([anEnumArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2993,7 +2997,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) } else { - let result = AnEnum(rawValue: listResponse[0] as! Int)! + let result = listResponse[0] as! AnEnum completion(.success(result)) } } @@ -3177,7 +3181,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in + channel.sendMessage([anEnumArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3188,8 +3192,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { let details: String? = nilOrValue(listResponse[2]) completion(.failure(PigeonError(code: code, message: message, details: details))) } else { - let result: AnEnum? = - isNullish(listResponse[0]) ? nil : AnEnum(rawValue: listResponse[0] as! Int)! + let result: AnEnum? = nilOrValue(listResponse[0]) completion(.success(result)) } } @@ -3255,7 +3258,7 @@ protocol HostTrivialApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostTrivialApiSetup { - /// The codec used by HostTrivialApi. + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostTrivialApi?, messageChannelSuffix: String = "" @@ -3263,7 +3266,7 @@ class HostTrivialApiSetup { let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let noopChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopChannel.setMessageHandler { _, reply in do { @@ -3288,7 +3291,7 @@ protocol HostSmallApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostSmallApiSetup { - /// The codec used by HostSmallApi. + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostSmallApi?, messageChannelSuffix: String = "" @@ -3296,7 +3299,7 @@ class HostSmallApiSetup { let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let echoChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -3315,7 +3318,7 @@ class HostSmallApiSetup { } let voidVoidChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { voidVoidChannel.setMessageHandler { _, reply in api.voidVoid { result in @@ -3332,42 +3335,6 @@ class HostSmallApiSetup { } } } -private class FlutterSmallApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return TestMessage.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class FlutterSmallApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? TestMessage { - super.writeByte(128) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class FlutterSmallApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return FlutterSmallApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FlutterSmallApiCodecWriter(data: data) - } -} - -class FlutterSmallApiCodec: FlutterStandardMessageCodec { - static let shared = FlutterSmallApiCodec(readerWriter: FlutterSmallApiCodecReaderWriter()) -} - /// A simple API called in some unit tests. /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. @@ -3382,8 +3349,8 @@ class FlutterSmallApi: FlutterSmallApiProtocol { self.binaryMessenger = binaryMessenger self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return FlutterSmallApiCodec.shared + var codec: CoreTestsPigeonCodec { + return CoreTestsPigeonCodec.shared } func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { 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 c54100d2db4..2b95f040b48 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 @@ -94,11 +94,15 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var list: [Any?] - var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any + var list: [Any?] + var stringList: [String?] + var intList: [Int64?] + var doubleList: [Double?] + var boolList: [Bool?] + var map: [AnyHashable: Any?] // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { @@ -112,11 +116,15 @@ struct AllTypes { let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData - let list = __pigeon_list[8] as! [Any?] - let aMap = __pigeon_list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! - let aString = __pigeon_list[11] as! String - let anObject = __pigeon_list[12]! + let anEnum = __pigeon_list[8] as! AnEnum + let aString = __pigeon_list[9] as! String + let anObject = __pigeon_list[10]! + let list = __pigeon_list[11] as! [Any?] + let stringList = __pigeon_list[12] as! [String?] + let intList = __pigeon_list[13] as! [Int64?] + let doubleList = __pigeon_list[14] as! [Double?] + let boolList = __pigeon_list[15] as! [Bool?] + let map = __pigeon_list[16] as! [AnyHashable: Any?] return AllTypes( aBool: aBool, @@ -127,11 +135,15 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - list: list, - aMap: aMap, anEnum: anEnum, aString: aString, - anObject: anObject + anObject: anObject, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map ) } func toList() -> [Any?] { @@ -144,11 +156,15 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - list, - aMap, - anEnum.rawValue, + anEnum, aString, anObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ] } } @@ -166,15 +182,20 @@ class AllNullableTypes { aNullable4ByteArray: FlutterStandardTypedData? = nil, aNullable8ByteArray: FlutterStandardTypedData? = nil, aNullableFloatArray: FlutterStandardTypedData? = nil, - aNullableList: [Any?]? = nil, - aNullableMap: [AnyHashable: Any?]? = nil, nullableNestedList: [[Bool?]?]? = nil, nullableMapWithAnnotations: [String?: String?]? = nil, nullableMapWithObject: [String?: Any?]? = nil, aNullableEnum: AnEnum? = nil, aNullableString: String? = nil, aNullableObject: Any? = nil, - allNullableTypes: AllNullableTypes? = nil + allNullableTypes: AllNullableTypes? = nil, + list: [Any?]? = nil, + stringList: [String?]? = nil, + intList: [Int64?]? = nil, + doubleList: [Double?]? = nil, + boolList: [Bool?]? = nil, + nestedClassList: [AllNullableTypes?]? = nil, + map: [AnyHashable: Any?]? = nil ) { self.aNullableBool = aNullableBool self.aNullableInt = aNullableInt @@ -184,8 +205,6 @@ class AllNullableTypes { self.aNullable4ByteArray = aNullable4ByteArray self.aNullable8ByteArray = aNullable8ByteArray self.aNullableFloatArray = aNullableFloatArray - self.aNullableList = aNullableList - self.aNullableMap = aNullableMap self.nullableNestedList = nullableNestedList self.nullableMapWithAnnotations = nullableMapWithAnnotations self.nullableMapWithObject = nullableMapWithObject @@ -193,6 +212,13 @@ class AllNullableTypes { self.aNullableString = aNullableString self.aNullableObject = aNullableObject self.allNullableTypes = allNullableTypes + self.list = list + self.stringList = stringList + self.intList = intList + self.doubleList = doubleList + self.boolList = boolList + self.nestedClassList = nestedClassList + self.map = map } var aNullableBool: Bool? var aNullableInt: Int64? @@ -202,8 +228,6 @@ class AllNullableTypes { var aNullable4ByteArray: FlutterStandardTypedData? var aNullable8ByteArray: FlutterStandardTypedData? var aNullableFloatArray: FlutterStandardTypedData? - var aNullableList: [Any?]? - var aNullableMap: [AnyHashable: Any?]? var nullableNestedList: [[Bool?]?]? var nullableMapWithAnnotations: [String?: String?]? var nullableMapWithObject: [String?: Any?]? @@ -211,6 +235,13 @@ class AllNullableTypes { var aNullableString: String? var aNullableObject: Any? var allNullableTypes: AllNullableTypes? + var list: [Any?]? + var stringList: [String?]? + var intList: [Int64?]? + var doubleList: [Double?]? + var boolList: [Bool?]? + var nestedClassList: [AllNullableTypes?]? + var map: [AnyHashable: Any?]? // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { @@ -230,19 +261,20 @@ class AllNullableTypes { let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) - let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) - var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) - if let aNullableEnumRawValue = aNullableEnumEnumVal { - aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! - } - let aNullableString: String? = nilOrValue(__pigeon_list[14]) - let aNullableObject: Any? = __pigeon_list[15] - let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[8]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[9]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[10]) + let aNullableEnum: AnEnum? = nilOrValue(__pigeon_list[11]) + let aNullableString: String? = nilOrValue(__pigeon_list[12]) + let aNullableObject: Any? = __pigeon_list[13] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[14]) + let list: [Any?]? = nilOrValue(__pigeon_list[15]) + let stringList: [String?]? = nilOrValue(__pigeon_list[16]) + let intList: [Int64?]? = nilOrValue(__pigeon_list[17]) + let doubleList: [Double?]? = nilOrValue(__pigeon_list[18]) + let boolList: [Bool?]? = nilOrValue(__pigeon_list[19]) + let nestedClassList: [AllNullableTypes?]? = nilOrValue(__pigeon_list[20]) + let map: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[21]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -253,15 +285,20 @@ class AllNullableTypes { aNullable4ByteArray: aNullable4ByteArray, aNullable8ByteArray: aNullable8ByteArray, aNullableFloatArray: aNullableFloatArray, - aNullableList: aNullableList, - aNullableMap: aNullableMap, nullableNestedList: nullableNestedList, nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, aNullableString: aNullableString, aNullableObject: aNullableObject, - allNullableTypes: allNullableTypes + allNullableTypes: allNullableTypes, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + nestedClassList: nestedClassList, + map: map ) } func toList() -> [Any?] { @@ -274,15 +311,20 @@ class AllNullableTypes { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.rawValue, + aNullableEnum, aNullableString, aNullableObject, allNullableTypes, + list, + stringList, + intList, + doubleList, + boolList, + nestedClassList, + map, ] } } @@ -301,14 +343,18 @@ struct AllNullableTypesWithoutRecursion { var aNullable4ByteArray: FlutterStandardTypedData? = nil var aNullable8ByteArray: FlutterStandardTypedData? = nil var aNullableFloatArray: FlutterStandardTypedData? = nil - var aNullableList: [Any?]? = nil - var aNullableMap: [AnyHashable: Any?]? = nil var nullableNestedList: [[Bool?]?]? = nil var nullableMapWithAnnotations: [String?: String?]? = nil var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil var aNullableObject: Any? = nil + var list: [Any?]? = nil + var stringList: [String?]? = nil + var intList: [Int64?]? = nil + var doubleList: [Double?]? = nil + var boolList: [Bool?]? = nil + var map: [AnyHashable: Any?]? = nil // swift-format-ignore: AlwaysUseLowerCamelCase static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { @@ -328,18 +374,18 @@ struct AllNullableTypesWithoutRecursion { let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) - let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) - var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) - if let aNullableEnumRawValue = aNullableEnumEnumVal { - aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! - } - let aNullableString: String? = nilOrValue(__pigeon_list[14]) - let aNullableObject: Any? = __pigeon_list[15] + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[8]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[9]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[10]) + let aNullableEnum: AnEnum? = nilOrValue(__pigeon_list[11]) + let aNullableString: String? = nilOrValue(__pigeon_list[12]) + let aNullableObject: Any? = __pigeon_list[13] + let list: [Any?]? = nilOrValue(__pigeon_list[14]) + let stringList: [String?]? = nilOrValue(__pigeon_list[15]) + let intList: [Int64?]? = nilOrValue(__pigeon_list[16]) + let doubleList: [Double?]? = nilOrValue(__pigeon_list[17]) + let boolList: [Bool?]? = nilOrValue(__pigeon_list[18]) + let map: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[19]) return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -350,14 +396,18 @@ struct AllNullableTypesWithoutRecursion { aNullable4ByteArray: aNullable4ByteArray, aNullable8ByteArray: aNullable8ByteArray, aNullableFloatArray: aNullableFloatArray, - aNullableList: aNullableList, - aNullableMap: aNullableMap, nullableNestedList: nullableNestedList, nullableMapWithAnnotations: nullableMapWithAnnotations, nullableMapWithObject: nullableMapWithObject, aNullableEnum: aNullableEnum, aNullableString: aNullableString, - aNullableObject: aNullableObject + aNullableObject: aNullableObject, + list: list, + stringList: stringList, + intList: intList, + doubleList: doubleList, + boolList: boolList, + map: map ) } func toList() -> [Any?] { @@ -370,14 +420,18 @@ struct AllNullableTypesWithoutRecursion { aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, - aNullableList, - aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, - aNullableEnum?.rawValue, + aNullableEnum, aNullableString, aNullableObject, + list, + stringList, + intList, + doubleList, + boolList, + map, ] } } @@ -436,62 +490,70 @@ struct TestMessage { ] } } - -private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { +private class CoreTestsPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return AllClassesWrapper.fromList(self.readValue() as! [Any?]) case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) + return AllTypes.fromList(self.readValue() as! [Any?]) case 130: - return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) + return AllNullableTypes.fromList(self.readValue() as! [Any?]) case 131: - return AllTypes.fromList(self.readValue() as! [Any?]) + return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) case 132: + return AllClassesWrapper.fromList(self.readValue() as! [Any?]) + case 133: return TestMessage.fromList(self.readValue() as! [Any?]) + case 134: + var enumResult: AnEnum? = nil + let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int) + if let enumResultAsInt = enumResultAsInt { + enumResult = AnEnum(rawValue: enumResultAsInt) + } + return enumResult default: return super.readValue(ofType: type) } } } -private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { +private class CoreTestsPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? AllClassesWrapper { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { + if let value = value as? AllTypes { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWithoutRecursion { + } else if let value = value as? AllNullableTypes { super.writeByte(130) super.writeValue(value.toList()) - } else if let value = value as? AllTypes { + } else if let value = value as? AllNullableTypesWithoutRecursion { super.writeByte(131) super.writeValue(value.toList()) - } else if let value = value as? TestMessage { + } else if let value = value as? AllClassesWrapper { super.writeByte(132) super.writeValue(value.toList()) + } else if let value = value as? TestMessage { + super.writeByte(133) + super.writeValue(value.toList()) + } else if let value = value as? AnEnum { + super.writeByte(134) + super.writeValue(value.rawValue) } else { super.writeValue(value) } } } -private class HostIntegrationCoreApiCodecReaderWriter: FlutterStandardReaderWriter { +private class CoreTestsPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return HostIntegrationCoreApiCodecReader(data: data) + return CoreTestsPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return HostIntegrationCoreApiCodecWriter(data: data) + return CoreTestsPigeonCodecWriter(data: data) } } -class HostIntegrationCoreApiCodec: FlutterStandardMessageCodec { - static let shared = HostIntegrationCoreApiCodec( - readerWriter: HostIntegrationCoreApiCodecReaderWriter()) +class CoreTestsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = CoreTestsPigeonCodec(readerWriter: CoreTestsPigeonCodecReaderWriter()) } /// The core interface that each host language plugin must implement in @@ -687,8 +749,7 @@ protocol HostIntegrationCoreApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostIntegrationCoreApiSetup { - /// The codec used by HostIntegrationCoreApi. - static var codec: FlutterStandardMessageCodec { HostIntegrationCoreApiCodec.shared } + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostIntegrationCoreApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostIntegrationCoreApi?, @@ -962,10 +1023,10 @@ class HostIntegrationCoreApiSetup { if let api = api { echoEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum do { let result = try api.echo(anEnumArg) - reply(wrapResult(result.rawValue)) + reply(wrapResult(result)) } catch { reply(wrapError(error)) } @@ -1317,10 +1378,10 @@ class HostIntegrationCoreApiSetup { if let api = api { echoNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) do { let result = try api.echoNullable(anEnumArg) - reply(wrapResult(result?.rawValue)) + reply(wrapResult(result)) } catch { reply(wrapError(error)) } @@ -1564,11 +1625,11 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum api.echoAsync(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -1875,11 +1936,11 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) api.echoAsyncNullable(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res?.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2202,11 +2263,11 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg = AnEnum(rawValue: args[0] as! Int)! + let anEnumArg = args[0] as! AnEnum api.callFlutterEcho(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2364,11 +2425,11 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableEnumChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anEnumArg: AnEnum? = isNullish(args[0]) ? nil : AnEnum(rawValue: args[0] as! Int)! + let anEnumArg: AnEnum? = nilOrValue(args[0]) api.callFlutterNullableEcho(anEnumArg) { result in switch result { case .success(let res): - reply(wrapResult(res?.rawValue)) + reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } @@ -2399,63 +2460,6 @@ class HostIntegrationCoreApiSetup { } } } -private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return AllClassesWrapper.fromList(self.readValue() as! [Any?]) - case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any?]) - case 130: - return AllNullableTypesWithoutRecursion.fromList(self.readValue() as! [Any?]) - case 131: - return AllTypes.fromList(self.readValue() as! [Any?]) - case 132: - return TestMessage.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? AllClassesWrapper { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { - super.writeByte(129) - super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWithoutRecursion { - super.writeByte(130) - super.writeValue(value.toList()) - } else if let value = value as? AllTypes { - super.writeByte(131) - super.writeValue(value.toList()) - } else if let value = value as? TestMessage { - super.writeByte(132) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class FlutterIntegrationCoreApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return FlutterIntegrationCoreApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FlutterIntegrationCoreApiCodecWriter(data: data) - } -} - -class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { - static let shared = FlutterIntegrationCoreApiCodec( - readerWriter: FlutterIntegrationCoreApiCodecReaderWriter()) -} - /// The core interface that the Dart platform_test code implements for host /// integration tests to call into. /// @@ -2550,8 +2554,8 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { self.binaryMessenger = binaryMessenger self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return FlutterIntegrationCoreApiCodec.shared + var codec: CoreTestsPigeonCodec { + return CoreTestsPigeonCodec.shared } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. @@ -2976,7 +2980,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in + channel.sendMessage([anEnumArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2993,7 +2997,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) } else { - let result = AnEnum(rawValue: listResponse[0] as! Int)! + let result = listResponse[0] as! AnEnum completion(.success(result)) } } @@ -3177,7 +3181,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in + channel.sendMessage([anEnumArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3188,8 +3192,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { let details: String? = nilOrValue(listResponse[2]) completion(.failure(PigeonError(code: code, message: message, details: details))) } else { - let result: AnEnum? = - isNullish(listResponse[0]) ? nil : AnEnum(rawValue: listResponse[0] as! Int)! + let result: AnEnum? = nilOrValue(listResponse[0]) completion(.success(result)) } } @@ -3255,7 +3258,7 @@ protocol HostTrivialApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostTrivialApiSetup { - /// The codec used by HostTrivialApi. + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostTrivialApi?, messageChannelSuffix: String = "" @@ -3263,7 +3266,7 @@ class HostTrivialApiSetup { let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let noopChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopChannel.setMessageHandler { _, reply in do { @@ -3288,7 +3291,7 @@ protocol HostSmallApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class HostSmallApiSetup { - /// The codec used by HostSmallApi. + static var codec: FlutterStandardMessageCodec { CoreTestsPigeonCodec.shared } /// Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: HostSmallApi?, messageChannelSuffix: String = "" @@ -3296,7 +3299,7 @@ class HostSmallApiSetup { let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let echoChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -3315,7 +3318,7 @@ class HostSmallApiSetup { } let voidVoidChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid\(channelSuffix)", - binaryMessenger: binaryMessenger) + binaryMessenger: binaryMessenger, codec: codec) if let api = api { voidVoidChannel.setMessageHandler { _, reply in api.voidVoid { result in @@ -3332,42 +3335,6 @@ class HostSmallApiSetup { } } } -private class FlutterSmallApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return TestMessage.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class FlutterSmallApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? TestMessage { - super.writeByte(128) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class FlutterSmallApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return FlutterSmallApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FlutterSmallApiCodecWriter(data: data) - } -} - -class FlutterSmallApiCodec: FlutterStandardMessageCodec { - static let shared = FlutterSmallApiCodec(readerWriter: FlutterSmallApiCodecReaderWriter()) -} - /// A simple API called in some unit tests. /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. @@ -3382,8 +3349,8 @@ class FlutterSmallApi: FlutterSmallApiProtocol { self.binaryMessenger = binaryMessenger self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return FlutterSmallApiCodec.shared + var codec: CoreTestsPigeonCodec { + return CoreTestsPigeonCodec.shared } func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { 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 c4e74f45119..ec06637957d 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 @@ -39,9 +39,12 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, - const EncodableList& list, const EncodableMap& a_map, const AnEnum& an_enum, const std::string& a_string, - const EncodableValue& an_object) + const EncodableValue& an_object, const EncodableList& list, + const EncodableList& string_list, + const EncodableList& int_list, + const EncodableList& double_list, + const EncodableList& bool_list, const EncodableMap& map) : a_bool_(a_bool), an_int_(an_int), an_int64_(an_int64), @@ -50,11 +53,15 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, a4_byte_array_(a4_byte_array), a8_byte_array_(a8_byte_array), a_float_array_(a_float_array), - list_(list), - a_map_(a_map), an_enum_(an_enum), a_string_(a_string), - an_object_(an_object) {} + an_object_(an_object), + list_(list), + string_list_(string_list), + int_list_(int_list), + double_list_(double_list), + bool_list_(bool_list), + map_(map) {} bool AllTypes::a_bool() const { return a_bool_; } @@ -104,14 +111,6 @@ void AllTypes::set_a_float_array(const std::vector& value_arg) { a_float_array_ = value_arg; } -const EncodableList& AllTypes::list() const { return list_; } - -void AllTypes::set_list(const EncodableList& value_arg) { list_ = value_arg; } - -const EncodableMap& AllTypes::a_map() const { return a_map_; } - -void AllTypes::set_a_map(const EncodableMap& value_arg) { a_map_ = value_arg; } - const AnEnum& AllTypes::an_enum() const { return an_enum_; } void AllTypes::set_an_enum(const AnEnum& value_arg) { an_enum_ = value_arg; } @@ -128,9 +127,41 @@ void AllTypes::set_an_object(const EncodableValue& value_arg) { an_object_ = value_arg; } +const EncodableList& AllTypes::list() const { return list_; } + +void AllTypes::set_list(const EncodableList& value_arg) { list_ = value_arg; } + +const EncodableList& AllTypes::string_list() const { return string_list_; } + +void AllTypes::set_string_list(const EncodableList& value_arg) { + string_list_ = value_arg; +} + +const EncodableList& AllTypes::int_list() const { return int_list_; } + +void AllTypes::set_int_list(const EncodableList& value_arg) { + int_list_ = value_arg; +} + +const EncodableList& AllTypes::double_list() const { return double_list_; } + +void AllTypes::set_double_list(const EncodableList& value_arg) { + double_list_ = value_arg; +} + +const EncodableList& AllTypes::bool_list() const { return bool_list_; } + +void AllTypes::set_bool_list(const EncodableList& value_arg) { + bool_list_ = value_arg; +} + +const EncodableMap& AllTypes::map() const { return map_; } + +void AllTypes::set_map(const EncodableMap& value_arg) { map_ = value_arg; } + EncodableList AllTypes::ToEncodableList() const { EncodableList list; - list.reserve(13); + list.reserve(17); list.push_back(EncodableValue(a_bool_)); list.push_back(EncodableValue(an_int_)); list.push_back(EncodableValue(an_int64_)); @@ -139,11 +170,15 @@ EncodableList AllTypes::ToEncodableList() const { list.push_back(EncodableValue(a4_byte_array_)); list.push_back(EncodableValue(a8_byte_array_)); list.push_back(EncodableValue(a_float_array_)); - list.push_back(EncodableValue(list_)); - list.push_back(EncodableValue(a_map_)); - list.push_back(EncodableValue((int)an_enum_)); + list.push_back(CustomEncodableValue(an_enum_)); list.push_back(EncodableValue(a_string_)); list.push_back(an_object_); + list.push_back(EncodableValue(list_)); + list.push_back(EncodableValue(string_list_)); + list.push_back(EncodableValue(int_list_)); + list.push_back(EncodableValue(double_list_)); + list.push_back(EncodableValue(bool_list_)); + list.push_back(EncodableValue(map_)); return list; } @@ -153,9 +188,12 @@ AllTypes AllTypes::FromEncodableList(const EncodableList& list) { std::get(list[3]), std::get>(list[4]), std::get>(list[5]), std::get>(list[6]), - std::get>(list[7]), std::get(list[8]), - std::get(list[9]), (AnEnum)(std::get(list[10])), - std::get(list[11]), list[12]); + std::get>(list[7]), + std::any_cast(std::get(list[8])), + std::get(list[9]), list[10], + std::get(list[11]), std::get(list[12]), + std::get(list[13]), std::get(list[14]), + std::get(list[15]), std::get(list[16])); return decoded; } @@ -170,13 +208,15 @@ AllNullableTypes::AllNullableTypes( const std::vector* a_nullable4_byte_array, const std::vector* a_nullable8_byte_array, const std::vector* a_nullable_float_array, - const EncodableList* a_nullable_list, const EncodableMap* a_nullable_map, const EncodableList* nullable_nested_list, const EncodableMap* nullable_map_with_annotations, const EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, const std::string* a_nullable_string, const EncodableValue* a_nullable_object, - const AllNullableTypes* all_nullable_types) + const AllNullableTypes* all_nullable_types, const EncodableList* list, + const EncodableList* string_list, const EncodableList* int_list, + const EncodableList* double_list, const EncodableList* bool_list, + const EncodableList* nested_class_list, const EncodableMap* map) : a_nullable_bool_(a_nullable_bool ? std::optional(*a_nullable_bool) : std::nullopt), a_nullable_int_(a_nullable_int ? std::optional(*a_nullable_int) @@ -203,12 +243,6 @@ AllNullableTypes::AllNullableTypes( a_nullable_float_array ? std::optional>(*a_nullable_float_array) : std::nullopt), - a_nullable_list_(a_nullable_list - ? std::optional(*a_nullable_list) - : std::nullopt), - a_nullable_map_(a_nullable_map - ? std::optional(*a_nullable_map) - : std::nullopt), nullable_nested_list_(nullable_nested_list ? std::optional( *nullable_nested_list) : std::nullopt), @@ -231,7 +265,20 @@ AllNullableTypes::AllNullableTypes( all_nullable_types_( all_nullable_types ? std::make_unique(*all_nullable_types) - : nullptr) {} + : nullptr), + list_(list ? std::optional(*list) : std::nullopt), + string_list_(string_list ? std::optional(*string_list) + : std::nullopt), + int_list_(int_list ? std::optional(*int_list) + : std::nullopt), + double_list_(double_list ? std::optional(*double_list) + : std::nullopt), + bool_list_(bool_list ? std::optional(*bool_list) + : std::nullopt), + nested_class_list_(nested_class_list + ? std::optional(*nested_class_list) + : std::nullopt), + map_(map ? std::optional(*map) : std::nullopt) {} AllNullableTypes::AllNullableTypes(const AllNullableTypes& other) : a_nullable_bool_(other.a_nullable_bool_ @@ -262,12 +309,6 @@ AllNullableTypes::AllNullableTypes(const AllNullableTypes& other) ? std::optional>( *other.a_nullable_float_array_) : std::nullopt), - a_nullable_list_(other.a_nullable_list_ ? std::optional( - *other.a_nullable_list_) - : std::nullopt), - a_nullable_map_(other.a_nullable_map_ - ? std::optional(*other.a_nullable_map_) - : std::nullopt), nullable_nested_list_( other.nullable_nested_list_ ? std::optional(*other.nullable_nested_list_) @@ -295,7 +336,26 @@ AllNullableTypes::AllNullableTypes(const AllNullableTypes& other) all_nullable_types_( other.all_nullable_types_ ? std::make_unique(*other.all_nullable_types_) - : nullptr) {} + : nullptr), + list_(other.list_ ? std::optional(*other.list_) + : std::nullopt), + string_list_(other.string_list_ + ? std::optional(*other.string_list_) + : std::nullopt), + int_list_(other.int_list_ ? std::optional(*other.int_list_) + : std::nullopt), + double_list_(other.double_list_ + ? std::optional(*other.double_list_) + : std::nullopt), + bool_list_(other.bool_list_ + ? std::optional(*other.bool_list_) + : std::nullopt), + nested_class_list_( + other.nested_class_list_ + ? std::optional(*other.nested_class_list_) + : std::nullopt), + map_(other.map_ ? std::optional(*other.map_) + : std::nullopt) {} AllNullableTypes& AllNullableTypes::operator=(const AllNullableTypes& other) { a_nullable_bool_ = other.a_nullable_bool_; @@ -306,8 +366,6 @@ AllNullableTypes& AllNullableTypes::operator=(const AllNullableTypes& other) { a_nullable4_byte_array_ = other.a_nullable4_byte_array_; a_nullable8_byte_array_ = other.a_nullable8_byte_array_; a_nullable_float_array_ = other.a_nullable_float_array_; - a_nullable_list_ = other.a_nullable_list_; - a_nullable_map_ = other.a_nullable_map_; nullable_nested_list_ = other.nullable_nested_list_; nullable_map_with_annotations_ = other.nullable_map_with_annotations_; nullable_map_with_object_ = other.nullable_map_with_object_; @@ -318,6 +376,13 @@ AllNullableTypes& AllNullableTypes::operator=(const AllNullableTypes& other) { other.all_nullable_types_ ? std::make_unique(*other.all_nullable_types_) : nullptr; + list_ = other.list_; + string_list_ = other.string_list_; + int_list_ = other.int_list_; + double_list_ = other.double_list_; + bool_list_ = other.bool_list_; + nested_class_list_ = other.nested_class_list_; + map_ = other.map_; return *this; } @@ -435,32 +500,6 @@ void AllNullableTypes::set_a_nullable_float_array( a_nullable_float_array_ = value_arg; } -const EncodableList* AllNullableTypes::a_nullable_list() const { - return a_nullable_list_ ? &(*a_nullable_list_) : nullptr; -} - -void AllNullableTypes::set_a_nullable_list(const EncodableList* value_arg) { - a_nullable_list_ = - value_arg ? std::optional(*value_arg) : std::nullopt; -} - -void AllNullableTypes::set_a_nullable_list(const EncodableList& value_arg) { - a_nullable_list_ = value_arg; -} - -const EncodableMap* AllNullableTypes::a_nullable_map() const { - return a_nullable_map_ ? &(*a_nullable_map_) : nullptr; -} - -void AllNullableTypes::set_a_nullable_map(const EncodableMap* value_arg) { - a_nullable_map_ = - value_arg ? std::optional(*value_arg) : std::nullopt; -} - -void AllNullableTypes::set_a_nullable_map(const EncodableMap& value_arg) { - a_nullable_map_ = value_arg; -} - const EncodableList* AllNullableTypes::nullable_nested_list() const { return nullable_nested_list_ ? &(*nullable_nested_list_) : nullptr; } @@ -562,9 +601,98 @@ void AllNullableTypes::set_all_nullable_types( all_nullable_types_ = std::make_unique(value_arg); } +const EncodableList* AllNullableTypes::list() const { + return list_ ? &(*list_) : nullptr; +} + +void AllNullableTypes::set_list(const EncodableList* value_arg) { + list_ = value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_list(const EncodableList& value_arg) { + list_ = value_arg; +} + +const EncodableList* AllNullableTypes::string_list() const { + return string_list_ ? &(*string_list_) : nullptr; +} + +void AllNullableTypes::set_string_list(const EncodableList* value_arg) { + string_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_string_list(const EncodableList& value_arg) { + string_list_ = value_arg; +} + +const EncodableList* AllNullableTypes::int_list() const { + return int_list_ ? &(*int_list_) : nullptr; +} + +void AllNullableTypes::set_int_list(const EncodableList* value_arg) { + int_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_int_list(const EncodableList& value_arg) { + int_list_ = value_arg; +} + +const EncodableList* AllNullableTypes::double_list() const { + return double_list_ ? &(*double_list_) : nullptr; +} + +void AllNullableTypes::set_double_list(const EncodableList* value_arg) { + double_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_double_list(const EncodableList& value_arg) { + double_list_ = value_arg; +} + +const EncodableList* AllNullableTypes::bool_list() const { + return bool_list_ ? &(*bool_list_) : nullptr; +} + +void AllNullableTypes::set_bool_list(const EncodableList* value_arg) { + bool_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_bool_list(const EncodableList& value_arg) { + bool_list_ = value_arg; +} + +const EncodableList* AllNullableTypes::nested_class_list() const { + return nested_class_list_ ? &(*nested_class_list_) : nullptr; +} + +void AllNullableTypes::set_nested_class_list(const EncodableList* value_arg) { + nested_class_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_nested_class_list(const EncodableList& value_arg) { + nested_class_list_ = value_arg; +} + +const EncodableMap* AllNullableTypes::map() const { + return map_ ? &(*map_) : nullptr; +} + +void AllNullableTypes::set_map(const EncodableMap* value_arg) { + map_ = value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypes::set_map(const EncodableMap& value_arg) { + map_ = value_arg; +} + EncodableList AllNullableTypes::ToEncodableList() const { EncodableList list; - list.reserve(17); + list.reserve(22); list.push_back(a_nullable_bool_ ? EncodableValue(*a_nullable_bool_) : EncodableValue()); list.push_back(a_nullable_int_ ? EncodableValue(*a_nullable_int_) @@ -585,10 +713,6 @@ EncodableList AllNullableTypes::ToEncodableList() const { list.push_back(a_nullable_float_array_ ? EncodableValue(*a_nullable_float_array_) : EncodableValue()); - list.push_back(a_nullable_list_ ? EncodableValue(*a_nullable_list_) - : EncodableValue()); - list.push_back(a_nullable_map_ ? EncodableValue(*a_nullable_map_) - : EncodableValue()); list.push_back(nullable_nested_list_ ? EncodableValue(*nullable_nested_list_) : EncodableValue()); list.push_back(nullable_map_with_annotations_ @@ -597,7 +721,7 @@ EncodableList AllNullableTypes::ToEncodableList() const { list.push_back(nullable_map_with_object_ ? EncodableValue(*nullable_map_with_object_) : EncodableValue()); - list.push_back(a_nullable_enum_ ? EncodableValue((int)(*a_nullable_enum_)) + list.push_back(a_nullable_enum_ ? CustomEncodableValue(*a_nullable_enum_) : EncodableValue()); list.push_back(a_nullable_string_ ? EncodableValue(*a_nullable_string_) : EncodableValue()); @@ -605,6 +729,16 @@ EncodableList AllNullableTypes::ToEncodableList() const { list.push_back(all_nullable_types_ ? CustomEncodableValue(*all_nullable_types_) : EncodableValue()); + list.push_back(list_ ? EncodableValue(*list_) : EncodableValue()); + list.push_back(string_list_ ? EncodableValue(*string_list_) + : EncodableValue()); + list.push_back(int_list_ ? EncodableValue(*int_list_) : EncodableValue()); + list.push_back(double_list_ ? EncodableValue(*double_list_) + : EncodableValue()); + list.push_back(bool_list_ ? EncodableValue(*bool_list_) : EncodableValue()); + list.push_back(nested_class_list_ ? EncodableValue(*nested_class_list_) + : EncodableValue()); + list.push_back(map_ ? EncodableValue(*map_) : EncodableValue()); return list; } @@ -648,50 +782,69 @@ AllNullableTypes AllNullableTypes::FromEncodableList( decoded.set_a_nullable_float_array( std::get>(encodable_a_nullable_float_array)); } - auto& encodable_a_nullable_list = list[8]; - if (!encodable_a_nullable_list.IsNull()) { - decoded.set_a_nullable_list( - std::get(encodable_a_nullable_list)); - } - auto& encodable_a_nullable_map = list[9]; - if (!encodable_a_nullable_map.IsNull()) { - decoded.set_a_nullable_map( - std::get(encodable_a_nullable_map)); - } - auto& encodable_nullable_nested_list = list[10]; + auto& encodable_nullable_nested_list = list[8]; if (!encodable_nullable_nested_list.IsNull()) { decoded.set_nullable_nested_list( std::get(encodable_nullable_nested_list)); } - auto& encodable_nullable_map_with_annotations = list[11]; + auto& encodable_nullable_map_with_annotations = list[9]; if (!encodable_nullable_map_with_annotations.IsNull()) { decoded.set_nullable_map_with_annotations( std::get(encodable_nullable_map_with_annotations)); } - auto& encodable_nullable_map_with_object = list[12]; + auto& encodable_nullable_map_with_object = list[10]; if (!encodable_nullable_map_with_object.IsNull()) { decoded.set_nullable_map_with_object( std::get(encodable_nullable_map_with_object)); } - auto& encodable_a_nullable_enum = list[13]; + auto& encodable_a_nullable_enum = list[11]; if (!encodable_a_nullable_enum.IsNull()) { - decoded.set_a_nullable_enum( - (AnEnum)(std::get(encodable_a_nullable_enum))); + decoded.set_a_nullable_enum(std::any_cast( + std::get(encodable_a_nullable_enum))); } - auto& encodable_a_nullable_string = list[14]; + auto& encodable_a_nullable_string = list[12]; if (!encodable_a_nullable_string.IsNull()) { decoded.set_a_nullable_string( std::get(encodable_a_nullable_string)); } - auto& encodable_a_nullable_object = list[15]; + auto& encodable_a_nullable_object = list[13]; if (!encodable_a_nullable_object.IsNull()) { decoded.set_a_nullable_object(encodable_a_nullable_object); } - auto& encodable_all_nullable_types = list[16]; + auto& encodable_all_nullable_types = list[14]; if (!encodable_all_nullable_types.IsNull()) { decoded.set_all_nullable_types(std::any_cast( std::get(encodable_all_nullable_types))); } + auto& encodable_list = list[15]; + if (!encodable_list.IsNull()) { + decoded.set_list(std::get(encodable_list)); + } + auto& encodable_string_list = list[16]; + if (!encodable_string_list.IsNull()) { + decoded.set_string_list(std::get(encodable_string_list)); + } + auto& encodable_int_list = list[17]; + if (!encodable_int_list.IsNull()) { + decoded.set_int_list(std::get(encodable_int_list)); + } + auto& encodable_double_list = list[18]; + if (!encodable_double_list.IsNull()) { + decoded.set_double_list(std::get(encodable_double_list)); + } + auto& encodable_bool_list = list[19]; + if (!encodable_bool_list.IsNull()) { + decoded.set_bool_list(std::get(encodable_bool_list)); + } + auto& encodable_nested_class_list = list[20]; + if (!encodable_nested_class_list.IsNull()) { + decoded.set_nested_class_list( + std::get(encodable_nested_class_list)); + } + auto& encodable_map = list[21]; + if (!encodable_map.IsNull()) { + decoded.set_map(std::get(encodable_map)); + } return decoded; } @@ -706,12 +859,14 @@ AllNullableTypesWithoutRecursion::AllNullableTypesWithoutRecursion( const std::vector* a_nullable4_byte_array, const std::vector* a_nullable8_byte_array, const std::vector* a_nullable_float_array, - const EncodableList* a_nullable_list, const EncodableMap* a_nullable_map, const EncodableList* nullable_nested_list, const EncodableMap* nullable_map_with_annotations, const EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, const std::string* a_nullable_string, - const EncodableValue* a_nullable_object) + const EncodableValue* a_nullable_object, const EncodableList* list, + const EncodableList* string_list, const EncodableList* int_list, + const EncodableList* double_list, const EncodableList* bool_list, + const EncodableMap* map) : a_nullable_bool_(a_nullable_bool ? std::optional(*a_nullable_bool) : std::nullopt), a_nullable_int_(a_nullable_int ? std::optional(*a_nullable_int) @@ -738,12 +893,6 @@ AllNullableTypesWithoutRecursion::AllNullableTypesWithoutRecursion( a_nullable_float_array ? std::optional>(*a_nullable_float_array) : std::nullopt), - a_nullable_list_(a_nullable_list - ? std::optional(*a_nullable_list) - : std::nullopt), - a_nullable_map_(a_nullable_map - ? std::optional(*a_nullable_map) - : std::nullopt), nullable_nested_list_(nullable_nested_list ? std::optional( *nullable_nested_list) : std::nullopt), @@ -762,7 +911,17 @@ AllNullableTypesWithoutRecursion::AllNullableTypesWithoutRecursion( : std::nullopt), a_nullable_object_(a_nullable_object ? std::optional(*a_nullable_object) - : std::nullopt) {} + : std::nullopt), + list_(list ? std::optional(*list) : std::nullopt), + string_list_(string_list ? std::optional(*string_list) + : std::nullopt), + int_list_(int_list ? std::optional(*int_list) + : std::nullopt), + double_list_(double_list ? std::optional(*double_list) + : std::nullopt), + bool_list_(bool_list ? std::optional(*bool_list) + : std::nullopt), + map_(map ? std::optional(*map) : std::nullopt) {} const bool* AllNullableTypesWithoutRecursion::a_nullable_bool() const { return a_nullable_bool_ ? &(*a_nullable_bool_) : nullptr; @@ -886,36 +1045,6 @@ void AllNullableTypesWithoutRecursion::set_a_nullable_float_array( a_nullable_float_array_ = value_arg; } -const EncodableList* AllNullableTypesWithoutRecursion::a_nullable_list() const { - return a_nullable_list_ ? &(*a_nullable_list_) : nullptr; -} - -void AllNullableTypesWithoutRecursion::set_a_nullable_list( - const EncodableList* value_arg) { - a_nullable_list_ = - value_arg ? std::optional(*value_arg) : std::nullopt; -} - -void AllNullableTypesWithoutRecursion::set_a_nullable_list( - const EncodableList& value_arg) { - a_nullable_list_ = value_arg; -} - -const EncodableMap* AllNullableTypesWithoutRecursion::a_nullable_map() const { - return a_nullable_map_ ? &(*a_nullable_map_) : nullptr; -} - -void AllNullableTypesWithoutRecursion::set_a_nullable_map( - const EncodableMap* value_arg) { - a_nullable_map_ = - value_arg ? std::optional(*value_arg) : std::nullopt; -} - -void AllNullableTypesWithoutRecursion::set_a_nullable_map( - const EncodableMap& value_arg) { - a_nullable_map_ = value_arg; -} - const EncodableList* AllNullableTypesWithoutRecursion::nullable_nested_list() const { return nullable_nested_list_ ? &(*nullable_nested_list_) : nullptr; @@ -1011,9 +1140,95 @@ void AllNullableTypesWithoutRecursion::set_a_nullable_object( a_nullable_object_ = value_arg; } +const EncodableList* AllNullableTypesWithoutRecursion::list() const { + return list_ ? &(*list_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_list( + const EncodableList* value_arg) { + list_ = value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_list( + const EncodableList& value_arg) { + list_ = value_arg; +} + +const EncodableList* AllNullableTypesWithoutRecursion::string_list() const { + return string_list_ ? &(*string_list_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_string_list( + const EncodableList* value_arg) { + string_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_string_list( + const EncodableList& value_arg) { + string_list_ = value_arg; +} + +const EncodableList* AllNullableTypesWithoutRecursion::int_list() const { + return int_list_ ? &(*int_list_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_int_list( + const EncodableList* value_arg) { + int_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_int_list( + const EncodableList& value_arg) { + int_list_ = value_arg; +} + +const EncodableList* AllNullableTypesWithoutRecursion::double_list() const { + return double_list_ ? &(*double_list_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_double_list( + const EncodableList* value_arg) { + double_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_double_list( + const EncodableList& value_arg) { + double_list_ = value_arg; +} + +const EncodableList* AllNullableTypesWithoutRecursion::bool_list() const { + return bool_list_ ? &(*bool_list_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_bool_list( + const EncodableList* value_arg) { + bool_list_ = + value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_bool_list( + const EncodableList& value_arg) { + bool_list_ = value_arg; +} + +const EncodableMap* AllNullableTypesWithoutRecursion::map() const { + return map_ ? &(*map_) : nullptr; +} + +void AllNullableTypesWithoutRecursion::set_map(const EncodableMap* value_arg) { + map_ = value_arg ? std::optional(*value_arg) : std::nullopt; +} + +void AllNullableTypesWithoutRecursion::set_map(const EncodableMap& value_arg) { + map_ = value_arg; +} + EncodableList AllNullableTypesWithoutRecursion::ToEncodableList() const { EncodableList list; - list.reserve(16); + list.reserve(20); list.push_back(a_nullable_bool_ ? EncodableValue(*a_nullable_bool_) : EncodableValue()); list.push_back(a_nullable_int_ ? EncodableValue(*a_nullable_int_) @@ -1034,10 +1249,6 @@ EncodableList AllNullableTypesWithoutRecursion::ToEncodableList() const { list.push_back(a_nullable_float_array_ ? EncodableValue(*a_nullable_float_array_) : EncodableValue()); - list.push_back(a_nullable_list_ ? EncodableValue(*a_nullable_list_) - : EncodableValue()); - list.push_back(a_nullable_map_ ? EncodableValue(*a_nullable_map_) - : EncodableValue()); list.push_back(nullable_nested_list_ ? EncodableValue(*nullable_nested_list_) : EncodableValue()); list.push_back(nullable_map_with_annotations_ @@ -1046,11 +1257,19 @@ EncodableList AllNullableTypesWithoutRecursion::ToEncodableList() const { list.push_back(nullable_map_with_object_ ? EncodableValue(*nullable_map_with_object_) : EncodableValue()); - list.push_back(a_nullable_enum_ ? EncodableValue((int)(*a_nullable_enum_)) + list.push_back(a_nullable_enum_ ? CustomEncodableValue(*a_nullable_enum_) : EncodableValue()); list.push_back(a_nullable_string_ ? EncodableValue(*a_nullable_string_) : EncodableValue()); list.push_back(a_nullable_object_ ? *a_nullable_object_ : EncodableValue()); + list.push_back(list_ ? EncodableValue(*list_) : EncodableValue()); + list.push_back(string_list_ ? EncodableValue(*string_list_) + : EncodableValue()); + list.push_back(int_list_ ? EncodableValue(*int_list_) : EncodableValue()); + list.push_back(double_list_ ? EncodableValue(*double_list_) + : EncodableValue()); + list.push_back(bool_list_ ? EncodableValue(*bool_list_) : EncodableValue()); + list.push_back(map_ ? EncodableValue(*map_) : EncodableValue()); return list; } @@ -1094,45 +1313,59 @@ AllNullableTypesWithoutRecursion::FromEncodableList(const EncodableList& list) { decoded.set_a_nullable_float_array( std::get>(encodable_a_nullable_float_array)); } - auto& encodable_a_nullable_list = list[8]; - if (!encodable_a_nullable_list.IsNull()) { - decoded.set_a_nullable_list( - std::get(encodable_a_nullable_list)); - } - auto& encodable_a_nullable_map = list[9]; - if (!encodable_a_nullable_map.IsNull()) { - decoded.set_a_nullable_map( - std::get(encodable_a_nullable_map)); - } - auto& encodable_nullable_nested_list = list[10]; + auto& encodable_nullable_nested_list = list[8]; if (!encodable_nullable_nested_list.IsNull()) { decoded.set_nullable_nested_list( std::get(encodable_nullable_nested_list)); } - auto& encodable_nullable_map_with_annotations = list[11]; + auto& encodable_nullable_map_with_annotations = list[9]; if (!encodable_nullable_map_with_annotations.IsNull()) { decoded.set_nullable_map_with_annotations( std::get(encodable_nullable_map_with_annotations)); } - auto& encodable_nullable_map_with_object = list[12]; + auto& encodable_nullable_map_with_object = list[10]; if (!encodable_nullable_map_with_object.IsNull()) { decoded.set_nullable_map_with_object( std::get(encodable_nullable_map_with_object)); } - auto& encodable_a_nullable_enum = list[13]; + auto& encodable_a_nullable_enum = list[11]; if (!encodable_a_nullable_enum.IsNull()) { - decoded.set_a_nullable_enum( - (AnEnum)(std::get(encodable_a_nullable_enum))); + decoded.set_a_nullable_enum(std::any_cast( + std::get(encodable_a_nullable_enum))); } - auto& encodable_a_nullable_string = list[14]; + auto& encodable_a_nullable_string = list[12]; if (!encodable_a_nullable_string.IsNull()) { decoded.set_a_nullable_string( std::get(encodable_a_nullable_string)); } - auto& encodable_a_nullable_object = list[15]; + auto& encodable_a_nullable_object = list[13]; if (!encodable_a_nullable_object.IsNull()) { decoded.set_a_nullable_object(encodable_a_nullable_object); } + auto& encodable_list = list[14]; + if (!encodable_list.IsNull()) { + decoded.set_list(std::get(encodable_list)); + } + auto& encodable_string_list = list[15]; + if (!encodable_string_list.IsNull()) { + decoded.set_string_list(std::get(encodable_string_list)); + } + auto& encodable_int_list = list[16]; + if (!encodable_int_list.IsNull()) { + decoded.set_int_list(std::get(encodable_int_list)); + } + auto& encodable_double_list = list[17]; + if (!encodable_double_list.IsNull()) { + decoded.set_double_list(std::get(encodable_double_list)); + } + auto& encodable_bool_list = list[18]; + if (!encodable_bool_list.IsNull()) { + decoded.set_bool_list(std::get(encodable_bool_list)); + } + auto& encodable_map = list[19]; + if (!encodable_map.IsNull()) { + decoded.set_map(std::get(encodable_map)); + } return decoded; } @@ -1290,46 +1523,53 @@ TestMessage TestMessage::FromEncodableList(const EncodableList& list) { return decoded; } -HostIntegrationCoreApiCodecSerializer::HostIntegrationCoreApiCodecSerializer() { -} +PigeonCodecSerializer::PigeonCodecSerializer() {} -EncodableValue HostIntegrationCoreApiCodecSerializer::ReadValueOfType( +EncodableValue PigeonCodecSerializer::ReadValueOfType( uint8_t type, flutter::ByteStreamReader* stream) const { switch (type) { - case 128: - return CustomEncodableValue(AllClassesWrapper::FromEncodableList( - std::get(ReadValue(stream)))); case 129: - return CustomEncodableValue(AllNullableTypes::FromEncodableList( + return CustomEncodableValue(AllTypes::FromEncodableList( std::get(ReadValue(stream)))); case 130: + return CustomEncodableValue(AllNullableTypes::FromEncodableList( + std::get(ReadValue(stream)))); + case 131: return CustomEncodableValue( AllNullableTypesWithoutRecursion::FromEncodableList( std::get(ReadValue(stream)))); - case 131: - return CustomEncodableValue(AllTypes::FromEncodableList( - std::get(ReadValue(stream)))); case 132: + return CustomEncodableValue(AllClassesWrapper::FromEncodableList( + std::get(ReadValue(stream)))); + case 133: return CustomEncodableValue(TestMessage::FromEncodableList( std::get(ReadValue(stream)))); + case 134: { + const auto& encodable_enum_arg = ReadValue(stream); + const int64_t enum_arg_value = + encodable_enum_arg.IsNull() ? 0 : encodable_enum_arg.LongValue(); + return encodable_enum_arg.IsNull() + ? EncodableValue() + : CustomEncodableValue(static_cast(enum_arg_value)); + } default: return flutter::StandardCodecSerializer::ReadValueOfType(type, stream); } } -void HostIntegrationCoreApiCodecSerializer::WriteValue( +void PigeonCodecSerializer::WriteValue( const EncodableValue& value, flutter::ByteStreamWriter* stream) const { if (const CustomEncodableValue* custom_value = std::get_if(&value)) { - if (custom_value->type() == typeid(AllClassesWrapper)) { - stream->WriteByte(128); - WriteValue(EncodableValue(std::any_cast(*custom_value) - .ToEncodableList()), + if (custom_value->type() == typeid(AllTypes)) { + stream->WriteByte(129); + WriteValue(EncodableValue( + std::any_cast(*custom_value).ToEncodableList()), stream); return; } if (custom_value->type() == typeid(AllNullableTypes)) { - stream->WriteByte(129); + stream->WriteByte(130); WriteValue( EncodableValue( std::any_cast(*custom_value).ToEncodableList()), @@ -1337,28 +1577,35 @@ void HostIntegrationCoreApiCodecSerializer::WriteValue( return; } if (custom_value->type() == typeid(AllNullableTypesWithoutRecursion)) { - stream->WriteByte(130); + stream->WriteByte(131); WriteValue(EncodableValue(std::any_cast( *custom_value) .ToEncodableList()), stream); return; } - if (custom_value->type() == typeid(AllTypes)) { - stream->WriteByte(131); - WriteValue(EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), + if (custom_value->type() == typeid(AllClassesWrapper)) { + stream->WriteByte(132); + WriteValue(EncodableValue(std::any_cast(*custom_value) + .ToEncodableList()), stream); return; } if (custom_value->type() == typeid(TestMessage)) { - stream->WriteByte(132); + stream->WriteByte(133); WriteValue( EncodableValue( std::any_cast(*custom_value).ToEncodableList()), stream); return; } + if (custom_value->type() == typeid(AnEnum)) { + stream->WriteByte(134); + WriteValue(EncodableValue( + static_cast(std::any_cast(*custom_value))), + stream); + return; + } } flutter::StandardCodecSerializer::WriteValue(value, stream); } @@ -1366,7 +1613,7 @@ void HostIntegrationCoreApiCodecSerializer::WriteValue( /// The codec used by HostIntegrationCoreApi. const flutter::StandardMessageCodec& HostIntegrationCoreApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &HostIntegrationCoreApiCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } // Sets up an instance of `HostIntegrationCoreApi` to handle messages through @@ -1872,8 +2119,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, reply(WrapError("an_enum_arg unexpectedly null.")); return; } - const AnEnum& an_enum_arg = - (AnEnum)encodable_an_enum_arg.LongValue(); + const auto& an_enum_arg = std::any_cast( + std::get(encodable_an_enum_arg)); ErrorOr output = api->EchoEnum(an_enum_arg); if (output.has_error()) { reply(WrapError(output.error())); @@ -1881,7 +2128,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } EncodableList wrapped; wrapped.push_back( - EncodableValue((int)std::move(output).TakeValue())); + CustomEncodableValue(std::move(output).TakeValue())); reply(EncodableValue(std::move(wrapped))); } catch (const std::exception& exception) { reply(WrapError(exception.what())); @@ -2578,15 +2825,13 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, try { const auto& args = std::get(message); const auto& encodable_an_enum_arg = args.at(0); - const int64_t an_enum_arg_value = - encodable_an_enum_arg.IsNull() - ? 0 - : encodable_an_enum_arg.LongValue(); - const auto an_enum_arg = - encodable_an_enum_arg.IsNull() - ? std::nullopt - : std::make_optional( - static_cast(an_enum_arg_value)); + AnEnum an_enum_arg_value; + const AnEnum* an_enum_arg = nullptr; + if (!encodable_an_enum_arg.IsNull()) { + an_enum_arg_value = std::any_cast( + std::get(encodable_an_enum_arg)); + an_enum_arg = &an_enum_arg_value; + } ErrorOr> output = api->EchoNullableEnum( an_enum_arg ? &(*an_enum_arg) : nullptr); if (output.has_error()) { @@ -2597,7 +2842,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, auto output_optional = std::move(output).TakeValue(); if (output_optional) { wrapped.push_back( - EncodableValue((int)std::move(output_optional).value())); + CustomEncodableValue(std::move(output_optional).value())); } else { wrapped.push_back(EncodableValue()); } @@ -3039,8 +3284,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, reply(WrapError("an_enum_arg unexpectedly null.")); return; } - const AnEnum& an_enum_arg = - (AnEnum)encodable_an_enum_arg.LongValue(); + const auto& an_enum_arg = std::any_cast( + std::get(encodable_an_enum_arg)); api->EchoAsyncEnum( an_enum_arg, [reply](ErrorOr&& output) { if (output.has_error()) { @@ -3049,7 +3294,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } EncodableList wrapped; wrapped.push_back( - EncodableValue((int)std::move(output).TakeValue())); + CustomEncodableValue(std::move(output).TakeValue())); reply(EncodableValue(std::move(wrapped))); }); } catch (const std::exception& exception) { @@ -3631,15 +3876,13 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, try { const auto& args = std::get(message); const auto& encodable_an_enum_arg = args.at(0); - const int64_t an_enum_arg_value = - encodable_an_enum_arg.IsNull() - ? 0 - : encodable_an_enum_arg.LongValue(); - const auto an_enum_arg = - encodable_an_enum_arg.IsNull() - ? std::nullopt - : std::make_optional( - static_cast(an_enum_arg_value)); + AnEnum an_enum_arg_value; + const AnEnum* an_enum_arg = nullptr; + if (!encodable_an_enum_arg.IsNull()) { + an_enum_arg_value = std::any_cast( + std::get(encodable_an_enum_arg)); + an_enum_arg = &an_enum_arg_value; + } api->EchoAsyncNullableEnum( an_enum_arg ? &(*an_enum_arg) : nullptr, [reply](ErrorOr>&& output) { @@ -3650,8 +3893,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, EncodableList wrapped; auto output_optional = std::move(output).TakeValue(); if (output_optional) { - wrapped.push_back(EncodableValue( - (int)std::move(output_optional).value())); + wrapped.push_back(CustomEncodableValue( + std::move(output_optional).value())); } else { wrapped.push_back(EncodableValue()); } @@ -4269,8 +4512,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, reply(WrapError("an_enum_arg unexpectedly null.")); return; } - const AnEnum& an_enum_arg = - (AnEnum)encodable_an_enum_arg.LongValue(); + const auto& an_enum_arg = std::any_cast( + std::get(encodable_an_enum_arg)); api->CallFlutterEchoEnum( an_enum_arg, [reply](ErrorOr&& output) { if (output.has_error()) { @@ -4279,7 +4522,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, } EncodableList wrapped; wrapped.push_back( - EncodableValue((int)std::move(output).TakeValue())); + CustomEncodableValue(std::move(output).TakeValue())); reply(EncodableValue(std::move(wrapped))); }); } catch (const std::exception& exception) { @@ -4594,15 +4837,13 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, try { const auto& args = std::get(message); const auto& encodable_an_enum_arg = args.at(0); - const int64_t an_enum_arg_value = - encodable_an_enum_arg.IsNull() - ? 0 - : encodable_an_enum_arg.LongValue(); - const auto an_enum_arg = - encodable_an_enum_arg.IsNull() - ? std::nullopt - : std::make_optional( - static_cast(an_enum_arg_value)); + AnEnum an_enum_arg_value; + const AnEnum* an_enum_arg = nullptr; + if (!encodable_an_enum_arg.IsNull()) { + an_enum_arg_value = std::any_cast( + std::get(encodable_an_enum_arg)); + an_enum_arg = &an_enum_arg_value; + } api->CallFlutterEchoNullableEnum( an_enum_arg ? &(*an_enum_arg) : nullptr, [reply](ErrorOr>&& output) { @@ -4613,8 +4854,8 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, EncodableList wrapped; auto output_optional = std::move(output).TakeValue(); if (output_optional) { - wrapped.push_back(EncodableValue( - (int)std::move(output_optional).value())); + wrapped.push_back(CustomEncodableValue( + std::move(output_optional).value())); } else { wrapped.push_back(EncodableValue()); } @@ -4682,79 +4923,6 @@ EncodableValue HostIntegrationCoreApi::WrapError(const FlutterError& error) { error.details()}); } -FlutterIntegrationCoreApiCodecSerializer:: - FlutterIntegrationCoreApiCodecSerializer() {} - -EncodableValue FlutterIntegrationCoreApiCodecSerializer::ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const { - switch (type) { - case 128: - return CustomEncodableValue(AllClassesWrapper::FromEncodableList( - std::get(ReadValue(stream)))); - case 129: - return CustomEncodableValue(AllNullableTypes::FromEncodableList( - std::get(ReadValue(stream)))); - case 130: - return CustomEncodableValue( - AllNullableTypesWithoutRecursion::FromEncodableList( - std::get(ReadValue(stream)))); - case 131: - return CustomEncodableValue(AllTypes::FromEncodableList( - std::get(ReadValue(stream)))); - case 132: - return CustomEncodableValue(TestMessage::FromEncodableList( - std::get(ReadValue(stream)))); - default: - return flutter::StandardCodecSerializer::ReadValueOfType(type, stream); - } -} - -void FlutterIntegrationCoreApiCodecSerializer::WriteValue( - const EncodableValue& value, flutter::ByteStreamWriter* stream) const { - if (const CustomEncodableValue* custom_value = - std::get_if(&value)) { - if (custom_value->type() == typeid(AllClassesWrapper)) { - stream->WriteByte(128); - WriteValue(EncodableValue(std::any_cast(*custom_value) - .ToEncodableList()), - stream); - return; - } - if (custom_value->type() == typeid(AllNullableTypes)) { - stream->WriteByte(129); - WriteValue( - EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); - return; - } - if (custom_value->type() == typeid(AllNullableTypesWithoutRecursion)) { - stream->WriteByte(130); - WriteValue(EncodableValue(std::any_cast( - *custom_value) - .ToEncodableList()), - stream); - return; - } - if (custom_value->type() == typeid(AllTypes)) { - stream->WriteByte(131); - WriteValue(EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); - return; - } - if (custom_value->type() == typeid(TestMessage)) { - stream->WriteByte(132); - WriteValue( - EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); - return; - } - } - flutter::StandardCodecSerializer::WriteValue(value, stream); -} - // Generated class from Pigeon that represents Flutter messages that can be // called from C++. FlutterIntegrationCoreApi::FlutterIntegrationCoreApi( @@ -4771,7 +4939,7 @@ FlutterIntegrationCoreApi::FlutterIntegrationCoreApi( const flutter::StandardMessageCodec& FlutterIntegrationCoreApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &FlutterIntegrationCoreApiCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } void FlutterIntegrationCoreApi::Noop( @@ -5347,7 +5515,7 @@ void FlutterIntegrationCoreApi::EchoEnum( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - EncodableValue((int)an_enum_arg), + CustomEncodableValue(an_enum_arg), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5365,8 +5533,8 @@ void FlutterIntegrationCoreApi::EchoEnum( std::get(list_return_value->at(1)), list_return_value->at(2))); } else { - const AnEnum& return_value = - (AnEnum)list_return_value->at(0).LongValue(); + const auto& return_value = std::any_cast( + std::get(list_return_value->at(0))); on_success(return_value); } } else { @@ -5650,37 +5818,37 @@ void FlutterIntegrationCoreApi::EchoNullableEnum( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - an_enum_arg ? EncodableValue((int)(*an_enum_arg)) : EncodableValue(), - }); - channel.Send(encoded_api_arguments, [channel_name, - on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const int64_t return_value_value = - list_return_value->at(0).IsNull() - ? 0 - : list_return_value->at(0).LongValue(); - const AnEnum enum_return_value = (AnEnum)return_value_value; - const auto* return_value = - list_return_value->at(0).IsNull() ? nullptr : &enum_return_value; - on_success(return_value); - } - } else { - on_error(CreateConnectionError(channel_name)); - } + an_enum_arg ? CustomEncodableValue(*an_enum_arg) : EncodableValue(), }); + channel.Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + AnEnum return_value_value; + const AnEnum* return_value = nullptr; + if (!list_return_value->at(0).IsNull()) { + return_value_value = std::any_cast( + std::get(list_return_value->at(0))); + return_value = &return_value_value; + } + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::NoopAsync( @@ -5757,7 +5925,7 @@ void FlutterIntegrationCoreApi::EchoAsyncString( /// The codec used by HostTrivialApi. const flutter::StandardMessageCodec& HostTrivialApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &flutter::StandardCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } // Sets up an instance of `HostTrivialApi` to handle messages through the @@ -5818,7 +5986,7 @@ EncodableValue HostTrivialApi::WrapError(const FlutterError& error) { /// The codec used by HostSmallApi. const flutter::StandardMessageCodec& HostSmallApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &flutter::StandardCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } // Sets up an instance of `HostSmallApi` to handle messages through the @@ -5914,35 +6082,6 @@ EncodableValue HostSmallApi::WrapError(const FlutterError& error) { error.details()}); } -FlutterSmallApiCodecSerializer::FlutterSmallApiCodecSerializer() {} - -EncodableValue FlutterSmallApiCodecSerializer::ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const { - switch (type) { - case 128: - return CustomEncodableValue(TestMessage::FromEncodableList( - std::get(ReadValue(stream)))); - default: - return flutter::StandardCodecSerializer::ReadValueOfType(type, stream); - } -} - -void FlutterSmallApiCodecSerializer::WriteValue( - const EncodableValue& value, flutter::ByteStreamWriter* stream) const { - if (const CustomEncodableValue* custom_value = - std::get_if(&value)) { - if (custom_value->type() == typeid(TestMessage)) { - stream->WriteByte(128); - WriteValue( - EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); - return; - } - } - flutter::StandardCodecSerializer::WriteValue(value, stream); -} - // Generated class from Pigeon that represents Flutter messages that can be // called from C++. FlutterSmallApi::FlutterSmallApi(flutter::BinaryMessenger* binary_messenger) @@ -5957,7 +6096,7 @@ FlutterSmallApi::FlutterSmallApi(flutter::BinaryMessenger* binary_messenger, const flutter::StandardMessageCodec& FlutterSmallApi::GetCodec() { return flutter::StandardMessageCodec::GetInstance( - &FlutterSmallApiCodecSerializer::GetInstance()); + &PigeonCodecSerializer::GetInstance()); } void FlutterSmallApi::EchoWrappedList( 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 7ee94453826..ceed1b08727 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 @@ -84,10 +84,14 @@ class AllTypes { const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, + const AnEnum& an_enum, const std::string& a_string, + const flutter::EncodableValue& an_object, const flutter::EncodableList& list, - const flutter::EncodableMap& a_map, const AnEnum& an_enum, - const std::string& a_string, - const flutter::EncodableValue& an_object); + const flutter::EncodableList& string_list, + const flutter::EncodableList& int_list, + const flutter::EncodableList& double_list, + const flutter::EncodableList& bool_list, + const flutter::EncodableMap& map); bool a_bool() const; void set_a_bool(bool value_arg); @@ -113,12 +117,6 @@ class AllTypes { const std::vector& a_float_array() const; void set_a_float_array(const std::vector& value_arg); - const flutter::EncodableList& list() const; - void set_list(const flutter::EncodableList& value_arg); - - const flutter::EncodableMap& a_map() const; - void set_a_map(const flutter::EncodableMap& value_arg); - const AnEnum& an_enum() const; void set_an_enum(const AnEnum& value_arg); @@ -128,20 +126,34 @@ class AllTypes { const flutter::EncodableValue& an_object() const; void set_an_object(const flutter::EncodableValue& value_arg); + const flutter::EncodableList& list() const; + void set_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList& string_list() const; + void set_string_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList& int_list() const; + void set_int_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList& double_list() const; + void set_double_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList& bool_list() const; + void set_bool_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableMap& map() const; + void set_map(const flutter::EncodableMap& value_arg); + private: static AllTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class AllClassesWrapper; friend class HostIntegrationCoreApi; - friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; - friend class FlutterIntegrationCoreApiCodecSerializer; friend class HostTrivialApi; - friend class HostTrivialApiCodecSerializer; friend class HostSmallApi; - friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; - friend class FlutterSmallApiCodecSerializer; + friend class PigeonCodecSerializer; friend class CoreTestsTest; bool a_bool_; int64_t an_int_; @@ -151,11 +163,15 @@ class AllTypes { std::vector a4_byte_array_; std::vector a8_byte_array_; std::vector a_float_array_; - flutter::EncodableList list_; - flutter::EncodableMap a_map_; AnEnum an_enum_; std::string a_string_; flutter::EncodableValue an_object_; + flutter::EncodableList list_; + flutter::EncodableList string_list_; + flutter::EncodableList int_list_; + flutter::EncodableList double_list_; + flutter::EncodableList bool_list_; + flutter::EncodableMap map_; }; // A class containing all supported nullable types. @@ -174,14 +190,19 @@ class AllNullableTypes { const std::vector* a_nullable4_byte_array, const std::vector* a_nullable8_byte_array, const std::vector* a_nullable_float_array, - const flutter::EncodableList* a_nullable_list, - const flutter::EncodableMap* a_nullable_map, const flutter::EncodableList* nullable_nested_list, const flutter::EncodableMap* nullable_map_with_annotations, const flutter::EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, const std::string* a_nullable_string, const flutter::EncodableValue* a_nullable_object, - const AllNullableTypes* all_nullable_types); + const AllNullableTypes* all_nullable_types, + const flutter::EncodableList* list, + const flutter::EncodableList* string_list, + const flutter::EncodableList* int_list, + const flutter::EncodableList* double_list, + const flutter::EncodableList* bool_list, + const flutter::EncodableList* nested_class_list, + const flutter::EncodableMap* map); ~AllNullableTypes() = default; AllNullableTypes(const AllNullableTypes& other); @@ -220,14 +241,6 @@ class AllNullableTypes { void set_a_nullable_float_array(const std::vector* value_arg); void set_a_nullable_float_array(const std::vector& value_arg); - const flutter::EncodableList* a_nullable_list() const; - void set_a_nullable_list(const flutter::EncodableList* value_arg); - void set_a_nullable_list(const flutter::EncodableList& value_arg); - - const flutter::EncodableMap* a_nullable_map() const; - void set_a_nullable_map(const flutter::EncodableMap* value_arg); - void set_a_nullable_map(const flutter::EncodableMap& value_arg); - const flutter::EncodableList* nullable_nested_list() const; void set_nullable_nested_list(const flutter::EncodableList* value_arg); void set_nullable_nested_list(const flutter::EncodableList& value_arg); @@ -258,20 +271,44 @@ class AllNullableTypes { void set_all_nullable_types(const AllNullableTypes* value_arg); void set_all_nullable_types(const AllNullableTypes& value_arg); + const flutter::EncodableList* list() const; + void set_list(const flutter::EncodableList* value_arg); + void set_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* string_list() const; + void set_string_list(const flutter::EncodableList* value_arg); + void set_string_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* int_list() const; + void set_int_list(const flutter::EncodableList* value_arg); + void set_int_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* double_list() const; + void set_double_list(const flutter::EncodableList* value_arg); + void set_double_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* bool_list() const; + void set_bool_list(const flutter::EncodableList* value_arg); + void set_bool_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* nested_class_list() const; + void set_nested_class_list(const flutter::EncodableList* value_arg); + void set_nested_class_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableMap* map() const; + void set_map(const flutter::EncodableMap* value_arg); + void set_map(const flutter::EncodableMap& value_arg); + private: static AllNullableTypes FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class AllClassesWrapper; friend class HostIntegrationCoreApi; - friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; - friend class FlutterIntegrationCoreApiCodecSerializer; friend class HostTrivialApi; - friend class HostTrivialApiCodecSerializer; friend class HostSmallApi; - friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; - friend class FlutterSmallApiCodecSerializer; + friend class PigeonCodecSerializer; friend class CoreTestsTest; std::optional a_nullable_bool_; std::optional a_nullable_int_; @@ -281,8 +318,6 @@ class AllNullableTypes { std::optional> a_nullable4_byte_array_; std::optional> a_nullable8_byte_array_; std::optional> a_nullable_float_array_; - std::optional a_nullable_list_; - std::optional a_nullable_map_; std::optional nullable_nested_list_; std::optional nullable_map_with_annotations_; std::optional nullable_map_with_object_; @@ -290,6 +325,13 @@ class AllNullableTypes { std::optional a_nullable_string_; std::optional a_nullable_object_; std::unique_ptr all_nullable_types_; + std::optional list_; + std::optional string_list_; + std::optional int_list_; + std::optional double_list_; + std::optional bool_list_; + std::optional nested_class_list_; + std::optional map_; }; // The primary purpose for this class is to ensure coverage of Swift structs @@ -310,13 +352,17 @@ class AllNullableTypesWithoutRecursion { const std::vector* a_nullable4_byte_array, const std::vector* a_nullable8_byte_array, const std::vector* a_nullable_float_array, - const flutter::EncodableList* a_nullable_list, - const flutter::EncodableMap* a_nullable_map, const flutter::EncodableList* nullable_nested_list, const flutter::EncodableMap* nullable_map_with_annotations, const flutter::EncodableMap* nullable_map_with_object, const AnEnum* a_nullable_enum, const std::string* a_nullable_string, - const flutter::EncodableValue* a_nullable_object); + const flutter::EncodableValue* a_nullable_object, + const flutter::EncodableList* list, + const flutter::EncodableList* string_list, + const flutter::EncodableList* int_list, + const flutter::EncodableList* double_list, + const flutter::EncodableList* bool_list, + const flutter::EncodableMap* map); const bool* a_nullable_bool() const; void set_a_nullable_bool(const bool* value_arg); @@ -350,14 +396,6 @@ class AllNullableTypesWithoutRecursion { void set_a_nullable_float_array(const std::vector* value_arg); void set_a_nullable_float_array(const std::vector& value_arg); - const flutter::EncodableList* a_nullable_list() const; - void set_a_nullable_list(const flutter::EncodableList* value_arg); - void set_a_nullable_list(const flutter::EncodableList& value_arg); - - const flutter::EncodableMap* a_nullable_map() const; - void set_a_nullable_map(const flutter::EncodableMap* value_arg); - void set_a_nullable_map(const flutter::EncodableMap& value_arg); - const flutter::EncodableList* nullable_nested_list() const; void set_nullable_nested_list(const flutter::EncodableList* value_arg); void set_nullable_nested_list(const flutter::EncodableList& value_arg); @@ -384,21 +422,41 @@ class AllNullableTypesWithoutRecursion { void set_a_nullable_object(const flutter::EncodableValue* value_arg); void set_a_nullable_object(const flutter::EncodableValue& value_arg); + const flutter::EncodableList* list() const; + void set_list(const flutter::EncodableList* value_arg); + void set_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* string_list() const; + void set_string_list(const flutter::EncodableList* value_arg); + void set_string_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* int_list() const; + void set_int_list(const flutter::EncodableList* value_arg); + void set_int_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* double_list() const; + void set_double_list(const flutter::EncodableList* value_arg); + void set_double_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableList* bool_list() const; + void set_bool_list(const flutter::EncodableList* value_arg); + void set_bool_list(const flutter::EncodableList& value_arg); + + const flutter::EncodableMap* map() const; + void set_map(const flutter::EncodableMap* value_arg); + void set_map(const flutter::EncodableMap& value_arg); + private: static AllNullableTypesWithoutRecursion FromEncodableList( const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class AllClassesWrapper; friend class HostIntegrationCoreApi; - friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; - friend class FlutterIntegrationCoreApiCodecSerializer; friend class HostTrivialApi; - friend class HostTrivialApiCodecSerializer; friend class HostSmallApi; - friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; - friend class FlutterSmallApiCodecSerializer; + friend class PigeonCodecSerializer; friend class CoreTestsTest; std::optional a_nullable_bool_; std::optional a_nullable_int_; @@ -408,14 +466,18 @@ class AllNullableTypesWithoutRecursion { std::optional> a_nullable4_byte_array_; std::optional> a_nullable8_byte_array_; std::optional> a_nullable_float_array_; - std::optional a_nullable_list_; - std::optional a_nullable_map_; std::optional nullable_nested_list_; std::optional nullable_map_with_annotations_; std::optional nullable_map_with_object_; std::optional a_nullable_enum_; std::optional a_nullable_string_; std::optional a_nullable_object_; + std::optional list_; + std::optional string_list_; + std::optional int_list_; + std::optional double_list_; + std::optional bool_list_; + std::optional map_; }; // A class for testing nested class handling. @@ -460,15 +522,11 @@ class AllClassesWrapper { const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class HostIntegrationCoreApi; - friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; - friend class FlutterIntegrationCoreApiCodecSerializer; friend class HostTrivialApi; - friend class HostTrivialApiCodecSerializer; friend class HostSmallApi; - friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; - friend class FlutterSmallApiCodecSerializer; + friend class PigeonCodecSerializer; friend class CoreTestsTest; std::unique_ptr all_nullable_types_; std::unique_ptr @@ -495,25 +553,20 @@ class TestMessage { static TestMessage FromEncodableList(const flutter::EncodableList& list); flutter::EncodableList ToEncodableList() const; friend class HostIntegrationCoreApi; - friend class HostIntegrationCoreApiCodecSerializer; friend class FlutterIntegrationCoreApi; - friend class FlutterIntegrationCoreApiCodecSerializer; friend class HostTrivialApi; - friend class HostTrivialApiCodecSerializer; friend class HostSmallApi; - friend class HostSmallApiCodecSerializer; friend class FlutterSmallApi; - friend class FlutterSmallApiCodecSerializer; + friend class PigeonCodecSerializer; friend class CoreTestsTest; std::optional test_list_; }; -class HostIntegrationCoreApiCodecSerializer - : public flutter::StandardCodecSerializer { +class PigeonCodecSerializer : public flutter::StandardCodecSerializer { public: - HostIntegrationCoreApiCodecSerializer(); - inline static HostIntegrationCoreApiCodecSerializer& GetInstance() { - static HostIntegrationCoreApiCodecSerializer sInstance; + PigeonCodecSerializer(); + inline static PigeonCodecSerializer& GetInstance() { + static PigeonCodecSerializer sInstance; return sInstance; } @@ -842,23 +895,6 @@ class HostIntegrationCoreApi { protected: HostIntegrationCoreApi() = default; }; -class FlutterIntegrationCoreApiCodecSerializer - : public flutter::StandardCodecSerializer { - public: - FlutterIntegrationCoreApiCodecSerializer(); - inline static FlutterIntegrationCoreApiCodecSerializer& GetInstance() { - static FlutterIntegrationCoreApiCodecSerializer sInstance; - return sInstance; - } - - void WriteValue(const flutter::EncodableValue& value, - flutter::ByteStreamWriter* stream) const override; - - protected: - flutter::EncodableValue ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const override; -}; - // The core interface that the Dart platform_test code implements for host // integration tests to call into. // @@ -1045,22 +1081,6 @@ class HostSmallApi { protected: HostSmallApi() = default; }; -class FlutterSmallApiCodecSerializer : public flutter::StandardCodecSerializer { - public: - FlutterSmallApiCodecSerializer(); - inline static FlutterSmallApiCodecSerializer& GetInstance() { - static FlutterSmallApiCodecSerializer sInstance; - return sInstance; - } - - void WriteValue(const flutter::EncodableValue& value, - flutter::ByteStreamWriter* stream) const override; - - protected: - flutter::EncodableValue ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const override; -}; - // A simple API called in some unit tests. // // Generated class from Pigeon that represents Flutter messages that can be diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp index d0c04561882..e6a366248f0 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp @@ -119,13 +119,9 @@ TEST_F(NullFieldsTest, ReplyFromListWithValues) { EncodableList list{ EncodableValue("result"), EncodableValue("error"), - EncodableValue(EncodableList{ - EncodableValue(1), - EncodableValue(2), - EncodableValue(3), - }), + EncodableValue(EncodableList({1, 2, 3})), CustomEncodableValue(request), - EncodableValue(0), + CustomEncodableValue(NullFieldsSearchReplyType::success), }; NullFieldsSearchReply reply = ReplyFromList(list); diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/pigeon_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/pigeon_test.cpp index 89118efc10d..427a62f06c6 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/pigeon_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/pigeon_test.cpp @@ -137,7 +137,7 @@ TEST(PigeonTests, CallSearch) { Writer writer; flutter::EncodableList args; args.push_back(flutter::CustomEncodableValue(request)); - MessageApiCodecSerializer::GetInstance().WriteValue(args, &writer); + PigeonCodecSerializer::GetInstance().WriteValue(args, &writer); handler(writer.data_.data(), writer.data_.size(), reply); EXPECT_TRUE(did_call_reply); } diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index edbba1f4027..0281b15cba3 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%3A%22p%3A+pigeon%22 -version: 19.0.2 # This must match the version in lib/generator_tools.dart +version: 20.0.0 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.2.0 diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index 8695ae45e96..ecdb0ab33d2 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1814,50 +1814,7 @@ void main() { expect(code, contains('// ///')); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const CppGenerator generator = CppGenerator(); - final OutputFileOptions generatorOptions = - OutputFileOptions( - fileType: FileType.header, - languageOptions: const CppOptions(), - ); - generator.generate( - generatorOptions, - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains(' : public flutter::StandardCodecSerializer'))); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( diff --git a/packages/pigeon/test/dart/proxy_api_test.dart b/packages/pigeon/test/dart/proxy_api_test.dart index 95c4f90da75..a8b3a5a9eb0 100644 --- a/packages/pigeon/test/dart/proxy_api_test.dart +++ b/packages/pigeon/test/dart/proxy_api_test.dart @@ -517,8 +517,8 @@ void main() { contains( r'__pigeon_channel.send([ ' r'__pigeon_instanceIdentifier, ' - r'validType, enumType.index, proxyApiType, ' - r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', + r'validType, enumType, proxyApiType, ' + r'nullableValidType, nullableEnumType, nullableProxyApiType ])', ), ); }); @@ -627,8 +627,8 @@ void main() { contains( r'__pigeon_channel.send([ ' r'__pigeon_instanceIdentifier, ' - r'validType, enumType.index, proxyApiType, ' - r'nullableValidType, nullableEnumType?.index, nullableProxyApiType ])', + r'validType, enumType, proxyApiType, ' + r'nullableValidType, nullableEnumType, nullableProxyApiType ])', ), ); expect( @@ -847,8 +847,8 @@ void main() { collapsedCode, contains( r'await __pigeon_channel.send([ this, validType, ' - r'enumType.index, proxyApiType, nullableValidType, ' - r'nullableEnumType?.index, nullableProxyApiType ])', + r'enumType, proxyApiType, nullableValidType, ' + r'nullableEnumType, nullableProxyApiType ])', ), ); }); @@ -1004,10 +1004,9 @@ void main() { contains(r'final int? arg_validType = (args[1] as int?);'), ); expect( - collapsedCode, + code, contains( - r'final AnEnum? arg_enumType = args[2] == null ? ' - r'null : AnEnum.values[args[2]! as int];', + r'final AnEnum? arg_enumType = (args[2] as AnEnum?);', ), ); expect( @@ -1019,10 +1018,9 @@ void main() { contains(r'final int? arg_nullableValidType = (args[4] as int?);'), ); expect( - collapsedCode, + code, contains( - r'final AnEnum? arg_nullableEnumType = args[5] == null ? ' - r'null : AnEnum.values[args[5]! as int];', + r'final AnEnum? arg_nullableEnumType = (args[5] as AnEnum?);', ), ); expect( diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index a1470427c7f..944c6e334ce 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -532,8 +532,10 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('enum1?.index,')); - expect(code, contains('? Enum.values[result[0]! as int]')); + expect(code, contains('return value == null ? null : Enum.values[value];')); + expect(code, contains('writeValue(buffer, value.index);')); + expect(code, + contains('final EnumClass? arg_enumClass = (args[0] as EnumClass?);')); expect(code, contains('EnumClass doSomething(EnumClass enumClass);')); }); @@ -571,7 +573,7 @@ void main() { final String code = sink.toString(); expect(code, contains('enum Foo {')); expect(code, contains('Future bar(Foo? foo) async')); - expect(code, contains('__pigeon_channel.send([foo?.index])')); + expect(code, contains('__pigeon_channel.send([foo])')); }); test('flutter non-nullable enum argument with enum class', () { @@ -624,8 +626,9 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('enum1.index,')); - expect(code, contains('enum1: Enum.values[result[0]! as int]')); + expect(code, contains('writeValue(buffer, value.index)')); + expect(code, contains('return value == null ? null : Enum.values[value];')); + expect(code, contains('enum1: result[0]! as Enum,')); }); test('host void argument', () { @@ -1600,46 +1603,7 @@ name: foobar expect(code, contains('/// ///')); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const DartGenerator generator = DartGenerator(); - generator.generate( - const DartOptions(), - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains('extends StandardMessageCodec'))); - expect(code, contains('StandardMessageCodec')); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( @@ -1740,10 +1704,10 @@ name: foobar ); final String testCode = sink.toString(); - expect( - testCode, - contains( - 'final Enum? arg_anEnum = args[0] == null ? null : Enum.values[args[0]! as int]')); + expect(testCode, contains('final Enum? arg_anEnum = (args[0] as Enum?);')); + expect(testCode, + contains('return value == null ? null : Enum.values[value];')); + expect(testCode, contains('writeValue(buffer, value.index);')); }); test('connection error contains channel name', () { diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index e68bb96239c..d7c49e37154 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -44,11 +44,6 @@ final Class emptyClass = Class(name: 'className', fields: [ ) ]); -final Enum emptyEnum = Enum( - name: 'enumName', - members: [EnumMember(name: 'enumMemberName')], -); - void main() { test('test merge maps', () { final Map source = { @@ -77,144 +72,26 @@ void main() { expect(_equalMaps(expected, mergeMaps(source, modification)), isTrue); }); - test('get codec classes from argument type arguments', () { - final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ - Method( - name: 'doSomething', - location: ApiLocation.flutter, - parameters: [ - Parameter( - type: TypeDeclaration( - baseName: 'List', - isNullable: false, - typeArguments: [ - TypeDeclaration( - baseName: 'Input', - isNullable: true, - associatedClass: emptyClass, - ) - ], - ), - name: '', - ) - ], - returnType: TypeDeclaration( - baseName: 'Output', - isNullable: false, - associatedClass: emptyClass, - ), - isAsynchronous: true, - ) - ]); - final Root root = - Root(classes: [], apis: [api], enums: []); - final List classes = getCodecClasses(api, root).toList(); - expect(classes.length, 2); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Input') - .length, - 1); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Output') - .length, - 1); - }); - - test('get codec classes from return value type arguments', () { - final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ - Method( - name: 'doSomething', - location: ApiLocation.flutter, - parameters: [ - Parameter( - type: TypeDeclaration( - baseName: 'Output', - isNullable: false, - associatedClass: emptyClass, - ), - name: '', - ) - ], - returnType: TypeDeclaration( - baseName: 'List', - isNullable: false, - typeArguments: [ - TypeDeclaration( - baseName: 'Input', + test('get codec types from all classes and enums', () { + final Root root = Root(classes: [ + Class(name: 'name', fields: [ + NamedType( + name: 'name', + type: const TypeDeclaration( + baseName: 'name', isNullable: true, - associatedClass: emptyClass, - ) - ], - ), - isAsynchronous: true, - ) - ]); - final Root root = - Root(classes: [], apis: [api], enums: []); - final List classes = getCodecClasses(api, root).toList(); - expect(classes.length, 2); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Input') - .length, - 1); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Output') - .length, - 1); - }); - - test('get codec classes from all arguments', () { - final AstFlutterApi api = AstFlutterApi(name: 'Api', methods: [ - Method( - name: 'doSomething', - location: ApiLocation.flutter, - parameters: [ - Parameter( - type: TypeDeclaration( - baseName: 'Foo', - isNullable: false, - associatedClass: emptyClass, - ), - name: '', - ), - Parameter( - type: TypeDeclaration( - baseName: 'Bar', - isNullable: false, - associatedEnum: emptyEnum, - ), - name: '', - ), - ], - returnType: const TypeDeclaration( - baseName: 'List', - isNullable: false, - typeArguments: [TypeDeclaration.voidDeclaration()], - ), - isAsynchronous: true, - ) + )) + ]) + ], apis: [], enums: [ + Enum(name: 'enum', members: [ + EnumMember(name: 'enumMember'), + ]) ]); - final Root root = - Root(classes: [], apis: [api], enums: []); - final List classes = getCodecClasses(api, root).toList(); - expect(classes.length, 2); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Foo') - .length, - 1); - expect( - classes - .where((EnumeratedClass element) => element.name == 'Bar') - .length, - 1); + final List types = getEnumeratedTypes(root).toList(); + expect(types.length, 2); }); - test('getCodecClasses: nested type arguments', () { + test('getEnumeratedTypes:ed type arguments', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( @@ -256,22 +133,17 @@ void main() { )) ]) ], enums: []); - final List classes = - getCodecClasses(root.apis[0], root).toList(); + final List classes = getEnumeratedTypes(root).toList(); expect(classes.length, 2); expect( - classes - .where((EnumeratedClass element) => element.name == 'Foo') - .length, + classes.where((EnumeratedType element) => element.name == 'Foo').length, 1); expect( - classes - .where((EnumeratedClass element) => element.name == 'Bar') - .length, + classes.where((EnumeratedType element) => element.name == 'Bar').length, 1); }); - test('getCodecClasses: with Object', () { + test('getEnumeratedTypes: Object', () { final Root root = Root(apis: [ AstFlutterApi( name: 'Api1', @@ -300,17 +172,14 @@ void main() { type: const TypeDeclaration(baseName: 'int', isNullable: true)), ]), ], enums: []); - final List classes = - getCodecClasses(root.apis[0], root).toList(); + final List classes = getEnumeratedTypes(root).toList(); expect(classes.length, 1); expect( - classes - .where((EnumeratedClass element) => element.name == 'Foo') - .length, + classes.where((EnumeratedType element) => element.name == 'Foo').length, 1); }); - test('getCodecClasses: unique entries', () { + test('getEnumeratedTypes:ue entries', () { final Root root = Root(apis: [ AstFlutterApi( name: 'Api1', @@ -357,13 +226,10 @@ void main() { type: const TypeDeclaration(baseName: 'int', isNullable: true)), ]), ], enums: []); - final List classes = - getCodecClasses(root.apis[0], root).toList(); + final List classes = getEnumeratedTypes(root).toList(); expect(classes.length, 1); expect( - classes - .where((EnumeratedClass element) => element.name == 'Foo') - .length, + classes.where((EnumeratedType element) => element.name == 'Foo').length, 1); }); diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index c3bb560279d..3982c25150b 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -739,12 +739,8 @@ void main() { expect(code, contains('private Enum1(final int index) {')); expect(code, contains(' this.index = index;')); - expect(code, - contains('toListResult.add(enum1 == null ? null : enum1.index);')); - expect( - code, - contains( - 'pigeonResult.setEnum1(enum1 == null ? null : Enum1.values()[(int) enum1])')); + expect(code, contains('toListResult.add(enum1);')); + expect(code, contains('pigeonResult.setEnum1((Enum1) enum1);')); }); test('primitive enum host', () { @@ -782,10 +778,13 @@ void main() { ); final String code = sink.toString(); expect(code, contains('public enum Foo')); + expect(code, + contains('return value == null ? null : Foo.values()[(int) value];')); expect( code, contains( - 'Foo fooArg = args.get(0) == null ? null : Foo.values()[(int) args.get(0)];')); + 'writeValue(stream, value == null ? null : ((Foo) value).index);')); + expect(code, contains('Foo fooArg = (Foo) args.get(0);')); }); Iterable makeIterable(String string) sync* { @@ -1512,47 +1511,7 @@ void main() { expect(code, isNot(contains('*//'))); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const JavaOptions javaOptions = JavaOptions(className: 'Messages'); - const JavaGenerator generator = JavaGenerator(); - generator.generate( - javaOptions, - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains(' extends StandardMessageCodec'))); - expect(code, contains('StandardMessageCodec')); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 40c1e75c3aa..ea87f508ca1 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -133,8 +133,8 @@ void main() { expect(code, contains('val field1: Foo,')); expect(code, contains('val field2: String')); expect(code, contains('fun fromList(__pigeon_list: List): Bar')); - expect( - code, contains('val field1 = Foo.ofRaw(__pigeon_list[0] as Int)!!\n')); + expect(code, contains('Foo.ofRaw(it)')); + expect(code, contains('val field1 = __pigeon_list[0] as Foo')); expect(code, contains('val field2 = __pigeon_list[1] as String\n')); expect(code, contains('fun toList(): List')); }); @@ -173,7 +173,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('enum class Foo(val raw: Int) {')); - expect(code, contains('val fooArg = Foo.ofRaw(args[0] as Int)')); + expect(code, contains('Foo.ofRaw(it)')); }); test('gen one host api', () { @@ -242,7 +242,7 @@ void main() { val args = message as List val inputArg = args[0] as Input val wrapped: List = try { - listOf(api.doSomething(inputArg)) + listOf(api.doSomething(inputArg)) } catch (exception: Throwable) { wrapError(exception) } @@ -595,7 +595,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doSomething(): Output')); - expect(code, contains('listOf(api.doSomething())')); + expect(code, contains('listOf(api.doSomething())')); expect(code, contains('wrapError(exception)')); expect(code, contains('reply(wrapped)')); }); @@ -1093,7 +1093,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doit(): List')); - expect(code, contains('listOf(api.doit())')); + expect(code, contains('listOf(api.doit())')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1171,7 +1171,7 @@ void main() { code, contains( 'val yArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long }')); - expect(code, contains('listOf(api.add(xArg, yArg))')); + expect(code, contains('listOf(api.add(xArg, yArg))')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1491,47 +1491,7 @@ void main() { expect(code, isNot(contains('*//'))); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const KotlinOptions kotlinOptions = KotlinOptions(); - const KotlinGenerator generator = KotlinGenerator(); - generator.generate( - kotlinOptions, - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains(' : StandardMessageCodec() '))); - expect(code, contains('StandardMessageCodec')); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( @@ -1823,4 +1783,99 @@ void main() { expect(code, contains(errorClassName)); expect(code, isNot(contains('FlutterError'))); }); + + test('do not generate duplicated entries in writeValue', () { + final Root root = Root( + apis: [ + AstHostApi( + name: 'FooBar', + methods: [ + Method( + name: 'fooBar', + location: ApiLocation.host, + returnType: const TypeDeclaration.voidDeclaration(), + parameters: [ + Parameter( + name: 'bar', + type: const TypeDeclaration( + baseName: 'Bar', + isNullable: false, + ), + ), + ], + ) + ], + ) + ], + classes: [ + Class( + name: 'Foo', + fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + name: 'foo', + ), + ], + ), + Class( + name: 'Bar', + fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'Foo', + isNullable: false, + ), + name: 'foo', + ), + NamedType( + type: const TypeDeclaration( + baseName: 'Foo', + isNullable: true, + ), + name: 'foo2', + ), + ], + ), + ], + enums: [], + ); + + final StringBuffer sink = StringBuffer(); + const String errorClassName = 'FooError'; + const KotlinOptions kotlinOptions = + KotlinOptions(errorClassName: errorClassName); + const KotlinGenerator generator = KotlinGenerator(); + generator.generate( + kotlinOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + + final String code = sink.toString(); + + // Extract override fun writeValue block + final int blockStart = code.indexOf('override fun writeValue'); + expect(blockStart, isNot(-1)); + final int blockEnd = code.indexOf('super.writeValue', blockStart); + expect(blockEnd, isNot(-1)); + final String writeValueBlock = code.substring(blockStart, blockEnd); + + // Count the occurrence of 'is Foo' in the block + int count = 0; + int index = 0; + while (index != -1) { + index = writeValueBlock.indexOf('is Foo', index); + if (index != -1) { + count++; + index += 'is Foo'.length; + } + } + + // There should be only one occurrence of 'is Foo' in the block + expect(count, 1); + }); } diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index 49ab94b78bc..84146be42db 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -183,7 +183,7 @@ void main() { expect( code, contains( - 'Enum1Box *enum1 = enum1AsNumber == nil ? nil : [[Enum1Box alloc] initWithValue:[enum1AsNumber integerValue]];')); + 'return enumAsNumber == nil ? nil : [[Enum1Box alloc] initWithValue:[enumAsNumber integerValue]];')); }); test('primitive enum host', () { @@ -246,7 +246,9 @@ void main() { expect( code, contains( - 'ACFoo arg_foo = [GetNullableObjectAtIndex(args, 0) integerValue];')); + 'return enumAsNumber == nil ? nil : [[ACFooBox alloc] initWithValue:[enumAsNumber integerValue]];')); + + expect(code, contains('ACFooBox * box = (ACFooBox *)value;')); } }); @@ -381,7 +383,6 @@ void main() { expect(code, contains('/// @return `nil` only when `error != nil`.')); expect(code, matches('nullable Output.*doSomething.*Input.*FlutterError')); expect(code, matches('SetUpApi.*.*_Nullable')); - expect(code, contains('ApiGetCodec(void)')); }); test('gen one api source', () { @@ -439,7 +440,6 @@ void main() { code, contains( 'NSCAssert([api respondsToSelector:@selector(doSomething:error:)')); - expect(code, contains('ApiGetCodec(void) {')); }); test('all the simple datatypes header', () { @@ -819,7 +819,6 @@ void main() { contains( 'initWithBinaryMessenger:(id)binaryMessenger;')); expect(code, matches('void.*doSomething.*Input.*Output')); - expect(code, contains('ApiGetCodec(void)')); }); test('gen flutter api source', () { @@ -871,7 +870,6 @@ void main() { final String code = sink.toString(); expect(code, contains('@implementation Api')); expect(code, matches('void.*doSomething.*Input.*Output.*{')); - expect(code, contains('ApiGetCodec(void) {')); }); test('gen host void header', () { @@ -2121,7 +2119,7 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('NSArray *args = message;')); + expect(code, contains('NSArray *args = message;')); expect( code, contains( @@ -2193,7 +2191,7 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect(code, contains('NSArray *args = message;')); + expect(code, contains('NSArray *args = message;')); expect( code, contains( @@ -2780,50 +2778,7 @@ void main() { expect(code, contains('/// ///')); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const ObjcGenerator generator = ObjcGenerator(); - final OutputFileOptions generatorOptions = - OutputFileOptions( - fileType: FileType.source, - languageOptions: const ObjcOptions(), - ); - generator.generate( - generatorOptions, - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains(' : FlutterStandardReader'))); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 34516e8c0de..8d56fa9d66f 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -1123,28 +1123,6 @@ abstract class Api { expect(results.errors.length, 0); }); - test('Enum key not supported', () { - const String code = ''' -enum MessageKey { - title, - subtitle, - description, -} - -class Message { - int? id; - Map? additionalProperties; -} - -@HostApi() -abstract class HostApiBridge { - void sendMessage(Message message); -} -'''; - final ParseResults results = parseSource(code); - expect(results.errors.length, 1); - }); - test('Export unreferenced enums', () { const String code = ''' enum MessageKey { @@ -1213,6 +1191,36 @@ class Message { expect(options.objcOptions!.copyrightHeader, ['A', 'Header']); }); + test('@ConfigurePigeon ObjcOptions.headerIncludePath', () { + const String code = ''' +@ConfigurePigeon(PigeonOptions( + objcOptions: ObjcOptions(headerIncludePath: 'Header.path'), +)) +class Message { + int? id; +} +'''; + + final ParseResults results = parseSource(code); + final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); + expect(options.objcOptions?.headerIncludePath, 'Header.path'); + }); + + test('@ConfigurePigeon CppOptions.headerIncludePath', () { + const String code = ''' +@ConfigurePigeon(PigeonOptions( + cppOptions: CppOptions(headerIncludePath: 'Header.path'), +)) +class Message { + int? id; +} +'''; + + final ParseResults results = parseSource(code); + final PigeonOptions options = PigeonOptions.fromMap(results.pigeonOptions!); + expect(options.cppOptions?.headerIncludePath, 'Header.path'); + }); + test('return nullable', () { const String code = ''' @HostApi() diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 780736c03b5..6ffe4f4d9d7 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -119,7 +119,12 @@ void main() { ); final String code = sink.toString(); expect(code, contains('enum Foo: Int')); - expect(code, contains('let fooArg = Foo(rawValue: args[0] as! Int)!')); + expect( + code, + contains( + 'let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int)')); + expect(code, contains('enumResult = Foo(rawValue: enumResultAsInt)')); + expect(code, contains('let fooArg = args[0] as! Foo')); expect(code, isNot(contains('if ('))); }); @@ -1326,46 +1331,7 @@ void main() { expect(code, contains('/// ///')); }); - test("doesn't create codecs if no custom datatypes", () { - final Root root = Root( - apis: [ - AstFlutterApi( - name: 'Api', - methods: [ - Method( - name: 'method', - location: ApiLocation.flutter, - returnType: const TypeDeclaration.voidDeclaration(), - parameters: [ - Parameter( - name: 'field', - type: const TypeDeclaration( - baseName: 'int', - isNullable: true, - ), - ), - ], - ) - ], - ) - ], - classes: [], - enums: [], - ); - final StringBuffer sink = StringBuffer(); - const SwiftOptions swiftOptions = SwiftOptions(); - const SwiftGenerator generator = SwiftGenerator(); - generator.generate( - swiftOptions, - root, - sink, - dartPackageName: DEFAULT_PACKAGE_NAME, - ); - final String code = sink.toString(); - expect(code, isNot(contains(': FlutterStandardReader '))); - }); - - test('creates custom codecs if custom datatypes present', () { + test('creates custom codecs', () { final Root root = Root(apis: [ AstFlutterApi(name: 'Api', methods: [ Method( diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index c4cf84582f1..8166e49d73f 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -98,6 +98,9 @@ Future generateTestPigeons({required String baseDir}) async { int generateCode = await runPigeon( input: './pigeons/$input.dart', dartOut: '$sharedDartOutputBase/lib/src/generated/$input.gen.dart', + dartTestOut: input == 'message' + ? '$sharedDartOutputBase/test/test_message.gen.dart' + : null, // Android kotlinOut: skipLanguages.contains(GeneratorLanguage.kotlin) ? null