AlipayApi.swift 3.63 KB
// // Copyright 2013 The Flutter Authors. All rights reserved.
// Autogenerated from Pigeon (v25.5.0), 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 pigeonError = error as? PigeonError {
    return [
      pigeonError.code,
      pigeonError.message,
      pigeonError.details,
    ]
  }
  if let flutterError = error as? FlutterError {
    return [
      flutterError.code,
      flutterError.message,
      flutterError.details,
    ]
  }
  return [
    "\(error)",
    "\(type(of: error))",
    "Stacktrace: \(Thread.callStackSymbols)",
  ]
}

private func isNullish(_ value: Any?) -> Bool {
  return value is NSNull || value == nil
}

private func nilOrValue<T>(_ value: Any?) -> T? {
  if value is NSNull { return nil }
  return value as! T?
}


/// Alipay payment result codes.
enum AliPayResultCode: Int {
  case success = 0
  case cancel = 1
  case error = 2
  case unsupported = 3
}

private class AlipayApiPigeonCodecReader: FlutterStandardReader {
  override func readValue(ofType type: UInt8) -> Any? {
    switch type {
    case 129:
      let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)
      if let enumResultAsInt = enumResultAsInt {
        return AliPayResultCode(rawValue: enumResultAsInt)
      }
      return nil
    default:
      return super.readValue(ofType: type)
    }
  }
}

private class AlipayApiPigeonCodecWriter: FlutterStandardWriter {
  override func writeValue(_ value: Any) {
    if let value = value as? AliPayResultCode {
      super.writeByte(129)
      super.writeValue(value.rawValue)
    } else {
      super.writeValue(value)
    }
  }
}

private class AlipayApiPigeonCodecReaderWriter: FlutterStandardReaderWriter {
  override func reader(with data: Data) -> FlutterStandardReader {
    return AlipayApiPigeonCodecReader(data: data)
  }

  override func writer(with data: NSMutableData) -> FlutterStandardWriter {
    return AlipayApiPigeonCodecWriter(data: data)
  }
}

class AlipayApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
  static let shared = AlipayApiPigeonCodec(readerWriter: AlipayApiPigeonCodecReaderWriter())
}

/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol AlipayHostApi {
  func launchAliPay(prepayData: String) throws -> AliPayResultCode
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class AlipayHostApiSetup {
  static var codec: FlutterStandardMessageCodec { AlipayApiPigeonCodec.shared }
  /// Sets up an instance of `AlipayHostApi` to handle messages through the `binaryMessenger`.
  static func setUp(binaryMessenger: FlutterBinaryMessenger, api: AlipayHostApi?, messageChannelSuffix: String = "") {
    let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
    let launchAliPayChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.AlipayHostApi.launchAliPay\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
    if let api = api {
      launchAliPayChannel.setMessageHandler { message, reply in
        let args = message as! [Any?]
        let prepayDataArg = args[0] as! String
        do {
          let result = try api.launchAliPay(prepayData: prepayDataArg)
          reply(wrapResult(result))
        } catch {
          reply(wrapError(error))
        }
      }
    } else {
      launchAliPayChannel.setMessageHandler(nil)
    }
  }
}