CoreTests.gen

//
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon
import Foundation
#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#else
#error("Unsupported platform.")
#endif
private func wrapResult(_ result: Any?) -> [Any?] {
  return [result]
}
private func wrapError(_ error: Any) -> [Any?] {
  if let flutterError = error as? FlutterError {
    return [
      flutterError.code,
      flutterError.message,
      flutterError.details
    ]
  }
  return [
    "\(error)",
    "\(type(of: error))",
    "Stacktrace: \(Thread.callStackSymbols)"
  ]
}
private func nilOrValue<T>(_ value: Any?) -> T? {
  if value is NSNull { return nil }
  return value as! T?
}
enum AnEnum: Int {
  case one = 0
  case two = 1
  case three = 2
}
/// Generated class from Pigeon that represents data sent in messages.
struct AllTypes {
  var aBool: Bool
  var anInt: Int64
  var anInt64: Int64
  var aDouble: Double
  var aByteArray: FlutterStandardTypedData
  var a4ByteArray: FlutterStandardTypedData
  var a8ByteArray: FlutterStandardTypedData
  var aFloatArray: FlutterStandardTypedData
  var aList: [Any?]
  var aMap: [AnyHashable: Any?]
  var anEnum: AnEnum
  var aString: String
  static func fromList(_ list: [Any?]) -> AllTypes? {
    let aBool = list[0] as! Bool
    let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32)
    let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32)
    let aDouble = list[3] as! Double
    let aByteArray = list[4] as! FlutterStandardTypedData
    let a4ByteArray = list[5] as! FlutterStandardTypedData
    let a8ByteArray = list[6] as! FlutterStandardTypedData
    let aFloatArray = list[7] as! FlutterStandardTypedData
    let aList = list[8] as! [Any?]
    let aMap = list[9] as! [AnyHashable: Any?]
    let anEnum = AnEnum(rawValue: list[10] as! Int)!
    let aString = list[11] as! String
    return AllTypes(
      aBool: aBool,
      anInt: anInt,
      anInt64: anInt64,
      aDouble: aDouble,
      aByteArray: aByteArray,
      a4ByteArray: a4ByteArray,
      a8ByteArray: a8ByteArray,
      aFloatArray: aFloatArray,
      aList: aList,
      aMap: aMap,
      anEnum: anEnum,
      aString: aString
    )
  }
  func toList() -> [Any?] {
    return [
      aBool,
      anInt,
      anInt64,
      aDouble,
      aByteArray,
      a4ByteArray,
      a8ByteArray,
      aFloatArray,
      aList,
      aMap,
      anEnum.rawValue,
      aString,
    ]
  }
}
/// Generated class from Pigeon that represents data sent in messages.
struct AllNullableTypes {
  var aNullableBool: Bool? = nil
  var aNullableInt: Int64? = nil
  var aNullableInt64: Int64? = nil
  var aNullableDouble: Double? = nil
  var aNullableByteArray: FlutterStandardTypedData? = nil
  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
  static func fromList(_ list: [Any?]) -> AllNullableTypes? {
    let aNullableBool: Bool? = nilOrValue(list[0])
    let aNullableInt: Int64? = list[1] is NSNull ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32))
    let aNullableInt64: Int64? = list[2] is NSNull ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32))
    let aNullableDouble: Double? = nilOrValue(list[3])
    let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4])
    let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5])
    let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6])
    let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7])
    let aNullableList: [Any?]? = nilOrValue(list[8])
    let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9])
    let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10])
    let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11])
    let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12])
    var aNullableEnum: AnEnum? = nil
    let aNullableEnumEnumVal: Int? = nilOrValue(list[13])
    if let aNullableEnumRawValue = aNullableEnumEnumVal {
      aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)!
    }
    let aNullableString: String? = nilOrValue(list[14])
    return AllNullableTypes(
      aNullableBool: aNullableBool,
      aNullableInt: aNullableInt,
      aNullableInt64: aNullableInt64,
      aNullableDouble: aNullableDouble,
      aNullableByteArray: aNullableByteArray,
      aNullable4ByteArray: aNullable4ByteArray,
      aNullable8ByteArray: aNullable8ByteArray,
      aNullableFloatArray: aNullableFloatArray,
      aNullableList: aNullableList,
      aNullableMap: aNullableMap,
      nullableNestedList: nullableNestedList,
      nullableMapWithAnnotations: nullableMapWithAnnotations,
      nullableMapWithObject: nullableMapWithObject,
      aNullableEnum: aNullableEnum,
      aNullableString: aNullableString
    )
  }
  func toList() -> [Any?] {
    return [
      aNullableBool,
      aNullableInt,
      aNullableInt64,
      aNullableDouble,
      aNullableByteArray,
      aNullable4ByteArray,
      aNullable8ByteArray,
      aNullableFloatArray,
      aNullableList,
      aNullableMap,
      nullableNestedList,
      nullableMapWithAnnotations,
      nullableMapWithObject,
      aNullableEnum?.rawValue,
      aNullableString,
    ]
  }
}
/// Generated class from Pigeon that represents data sent in messages.
struct AllNullableTypesWrapper {
  var values: AllNullableTypes
  static func fromList(_ list: [Any?]) -> AllNullableTypesWrapper? {
    let values = AllNullableTypes.fromList(list[0] as! [Any?])!
    return AllNullableTypesWrapper(
      values: values
    )
  }
  func toList() -> [Any?] {
    return [
      values.toList(),
    ]
  }
}
/// A data class containing a List, used in unit tests.
///
/// Generated class from Pigeon that represents data sent in messages.
struct TestMessage {
  var testList: [Any?]? = nil
  static func fromList(_ list: [Any?]) -> TestMessage? {
    let testList: [Any?]? = nilOrValue(list[0])
    return TestMessage(
      testList: testList
    )
  }
  func toList() -> [Any?] {
    return [
      testList,
    ]
  }
}
private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
      case 128:
        return AllNullableTypes.fromList(self.readValue() as! [Any?])
      case 129:
        return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
      case 130:
        return AllTypes.fromList(self.readValue() as! [Any?])
      case 131:
        return TestMessage.fromList(self.readValue() as! [Any?])
      default:
        return super.readValue(ofType: type)
    }
  }
}
private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter {
  override func writeValue(_ value: Any) {
    if let value = value as? AllNullableTypes {
      super.writeByte(128)
      super.writeValue(value.toList())
    } else if let value = value as? AllNullableTypesWrapper {
      super.writeByte(129)
      super.writeValue(value.toList())
    } else if let value = value as? AllTypes {
      super.writeByte(130)
      super.writeValue(value.toList())
    } else if let value = value as? TestMessage {
      super.writeByte(131)
      super.writeValue(value.toList())
    } else {
      super.writeValue(value)
    }
  }
}
private class HostIntegrationCoreApiCodecReaderWriter: FlutterStandardReaderWriter {
  override func reader(with data: Data) -> FlutterStandardReader {
    return HostIntegrationCoreApiCodecReader(data: data)
  }
  override func writer(with data: NSMutableData) -> FlutterStandardWriter {
    return HostIntegrationCoreApiCodecWriter(data: data)
  }
}
class HostIntegrationCoreApiCodec: FlutterStandardMessageCodec {
  static let shared = HostIntegrationCoreApiCodec(readerWriter: HostIntegrationCoreApiCodecReaderWriter())
}
/// The core interface that each host language plugin must implement in
/// platform_test integration tests.
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol HostIntegrationCoreApi {
  /// A no-op function taking no arguments and returning no value, to sanity
  /// test basic calling.
  func noop() throws
  /// Returns the passed object, to test serialization and deserialization.
  func echo(_ everything: AllTypes) throws -> AllTypes
  /// Returns an error, to test error handling.
  func throwError() throws -> Any?
  /// Returns an error from a void function, to test error handling.
  func throwErrorFromVoid() throws
  /// Returns a Flutter error, to test error handling.
  func throwFlutterError() throws -> Any?
  /// Returns passed in int.
  func echo(_ anInt: Int64) throws -> Int64
  /// Returns passed in double.
  func echo(_ aDouble: Double) throws -> Double
  /// Returns the passed in boolean.
  func echo(_ aBool: Bool) throws -> Bool
  /// Returns the passed in string.
  func echo(_ aString: String) throws -> String
  /// Returns the passed in Uint8List.
  func echo(_ aUint8List: FlutterStandardTypedData) throws -> FlutterStandardTypedData
  /// Returns the passed in generic Object.
  func echo(_ anObject: Any) throws -> Any
  /// Returns the passed list, to test serialization and deserialization.
  func echo(_ aList: [Any?]) throws -> [Any?]
  /// Returns the passed map, to test serialization and deserialization.
  func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?]
  /// Returns the passed object, to test serialization and deserialization.
  func echo(_ everything: AllNullableTypes?) throws -> AllNullableTypes?
  /// Returns the inner `aString` value from the wrapped object, to test
  /// sending of nested objects.
  func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) throws -> String?
  /// Returns the inner `aString` value from the wrapped object, to test
  /// sending of nested objects.
  func createNestedObject(with nullableString: String?) throws -> AllNullableTypesWrapper
  /// Returns passed in arguments of multiple types.
  func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) throws -> AllNullableTypes
  /// Returns passed in int.
  func echo(_ aNullableInt: Int64?) throws -> Int64?
  /// Returns passed in double.
  func echo(_ aNullableDouble: Double?) throws -> Double?
  /// Returns the passed in boolean.
  func echo(_ aNullableBool: Bool?) throws -> Bool?
  /// Returns the passed in string.
  func echo(_ aNullableString: String?) throws -> String?
  /// Returns the passed in Uint8List.
  func echo(_ aNullableUint8List: FlutterStandardTypedData?) throws -> FlutterStandardTypedData?
  /// Returns the passed in generic Object.
  func echo(_ aNullableObject: Any?) throws -> Any?
  /// Returns the passed list, to test serialization and deserialization.
  func echoNullable(_ aNullableList: [Any?]?) throws -> [Any?]?
  /// Returns the passed map, to test serialization and deserialization.
  func echoNullable(_ aNullableMap: [String?: Any?]?) throws -> [String?: Any?]?
  /// A no-op function taking no arguments and returning no value, to sanity
  /// test basic asynchronous calling.
  /// Returns passed in int asynchronously.
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class HostIntegrationCoreApiSetup {
  /// The codec used by HostIntegrationCoreApi.
  static var codec: FlutterStandardMessageCodec { HostIntegrationCoreApiCodec.shared }
  /// Sets up an instance of `HostIntegrationCoreApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HostIntegrationCoreApi?) {
    /// A no-op function taking no arguments and returning no value, to sanity
    /// test basic calling.
    let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      noopChannel.setMessageHandler { _, reply in
        do {
          try api.noop()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      noopChannel.setMessageHandler(nil)
    }
    /// Returns the passed object, to test serialization and deserialization.
    let echoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAllTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let everythingArg = args[0] as! AllTypes
        do {
          let result = try api.echo(everythingArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoAllTypesChannel.setMessageHandler(nil)
    }
    /// Returns an error, to test error handling.
    let throwErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwErrorChannel.setMessageHandler { _, reply in
        do {
          let result = try api.throwError()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      throwErrorChannel.setMessageHandler(nil)
    }
    /// Returns an error from a void function, to test error handling.
    let throwErrorFromVoidChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwErrorFromVoidChannel.setMessageHandler { _, reply in
        do {
          try api.throwErrorFromVoid()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      throwErrorFromVoidChannel.setMessageHandler(nil)
    }
    /// Returns a Flutter error, to test error handling.
    let throwFlutterErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwFlutterError", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwFlutterErrorChannel.setMessageHandler { _, reply in
        do {
          let result = try api.throwFlutterError()
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      throwFlutterErrorChannel.setMessageHandler(nil)
    }
    /// Returns passed in int.
    let echoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anIntArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32)
        do {
          let result = try api.echo(anIntArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoIntChannel.setMessageHandler(nil)
    }
    /// Returns passed in double.
    let echoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aDoubleArg = args[0] as! Double
        do {
          let result = try api.echo(aDoubleArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoDoubleChannel.setMessageHandler(nil)
    }
    /// Returns the passed in boolean.
    let echoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aBoolArg = args[0] as! Bool
        do {
          let result = try api.echo(aBoolArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoBoolChannel.setMessageHandler(nil)
    }
    /// Returns the passed in string.
    let echoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg = args[0] as! String
        do {
          let result = try api.echo(aStringArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoStringChannel.setMessageHandler(nil)
    }
    /// Returns the passed in Uint8List.
    let echoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aUint8ListArg = args[0] as! FlutterStandardTypedData
        do {
          let result = try api.echo(aUint8ListArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoUint8ListChannel.setMessageHandler(nil)
    }
    /// Returns the passed in generic Object.
    let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoObjectChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anObjectArg = args[0]!
        do {
          let result = try api.echo(anObjectArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoObjectChannel.setMessageHandler(nil)
    }
    /// Returns the passed list, to test serialization and deserialization.
    let echoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg = args[0] as! [Any?]
        do {
          let result = try api.echo(aListArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoListChannel.setMessageHandler(nil)
    }
    /// Returns the passed map, to test serialization and deserialization.
    let echoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aMapArg = args[0] as! [String?: Any?]
        do {
          let result = try api.echo(aMapArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoMapChannel.setMessageHandler(nil)
    }
    /// Returns the passed object, to test serialization and deserialization.
    let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAllNullableTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let everythingArg: AllNullableTypes? = nilOrValue(args[0])
        do {
          let result = try api.echo(everythingArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoAllNullableTypesChannel.setMessageHandler(nil)
    }
    /// Returns the inner `aString` value from the wrapped object, to test
    /// sending of nested objects.
    let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      extractNestedNullableStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let wrapperArg = args[0] as! AllNullableTypesWrapper
        do {
          let result = try api.extractNestedNullableString(from: wrapperArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      extractNestedNullableStringChannel.setMessageHandler(nil)
    }
    /// Returns the inner `aString` value from the wrapped object, to test
    /// sending of nested objects.
    let createNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      createNestedNullableStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let nullableStringArg: String? = nilOrValue(args[0])
        do {
          let result = try api.createNestedObject(with: nullableStringArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      createNestedNullableStringChannel.setMessageHandler(nil)
    }
    /// Returns passed in arguments of multiple types.
    let sendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      sendMultipleNullableTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableBoolArg: Bool? = nilOrValue(args[0])
        let aNullableIntArg: Int64? = args[1] is NSNull ? nil : (args[1] is Int64? ? args[1] as! Int64? : Int64(args[1] as! Int32))
        let aNullableStringArg: String? = nilOrValue(args[2])
        do {
          let result = try api.sendMultipleNullableTypes(aBool: aNullableBoolArg, anInt: aNullableIntArg, aString: aNullableStringArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      sendMultipleNullableTypesChannel.setMessageHandler(nil)
    }
    /// Returns passed in int.
    let echoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableIntArg: Int64? = args[0] is NSNull ? nil : (args[0] is Int64? ? args[0] as! Int64? : Int64(args[0] as! Int32))
        do {
          let result = try api.echo(aNullableIntArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableIntChannel.setMessageHandler(nil)
    }
    /// Returns passed in double.
    let echoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableDoubleArg: Double? = nilOrValue(args[0])
        do {
          let result = try api.echo(aNullableDoubleArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableDoubleChannel.setMessageHandler(nil)
    }
    /// Returns the passed in boolean.
    let echoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableBoolArg: Bool? = nilOrValue(args[0])
        do {
          let result = try api.echo(aNullableBoolArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableBoolChannel.setMessageHandler(nil)
    }
    /// Returns the passed in string.
    let echoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableStringArg: String? = nilOrValue(args[0])
        do {
          let result = try api.echo(aNullableStringArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableStringChannel.setMessageHandler(nil)
    }
    /// Returns the passed in Uint8List.
    let echoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[0])
        do {
          let result = try api.echo(aNullableUint8ListArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableUint8ListChannel.setMessageHandler(nil)
    }
    /// Returns the passed in generic Object.
    let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableObjectChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableObjectArg: Any? = args[0]
        do {
          let result = try api.echo(aNullableObjectArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableObjectChannel.setMessageHandler(nil)
    }
    /// Returns the passed list, to test serialization and deserialization.
    let echoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableListArg: [Any?]? = nilOrValue(args[0])
        do {
          let result = try api.echoNullable(aNullableListArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableListChannel.setMessageHandler(nil)
    }
    /// Returns the passed map, to test serialization and deserialization.
    let echoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoNullableMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableMapArg: [String?: Any?]? = nilOrValue(args[0])
        do {
          let result = try api.echoNullable(aNullableMapArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      echoNullableMapChannel.setMessageHandler(nil)
    }
    /// A no-op function taking no arguments and returning no value, to sanity
    /// test basic asynchronous calling.
    let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      noopAsyncChannel.setMessageHandler { _, reply in
        api.noopAsync() { result in
          switch result {
            case .success:
              reply(wrapResult(nil))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      noopAsyncChannel.setMessageHandler(nil)
    }
    /// Returns passed in int asynchronously.
    let echoAsyncIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anIntArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32)
        api.echoAsync(anIntArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncIntChannel.setMessageHandler(nil)
    }
    /// Returns passed in double asynchronously.
    let echoAsyncDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aDoubleArg = args[0] as! Double
        api.echoAsync(aDoubleArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncDoubleChannel.setMessageHandler(nil)
    }
    /// Returns the passed in boolean asynchronously.
    let echoAsyncBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aBoolArg = args[0] as! Bool
        api.echoAsync(aBoolArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncBoolChannel.setMessageHandler(nil)
    }
    /// Returns the passed string asynchronously.
    let echoAsyncStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg = args[0] as! String
        api.echoAsync(aStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncStringChannel.setMessageHandler(nil)
    }
    /// Returns the passed in Uint8List asynchronously.
    let echoAsyncUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aUint8ListArg = args[0] as! FlutterStandardTypedData
        api.echoAsync(aUint8ListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncUint8ListChannel.setMessageHandler(nil)
    }
    /// Returns the passed in generic Object asynchronously.
    let echoAsyncObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncObject", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncObjectChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anObjectArg = args[0]!
        api.echoAsync(anObjectArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncObjectChannel.setMessageHandler(nil)
    }
    /// Returns the passed list, to test serialization and deserialization asynchronously.
    let echoAsyncListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg = args[0] as! [Any?]
        api.echoAsync(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncListChannel.setMessageHandler(nil)
    }
    /// Returns the passed map, to test serialization and deserialization asynchronously.
    let echoAsyncMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aMapArg = args[0] as! [String?: Any?]
        api.echoAsync(aMapArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncMapChannel.setMessageHandler(nil)
    }
    /// Responds with an error from an async function returning a value.
    let throwAsyncErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwAsyncErrorChannel.setMessageHandler { _, reply in
        api.throwAsyncError() { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      throwAsyncErrorChannel.setMessageHandler(nil)
    }
    /// Responds with an error from an async void function.
    let throwAsyncErrorFromVoidChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwAsyncErrorFromVoidChannel.setMessageHandler { _, reply in
        api.throwAsyncErrorFromVoid() { result in
          switch result {
            case .success:
              reply(wrapResult(nil))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      throwAsyncErrorFromVoidChannel.setMessageHandler(nil)
    }
    /// Responds with a Flutter error from an async function returning a value.
    let throwAsyncFlutterErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncFlutterError", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      throwAsyncFlutterErrorChannel.setMessageHandler { _, reply in
        api.throwAsyncFlutterError() { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      throwAsyncFlutterErrorChannel.setMessageHandler(nil)
    }
    /// Returns the passed object, to test async serialization and deserialization.
    let echoAsyncAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncAllTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncAllTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let everythingArg = args[0] as! AllTypes
        api.echoAsync(everythingArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncAllTypesChannel.setMessageHandler(nil)
    }
    /// Returns the passed object, to test serialization and deserialization.
    let echoAsyncNullableAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableAllNullableTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let everythingArg: AllNullableTypes? = nilOrValue(args[0])
        api.echoAsync(everythingArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableAllNullableTypesChannel.setMessageHandler(nil)
    }
    /// Returns passed in int asynchronously.
    let echoAsyncNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anIntArg: Int64? = args[0] is NSNull ? nil : (args[0] is Int64? ? args[0] as! Int64? : Int64(args[0] as! Int32))
        api.echoAsyncNullable(anIntArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableIntChannel.setMessageHandler(nil)
    }
    /// Returns passed in double asynchronously.
    let echoAsyncNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aDoubleArg: Double? = nilOrValue(args[0])
        api.echoAsyncNullable(aDoubleArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableDoubleChannel.setMessageHandler(nil)
    }
    /// Returns the passed in boolean asynchronously.
    let echoAsyncNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aBoolArg: Bool? = nilOrValue(args[0])
        api.echoAsyncNullable(aBoolArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableBoolChannel.setMessageHandler(nil)
    }
    /// Returns the passed string asynchronously.
    let echoAsyncNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg: String? = nilOrValue(args[0])
        api.echoAsyncNullable(aStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableStringChannel.setMessageHandler(nil)
    }
    /// Returns the passed in Uint8List asynchronously.
    let echoAsyncNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[0])
        api.echoAsyncNullable(aUint8ListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableUint8ListChannel.setMessageHandler(nil)
    }
    /// Returns the passed in generic Object asynchronously.
    let echoAsyncNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableObject", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableObjectChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anObjectArg: Any? = args[0]
        api.echoAsyncNullable(anObjectArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableObjectChannel.setMessageHandler(nil)
    }
    /// Returns the passed list, to test serialization and deserialization asynchronously.
    let echoAsyncNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg: [Any?]? = nilOrValue(args[0])
        api.echoAsyncNullable(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableListChannel.setMessageHandler(nil)
    }
    /// Returns the passed map, to test serialization and deserialization asynchronously.
    let echoAsyncNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncNullableMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      echoAsyncNullableMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aMapArg: [String?: Any?]? = nilOrValue(args[0])
        api.echAsyncoNullable(aMapArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoAsyncNullableMapChannel.setMessageHandler(nil)
    }
    let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterNoopChannel.setMessageHandler { _, reply in
        api.callFlutterNoop() { result in
          switch result {
            case .success:
              reply(wrapResult(nil))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterNoopChannel.setMessageHandler(nil)
    }
    let callFlutterThrowErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterThrowError", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterThrowErrorChannel.setMessageHandler { _, reply in
        api.callFlutterThrowError() { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterThrowErrorChannel.setMessageHandler(nil)
    }
    let callFlutterThrowErrorFromVoidChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterThrowErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterThrowErrorFromVoidChannel.setMessageHandler { _, reply in
        api.callFlutterThrowErrorFromVoid() { result in
          switch result {
            case .success:
              reply(wrapResult(nil))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterThrowErrorFromVoidChannel.setMessageHandler(nil)
    }
    let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let everythingArg = args[0] as! AllTypes
        api.callFlutterEcho(everythingArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoAllTypesChannel.setMessageHandler(nil)
    }
    let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aNullableBoolArg: Bool? = nilOrValue(args[0])
        let aNullableIntArg: Int64? = args[1] is NSNull ? nil : (args[1] is Int64? ? args[1] as! Int64? : Int64(args[1] as! Int32))
        let aNullableStringArg: String? = nilOrValue(args[2])
        api.callFlutterSendMultipleNullableTypes(aBool: aNullableBoolArg, anInt: aNullableIntArg, aString: aNullableStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterSendMultipleNullableTypesChannel.setMessageHandler(nil)
    }
    let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aBoolArg = args[0] as! Bool
        api.callFlutterEcho(aBoolArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoBoolChannel.setMessageHandler(nil)
    }
    let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anIntArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32)
        api.callFlutterEcho(anIntArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoIntChannel.setMessageHandler(nil)
    }
    let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aDoubleArg = args[0] as! Double
        api.callFlutterEcho(aDoubleArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoDoubleChannel.setMessageHandler(nil)
    }
    let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg = args[0] as! String
        api.callFlutterEcho(aStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoStringChannel.setMessageHandler(nil)
    }
    let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg = args[0] as! FlutterStandardTypedData
        api.callFlutterEcho(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoUint8ListChannel.setMessageHandler(nil)
    }
    let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg = args[0] as! [Any?]
        api.callFlutterEcho(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoListChannel.setMessageHandler(nil)
    }
    let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aMapArg = args[0] as! [String?: Any?]
        api.callFlutterEcho(aMapArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoMapChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aBoolArg: Bool? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aBoolArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableBoolChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let anIntArg: Int64? = args[0] is NSNull ? nil : (args[0] is Int64? ? args[0] as! Int64? : Int64(args[0] as! Int32))
        api.callFlutterEchoNullable(anIntArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableIntChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aDoubleArg: Double? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aDoubleArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableDoubleChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg: String? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableStringChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg: FlutterStandardTypedData? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableUint8ListChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableListChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aListArg: [Any?]? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aListArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableListChannel.setMessageHandler(nil)
    }
    let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aMapArg: [String?: Any?]? = nilOrValue(args[0])
        api.callFlutterEchoNullable(aMapArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      callFlutterEchoNullableMapChannel.setMessageHandler(nil)
    }
  }
}
private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
      case 128:
        return AllNullableTypes.fromList(self.readValue() as! [Any?])
      case 129:
        return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
      case 130:
        return AllTypes.fromList(self.readValue() as! [Any?])
      case 131:
        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? AllNullableTypes {
      super.writeByte(128)
      super.writeValue(value.toList())
    } else if let value = value as? AllNullableTypesWrapper {
      super.writeByte(129)
      super.writeValue(value.toList())
    } else if let value = value as? AllTypes {
      super.writeByte(130)
      super.writeValue(value.toList())
    } else if let value = value as? TestMessage {
      super.writeByte(131)
      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.
///
/// Generated class from Pigeon that represents Flutter messages that can be called from Swift.
class FlutterIntegrationCoreApi {
  private let binaryMessenger: FlutterBinaryMessenger
  init(binaryMessenger: FlutterBinaryMessenger){
    self.binaryMessenger = binaryMessenger
  }
  var codec: FlutterStandardMessageCodec {
    return FlutterIntegrationCoreApiCodec.shared
  }
  /// A no-op function taking no arguments and returning no value, to sanity
  /// test basic calling.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage(nil) { _ in
      completion()
    }
  }
  /// Returns the passed object, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([everythingArg] as [Any?]) { response in
      let result = response as! AllNullableTypes
      completion(result)
    }
  }
  /// Returns passed in arguments of multiple types.
  ///
  /// Tests multiple-arity FlutterApi handling.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aBoolArg] as [Any?]) { response in
      let result = response as! Bool
      completion(result)
    }
  }
  /// Returns the passed int, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aDoubleArg] as [Any?]) { response in
      let result = response as! Double
      completion(result)
    }
  }
  /// Returns the passed string, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aListArg] as [Any?]) { response in
      let result = response as! FlutterStandardTypedData
      completion(result)
    }
  }
  /// Returns the passed list, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aMapArg] as [Any?]) { response in
      let result = response as! [String?: Any?]
      completion(result)
    }
  }
  /// Returns the passed boolean, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([anIntArg] as [Any?]) { response in
      let result: Int64? = response is NSNull ? nil : (response is Int64? ? response as! Int64? : Int64(response as! Int32))
      completion(result)
    }
  }
  /// Returns the passed double, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aStringArg] as [Any?]) { response in
      let result: String? = nilOrValue(response)
      completion(result)
    }
  }
  /// Returns the passed byte list, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aListArg] as [Any?]) { response in
      let result: [Any?]? = nilOrValue(response)
      completion(result)
    }
  }
  /// Returns the passed map, to test serialization and deserialization.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage(nil) { _ in
      completion()
    }
  }
  /// Returns the passed in generic Object asynchronously.
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([aStringArg] as [Any?]) { response in
      let result = response as! String
      completion(result)
    }
  }
}
/// An API that can be implemented for minimal, compile-only tests.
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol HostTrivialApi {
  func noop() throws
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class HostTrivialApiSetup {
  /// The codec used by HostTrivialApi.
  /// Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HostTrivialApi?) {
    let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostTrivialApi.noop", binaryMessenger: binaryMessenger)
    if let api = api {
      noopChannel.setMessageHandler { _, reply in
        do {
          try api.noop()
          reply(wrapResult(nil))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      noopChannel.setMessageHandler(nil)
    }
  }
}
/// A simple API implemented in some unit tests.
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol HostSmallApi {
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class HostSmallApiSetup {
  /// The codec used by HostSmallApi.
  /// Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HostSmallApi?) {
    let echoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostSmallApi.echo", binaryMessenger: binaryMessenger)
    if let api = api {
      echoChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let aStringArg = args[0] as! String
        api.echo(aString: aStringArg) { result in
          switch result {
            case .success(let res):
              reply(wrapResult(res))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      echoChannel.setMessageHandler(nil)
    }
    let voidVoidChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostSmallApi.voidVoid", binaryMessenger: binaryMessenger)
    if let api = api {
      voidVoidChannel.setMessageHandler { _, reply in
        api.voidVoid() { result in
          switch result {
            case .success:
              reply(wrapResult(nil))
            case .failure(let error):
              reply(wrapError(error))
          }
        }
      }
    } else {
      voidVoidChannel.setMessageHandler(nil)
    }
  }
}
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 class from Pigeon that represents Flutter messages that can be called from Swift.
class FlutterSmallApi {
  private let binaryMessenger: FlutterBinaryMessenger
  init(binaryMessenger: FlutterBinaryMessenger){
    self.binaryMessenger = binaryMessenger
  }
  var codec: FlutterStandardMessageCodec {
    return FlutterSmallApiCodec.shared
  }
    let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.FlutterSmallApi.echoWrappedList", binaryMessenger: binaryMessenger, codec: codec)
    channel.sendMessage([msgArg] as [Any?]) { response in
      let result = response as! TestMessage
      completion(result)
    }
  }
}


TestPlugin

import Cocoa
import FlutterMacOS
extension FlutterError: Error {}
/**
 * This plugin handles the native side of the integration tests in
 * example/integration_test/.
 */
public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi {
  var flutterAPI: FlutterIntegrationCoreApi
  public static func register(with registrar: FlutterPluginRegistrar) {
    let plugin = TestPlugin(binaryMessenger: registrar.messenger)
    HostIntegrationCoreApiSetup.setUp(binaryMessenger: registrar.messenger, api: plugin)
  }
  init(binaryMessenger: FlutterBinaryMessenger) {
    flutterAPI = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger)
  }
  // MARK: HostIntegrationCoreApi implementation
  func noop() {
  }
  func echo(_ everything: AllTypes) -> AllTypes {
    return everything
  }
  func echo(_ everything: AllNullableTypes?) -> AllNullableTypes? {
    return everything
  }
  func throwError() throws -> Any? {
    throw FlutterError(code: "code", message: "message", details: "details")
  }
  func throwErrorFromVoid() throws {
    throw FlutterError(code: "code", message: "message", details: "details")
  }
  func throwFlutterError() throws -> Any? {
    throw FlutterError(code: "code", message: "message", details: "details")
  }
  func echo(_ anInt: Int64) -> Int64 {
    return anInt
  }
  func echo(_ aDouble: Double) -> Double {
    return aDouble
  }
  func echo(_ aBool: Bool) -> Bool {
    return aBool
  }
  func echo(_ aString: String) -> String {
    return aString
  }
  func echo(_ aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData {
    return aUint8List
  }
  func echo(_ anObject: Any) -> Any {
    return anObject
  }
  func echo(_ aList: [Any?]) throws -> [Any?] {
    return aList
  }
  func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] {
    return aMap
  }
  func extractNestedNullableString(from wrapper: AllNullableTypesWrapper) -> String? {
    return wrapper.values.aNullableString;
  }
  func createNestedObject(with nullableString: String?) -> AllNullableTypesWrapper {
    return AllNullableTypesWrapper(values: AllNullableTypes(aNullableString: nullableString))
  }
  func sendMultipleNullableTypes(aBool aNullableBool: Bool?, anInt aNullableInt: Int64?, aString aNullableString: String?) -> AllNullableTypes {
    let someThings = AllNullableTypes(aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString)
    return someThings
  }
  func echo(_ aNullableInt: Int64?) -> Int64? {
    return aNullableInt
  }
  func echo(_ aNullableDouble: Double?) -> Double? {
    return aNullableDouble
  }
  func echo(_ aNullableBool: Bool?) -> Bool? {
    return aNullableBool
  }
  func echo(_ aNullableString: String?) -> String? {
    return aNullableString
  }
  func echo(_ aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? {
    return aNullableUint8List
  }
  func echo(_ aNullableObject: Any?) -> Any? {
    return aNullableObject
  }
  func echoNullable(_ aNullableList: [Any?]?) throws -> [Any?]? {
    return aNullableList
  }
  func echoNullable(_ aNullableMap: [String?: Any?]?) throws -> [String?: Any?]? {
    return aNullableMap
  }
    completion(.success(everything))
  }
    completion(.success(aString))
  }
    completion(.success(anInt))
  }
    completion(.success(anObject))
  }
    // TODO: (tarrinneal) Once flutter api error handling is added, enable these tests.
    // See issue https://github.com/flutter/flutter/issues/118243
  }
  ) {
    flutterAPI.sendMultipleNullableTypes(
      aBool: aNullableBool,
      anInt: aNullableInt,
      aString: aNullableString
    ) {
      completion(.success($0))
    }
  }
    flutterAPI.echo(aDouble) {
      completion(.success($0))
    }
  }
    flutterAPI.echo(aList) {
      completion(.success($0))
    }
  }
    flutterAPI.echoNullable(anInt) {
      completion(.success($0))
    }
  }
    flutterAPI.echoNullable(aList) {
      completion(.success($0))
    }
  }
    flutterAPI.echoNullable(aMap) {
      completion(.success($0))
    }
  }
}


RunnerTests

class RunnerTests: XCTestCase {

  func testToListAndBack() throws {
    let reply = MessageSearchReply(result: "foobar")
    let dict = reply.toList()
    let copy = MessageSearchReply.fromList(dict)
    XCTAssertEqual(reply.result, copy?.result)
  }
  func testHandlesNull() throws {
    let reply = MessageSearchReply()
    let dict = reply.toList()
    let copy = MessageSearchReply.fromList(dict)
    XCTAssertNil(copy?.result)
  }
  func testHandlesNullFirst() throws {
    let reply = MessageSearchReply(error: "foobar")
    let dict = reply.toList()
    let copy = MessageSearchReply.fromList(dict)
    XCTAssertEqual(reply.error, copy?.error)
  }
}


EchoBinaryMessenger

import Foundation
import Flutter
class EchoBinaryMessenger: NSObject, FlutterBinaryMessenger {
  let codec: FlutterMessageCodec
  private(set) var count = 0
  var defaultReturn: Any?

  init(codec: FlutterMessageCodec) {
    self.codec = codec
    super.init()
  }

  func send(onChannel channel: String, message: Data?) {
    // Method not implemented because this messenger is just for echoing
  }

  func send(
    onChannel channel: String,
    message: Data?,
    binaryReply callback: FlutterBinaryReply? = nil
  ) {
    guard let callback = callback else { return }

    guard
      let args = self.codec.decode(message) as? [Any?],
      let firstArg = args.first,
      let castedFirstArg: Any? = nilOrValue(firstArg)
    else {
      callback(self.defaultReturn.flatMap { self.codec.encode($0) })
      return
    }

    callback(self.codec.encode(castedFirstArg))
  }

  func setMessageHandlerOnChannel(
    _ channel: String, binaryMessageHandler handler:
    FlutterBinaryMessageHandler? = nil
  ) -> FlutterBinaryMessengerConnection {
    self.count += 1
    return FlutterBinaryMessengerConnection(self.count)
  }

  func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {
    // Method not implemented because this messenger is just for echoing
  }
  private func nilOrValue<T>(_ value: Any?) -> T? {
    if value is NSNull { return nil }
    return (value as Any) as! T?
  }
}


HandlerBinaryMessenger

    self.codec = codec
    self.handler = handler
    super.init()
  }

  func send(onChannel channel: String, message: Data?) {
    // Method not implemented because this messenger is just for handling
  }

  func send(
    onChannel channel: String,
    message: Data?,
    binaryReply callback: FlutterBinaryReply? = nil
  ) {
    guard let callback = callback else { return }

    guard let args = self.codec.decode(message) as? [Any?] else {
      callback(nil)
      return
    }

    let result = self.handler(args)
    callback(self.codec.encode(result))
  }

  func setMessageHandlerOnChannel(
    _ channel: String,
    binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil
  ) -> FlutterBinaryMessengerConnection {
    self.count += 1
    return FlutterBinaryMessengerConnection(self.count)
  }

  func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {
    // Method not implemented because this messenger is just for handling
  }
}


MultipleArityTests

class MockMultipleArityHostApi: MultipleArityHostApi {
  func subtract(x: Int64, y: Int64) -> Int64 {
    return x - y
  }
}
class MultipleArityTests: XCTestCase {
  var codec = FlutterStandardMessageCodec.sharedInstance()
  func testSimpleHost() throws {
    let binaryMessenger = MockBinaryMessenger<Int64>(codec: EnumApi2HostCodec.shared)
    MultipleArityHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockMultipleArityHostApi())
    let channelName = "dev.flutter.pigeon.MultipleArityHostApi.subtract"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let inputX = 10
    let inputY = 7
    let inputEncoded = binaryMessenger.codec.encode([inputX, inputY])
    let expectation = XCTestExpectation(description: "subtraction")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList![0] as? Int64
      XCTAssertEqual(3, output)
        XCTAssertTrue(outputList?.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testSimpleFlutter() throws {
    let binaryMessenger = HandlerBinaryMessenger(codec: codec) { args in
      return (args[0] as! Int) - (args[1] as! Int)
    }
    let api = MultipleArityFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "subtraction")
    api.subtract(x: 30, y: 10) { result in
      XCTAssertEqual(20, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


AsyncHandlersTest

    completion(.success(()))
  }
}
class AsyncHandlersTest: XCTestCase {
  func testAsyncHost2Flutter() throws {
    let value = "Test"
    let binaryMessenger = MockBinaryMessenger<String>(codec: FlutterIntegrationCoreApiCodec.shared)
    binaryMessenger.result = value
    let flutterApi = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    flutterApi.echo(value) { output in
      XCTAssertEqual(output, value)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testAsyncFlutter2HostVoidVoid() throws {
    let binaryMessenger = MockBinaryMessenger<String>(codec: FlutterStandardMessageCodec.sharedInstance())
    let mockHostSmallApi = MockHostSmallApi()
    HostSmallApiSetup.setUp(binaryMessenger: binaryMessenger, api: mockHostSmallApi)
    let channelName = "dev.flutter.pigeon.HostSmallApi.voidVoid"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let expectation = XCTestExpectation(description: "voidvoid callback")
    binaryMessenger.handlers[channelName]?(nil) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
        XCTAssertEqual(outputList?.first as! NSNull, NSNull())
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testAsyncFlutter2Host() throws {
    let binaryMessenger = MockBinaryMessenger<String>(codec: FlutterStandardMessageCodec.sharedInstance())
    let mockHostSmallApi = MockHostSmallApi()
    let value = "Test"
    mockHostSmallApi.output = value
    HostSmallApiSetup.setUp(binaryMessenger: binaryMessenger, api: mockHostSmallApi)
    let channelName = "dev.flutter.pigeon.HostSmallApi.echo"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let inputEncoded = binaryMessenger.codec.encode([value])
    let expectation = XCTestExpectation(description: "echo callback")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
        let output = outputList?.first as? String
      XCTAssertEqual(output, value)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


NullableReturnsTests

class MockNullableArgHostApi: NullableArgHostApi {
  var didCall: Bool = false
  var x: Int64?
  func doit(x: Int64?) -> Int64 {
    didCall = true
    self.x = x
    return x ?? 0
  }
}
class NullableReturnsTests: XCTestCase {
  var codec = FlutterStandardMessageCodec.sharedInstance()
  func testNullableParameterWithFlutterApi() {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    binaryMessenger.defaultReturn = 99
    let api = NullableArgFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.doit(x: nil) { result in
      XCTAssertEqual(99, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testNullableParameterWithHostApi() {
    let api = MockNullableArgHostApi()
    let binaryMessenger = MockBinaryMessenger<Int64?>(codec: codec)
    let channel = "dev.flutter.pigeon.NullableArgHostApi.doit"
    NullableArgHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: api)
    XCTAssertNotNil(binaryMessenger.handlers[channel])
    let inputEncoded = binaryMessenger.codec.encode([nil] as [Any?])
    let expectation = XCTestExpectation(description: "callback")
    binaryMessenger.handlers[channel]?(inputEncoded) { _ in
      expectation.fulfill()
    }
    XCTAssertTrue(api.didCall)
    XCTAssertNil(api.x)
    wait(for: [expectation], timeout: 1.0)
  }
}


NonNullFieldsTest

class NonNullFieldsTests: XCTestCase {
  func testMake() {
    let request = NonNullFieldSearchRequest(query: "hello")
    XCTAssertEqual("hello", request.query)
  }
}


ListTests

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 api = FlutterSmallApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.echo(top) { result in
      XCTAssertEqual(1, result.testList?.count)
      XCTAssertTrue(result.testList?[0] is TestMessage)
      XCTAssert(equalsList(inside.testList, (result.testList?[0] as! TestMessage).testList))
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


Utils

import Foundation
func equals(_ x: Any?, _ y: Any?) -> Bool {
  if x == nil, y == nil {
    return true
  }
  guard let x = x as? AnyHashable, let y = y as? AnyHashable else {
    return false
  }
  return x == y
}
func equalsList(_ x: [Any?]?, _ y: [Any?]?) -> Bool {
  if x == nil, y == nil {
    return true
  }
  guard x?.count == y?.count else { return false }
  guard let x = x, let y = y else { return false }
  return (0..<x.count).allSatisfy { equals(x[$0], y[$0]) }
}
func equalsDictionary(_ x: [AnyHashable: Any?]?, _ y: [AnyHashable: Any?]?) -> Bool {
  if x == nil, y == nil {
    return true
  }
  guard x?.count == y?.count else { return false }
  guard let x = x, let y = y else { return false }
  return x.allSatisfy { equals($0.value, y[$0.key] as Any?) }
}


MockBinaryMessenger

class MockBinaryMessenger<T>: NSObject, FlutterBinaryMessenger {
  let codec: FlutterMessageCodec
  var result: T?
  private(set) var handlers: [String: FlutterBinaryMessageHandler] = [:]
  init(codec: FlutterMessageCodec) {
    self.codec = codec
    super.init()
  }
  func send(onChannel channel: String, message: Data?) {}
  func send(
    onChannel channel: String,
    message: Data?,
    binaryReply callback: FlutterBinaryReply? = nil
  ) {
    if let result = result {
      callback?(codec.encode(result))
    }
  }
  func setMessageHandlerOnChannel(
    _ channel: String,
    binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil
  ) -> FlutterBinaryMessengerConnection {
    handlers[channel] = handler
    return .init(handlers.count)
  }
  func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {}
}


EnumTests

class MockEnumApi2Host: EnumApi2Host {
  func echo(data: DataWithEnum) -> DataWithEnum {
    return data
  }
}
extension DataWithEnum: Equatable {
  public static func == (lhs: DataWithEnum, rhs: DataWithEnum) -> Bool {
    lhs.state == rhs.state
  }
}
class EnumTests: XCTestCase {
  func testEchoHost() throws {
    let binaryMessenger = MockBinaryMessenger<DataWithEnum>(codec: EnumApi2HostCodec.shared)
    EnumApi2HostSetup.setUp(binaryMessenger: binaryMessenger, api: MockEnumApi2Host())
    let channelName = "dev.flutter.pigeon.EnumApi2Host.echo"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input = DataWithEnum(state: .success)
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "echo")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputMap = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputMap)

      let output = outputMap?.first as? DataWithEnum
      XCTAssertEqual(output, input)
      XCTAssertTrue(outputMap?.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testEchoFlutter() throws {
    let data = DataWithEnum(state: .error)
    let binaryMessenger = EchoBinaryMessenger(codec: EnumApi2HostCodec.shared)
    let api = EnumApi2Flutter(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.echo(data: data) { result in
      XCTAssertEqual(data.state, result.state)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


AllDatatypesTests

class AllDatatypesTests: XCTestCase {
  func testAllNull() throws {
    let everything = AllNullableTypes()
    let binaryMessenger = EchoBinaryMessenger(codec: FlutterIntegrationCoreApiCodec.shared)
    let api = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.echoNullable(everything) { result in
      XCTAssertNil(result.aNullableBool)
      XCTAssertNil(result.aNullableInt)
      XCTAssertNil(result.aNullableDouble)
      XCTAssertNil(result.aNullableString)
      XCTAssertNil(result.aNullableByteArray)
      XCTAssertNil(result.aNullable4ByteArray)
      XCTAssertNil(result.aNullable8ByteArray)
      XCTAssertNil(result.aNullableFloatArray)
      XCTAssertNil(result.aNullableList)
      XCTAssertNil(result.aNullableMap)
      XCTAssertNil(result.nullableNestedList)
      XCTAssertNil(result.nullableMapWithAnnotations)
      XCTAssertNil(result.nullableMapWithObject)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testAllEquals() throws {
    let everything = AllNullableTypes(
      aNullableBool: true,
      aNullableInt: 1,
      aNullableDouble: 2.0,
      aNullableByteArray: FlutterStandardTypedData(bytes: "1234".data(using: .utf8)!),
      aNullable4ByteArray: FlutterStandardTypedData(int32: "1234".data(using: .utf8)!),
      aNullable8ByteArray: FlutterStandardTypedData(int64: "12345678".data(using: .utf8)!),
      aNullableFloatArray: FlutterStandardTypedData(float64: "12345678".data(using: .utf8)!),
      aNullableList: [1, 2],
      aNullableMap: ["hello": 1234],
      nullableNestedList: [[true, false], [true]],
      nullableMapWithAnnotations: ["hello": "world"],
      nullableMapWithObject: ["hello": 1234, "goodbye" : "world"],
      aNullableString: "123"
    )

    let binaryMessenger = EchoBinaryMessenger(codec: FlutterIntegrationCoreApiCodec.shared)
    let api = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.echoNullable(everything) { result in
      XCTAssertEqual(result.aNullableBool, everything.aNullableBool)
      XCTAssertEqual(result.aNullableInt, everything.aNullableInt)
      XCTAssertEqual(result.aNullableDouble, everything.aNullableDouble)
      XCTAssertEqual(result.aNullableString, everything.aNullableString)
      XCTAssertEqual(result.aNullableByteArray, everything.aNullableByteArray)
      XCTAssertEqual(result.aNullable4ByteArray, everything.aNullable4ByteArray)
      XCTAssertEqual(result.aNullable8ByteArray, everything.aNullable8ByteArray)
      XCTAssertEqual(result.aNullableFloatArray, everything.aNullableFloatArray)
      XCTAssert(equalsList(result.aNullableList, everything.aNullableList))
      XCTAssert(equalsDictionary(result.aNullableMap, everything.aNullableMap))
      XCTAssertEqual(result.nullableNestedList, everything.nullableNestedList)
      XCTAssertEqual(result.nullableMapWithAnnotations, everything.nullableMapWithAnnotations)
      XCTAssert(equalsDictionary(result.nullableMapWithObject, everything.nullableMapWithObject))
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


PrimitiveTests

class MockPrimitiveHostApi: PrimitiveHostApi {
  func anInt(value: Int64) -> Int64 { value }
  func aBool(value: Bool) -> Bool { value }
  func aString(value: String) -> String { value  }
  func aDouble(value: Double) -> Double { value }
  func aMap(value: [AnyHashable: Any?]) -> [AnyHashable: Any?] { value }
  func aList(value: [Any?]) -> [Any?] { value }
  func anInt32List(value: FlutterStandardTypedData) -> FlutterStandardTypedData { value }
  func aBoolList(value: [Bool?]) -> [Bool?] { value }
  func aStringIntMap(value: [String?: Int64?]) -> [String?: Int64?] { value }
}
class PrimitiveTests: XCTestCase {
  var codec = FlutterStandardMessageCodec.sharedInstance()
  func testIntPrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<Int32>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.anInt"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input = 1
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "anInt")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList!.first as? Int64
      XCTAssertEqual(1, output)
      XCTAssertTrue(outputList!.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testIntPrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.anInt(value: 1) { result in
      XCTAssertEqual(1, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testBoolPrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<Bool>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.aBool"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input = true
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "aBool")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList!.first as? Bool
      XCTAssertEqual(true, output)
      XCTAssertTrue(outputList!.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testBoolPrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    api.aBool(value: true) { result in
      XCTAssertEqual(true, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testDoublePrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<Double>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.aDouble"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input: Double = 1.0
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "aDouble")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList!.first as? Double
      XCTAssertEqual(1.0, output)
      XCTAssertTrue(outputList!.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testDoublePrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    let arg: Double = 1.5
    api.aDouble(value: arg) { result in
      XCTAssertEqual(arg, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testStringPrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<String>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.aString"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input: String = "hello"
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "aString")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList!.first as? String
      XCTAssertEqual("hello", output)
      XCTAssertTrue(outputList!.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testStringPrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    let arg: String = "hello"
    api.aString(value: arg) { result in
      XCTAssertEqual(arg, result)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testListPrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<[Int]>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.aList"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input: [Int] = [1, 2, 3]
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "aList")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let outputList = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertNotNil(outputList)

      let output = outputList!.first as? [Int]
      XCTAssertEqual([1, 2, 3], output)
      XCTAssertTrue(outputList!.count == 1)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testListPrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    let arg = ["hello"]
    api.aList(value: arg) { result in
      XCTAssert(equalsList(arg, result))
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testMapPrimitiveHost() throws {
    let binaryMessenger = MockBinaryMessenger<[String: Int]>(codec: codec)
    PrimitiveHostApiSetup.setUp(binaryMessenger: binaryMessenger, api: MockPrimitiveHostApi())
    let channelName = "dev.flutter.pigeon.PrimitiveHostApi.aMap"
    XCTAssertNotNil(binaryMessenger.handlers[channelName])
    let input: [String: Int] = ["hello": 1, "world": 2]
    let inputEncoded = binaryMessenger.codec.encode([input])
    let expectation = XCTestExpectation(description: "aMap")
    binaryMessenger.handlers[channelName]?(inputEncoded) { data in
      let output = binaryMessenger.codec.decode(data) as? [Any]
      XCTAssertTrue(output?.count == 1)
      let outputMap = output?.first as? [String: Int]
      XCTAssertNotNil(outputMap)
      XCTAssertEqual(["hello": 1, "world": 2], outputMap)
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
  func testMapPrimitiveFlutter() throws {
    let binaryMessenger = EchoBinaryMessenger(codec: codec)
    let api = PrimitiveFlutterApi(binaryMessenger: binaryMessenger)
    let expectation = XCTestExpectation(description: "callback")
    let arg = ["hello": 1]
    api.aMap(value: arg) { result in
      XCTAssert(equalsDictionary(arg, result))
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 1.0)
  }
}


AppDelegate

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}


BasicCompileTest

class MyApi: HostTrivialApi {
  func noop() {}
}
// Since the generator is almost entirely shared with iOS, this is currently
// just testing that the generated code compiles for macOS (e.g., that the
// Flutter framework import is correct).
class BasicCompileTest: XCTestCase {
  func testMakeApi() {
    let api = MyApi()
    XCTAssertNotNil(api)
  }
}


AppDelegate

class AppDelegate: FlutterAppDelegate {
  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    return true
  }
}


MainFlutterWindow

import Cocoa
import FlutterMacOS
class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let flutterViewController = FlutterViewController.init()
    let windowFrame = self.frame
    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)
    RegisterGeneratedPlugins(registry: flutterViewController)
    super.awakeFromNib()
  }
}


import Cocoa
import FlutterMacOS
class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let flutterViewController = FlutterViewController()
    let windowFrame = self.frame
    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)
    RegisterGeneratedPlugins(registry: flutterViewController)
    super.awakeFromNib()
  }
}