Skip to content

Commit

Permalink
issue(160501): added generation of empty classes in dart
Browse files Browse the repository at this point in the history
  • Loading branch information
feduke-nukem committed Dec 21, 2024
1 parent 3515aba commit 61a6f32
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,68 +1,98 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon, do not edit directly.
// Autogenerated from Pigeon (v22.7.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")


import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.common.MessageCodec
import io.flutter.plugin.common.StandardMethodCodec
import io.flutter.plugin.common.StandardMessageCodec
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer

/**
* Generated class from Pigeon that represents data sent in messages. This class should not be
* extended by any user class outside of the generated file.
* Generated class from Pigeon that represents data sent in messages.
* This class should not be extended by any user class outside of the generated file.
*/
sealed class PlatformEvent
sealed class PlatformEvent
/** Generated class from Pigeon that represents data sent in messages. */
data class IntEvent(val data: Long) : PlatformEvent() {
data class IntEvent (
val data: Long
) : PlatformEvent()
{
companion object {
fun fromList(pigeonVar_list: List<Any?>): IntEvent {
val data = pigeonVar_list[0] as Long
return IntEvent(data)
}
}

fun toList(): List<Any?> {
return listOf(
data,
data,
)
}
}

/** Generated class from Pigeon that represents data sent in messages. */
data class StringEvent(val data: String) : PlatformEvent() {
data class StringEvent (
val data: String
) : PlatformEvent()
{
companion object {
fun fromList(pigeonVar_list: List<Any?>): StringEvent {
val data = pigeonVar_list[0] as String
return StringEvent(data)
}
}

fun toList(): List<Any?> {
return listOf(
data,
data,
)
}
}

/** Generated class from Pigeon that represents data sent in messages. */
class EmptyEvent (
) : PlatformEvent()
{
companion object {
fun fromList(pigeonVar_list: List<Any?>): EmptyEvent {
return EmptyEvent()
}
}
fun toList(): List<Any?> {
return listOf(
)
}
}
private open class EventChannelMessagesPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
129.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let { IntEvent.fromList(it) }
return (readValue(buffer) as? List<Any?>)?.let {
IntEvent.fromList(it)
}
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let { StringEvent.fromList(it) }
return (readValue(buffer) as? List<Any?>)?.let {
StringEvent.fromList(it)
}
}
131.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
EmptyEvent.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}

override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
when (value) {
is IntEvent -> {
stream.write(129)
Expand All @@ -72,15 +102,21 @@ private open class EventChannelMessagesPigeonCodec : StandardMessageCodec() {
stream.write(130)
writeValue(stream, value.toList())
}
is EmptyEvent -> {
stream.write(131)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
}

val EventChannelMessagesPigeonMethodCodec = StandardMethodCodec(EventChannelMessagesPigeonCodec())
val EventChannelMessagesPigeonMethodCodec = StandardMethodCodec(EventChannelMessagesPigeonCodec());


private class PigeonStreamHandler<T>(val wrapper: PigeonEventChannelWrapper<T>) :
EventChannel.StreamHandler {
private class PigeonStreamHandler<T>(
val wrapper: PigeonEventChannelWrapper<T>
) : EventChannel.StreamHandler {
var pigeonSink: PigeonEventSink<T>? = null

override fun onListen(p0: Any?, sink: EventChannel.EventSink) {
Expand Down Expand Up @@ -108,27 +144,22 @@ class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
sink.error(errorCode, errorMessage, errorDetails)
}

fun endOfStream() {
fun endOfStream() {
sink.endOfStream()
}
}

abstract class StreamEventsStreamHandler : PigeonEventChannelWrapper<PlatformEvent> {
companion object {
fun register(
messenger: BinaryMessenger,
streamHandler: StreamEventsStreamHandler,
instanceName: String = ""
) {
var channelName: String =
"dev.flutter.pigeon.pigeon_example_package.EventChannelMethods.streamEvents"
fun register(messenger: BinaryMessenger, streamHandler: StreamEventsStreamHandler, instanceName: String = "") {
var channelName: String = "dev.flutter.pigeon.pigeon_example_package.EventChannelMethods.streamEvents"
if (instanceName.isNotEmpty()) {
channelName += ".$instanceName"
}
val internalStreamHandler = PigeonStreamHandler<PlatformEvent>(streamHandler)
EventChannel(messenger, channelName, EventChannelMessagesPigeonMethodCodec)
.setStreamHandler(internalStreamHandler)
EventChannel(messenger, channelName, EventChannelMessagesPigeonMethodCodec).setStreamHandler(internalStreamHandler)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PigeonEventSink
import PlatformEvent
import StreamEventsStreamHandler
import StringEvent
import EmptyEvent
import android.os.Handler
import android.os.Looper
import io.flutter.embedding.android.FlutterActivity
Expand Down Expand Up @@ -72,6 +73,10 @@ class EventListener : StreamEventsStreamHandler() {
eventSink?.success(StringEvent(data = event))
}

fun onEmptyEvent() {
eventSink?.success(EmptyEvent())
}

fun onEventsDone() {
eventSink?.endOfStream()
eventSink = null
Expand All @@ -93,6 +98,11 @@ fun sendEvents(eventListener: EventListener) {
eventListener.onIntEvent(count.toLong())
count++
}
} else if (count % 5 == 0) {
handler.post {
eventListener.onEmptyEvent()
count++
}
} else {
handler.post {
eventListener.onStringEvent(count.toString())
Expand Down
8 changes: 8 additions & 0 deletions packages/pigeon/example/app/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class EventListener: StreamEventsStreamHandler {
}
}

func onEmptyEvent() {
if let eventSink = eventSink {
eventSink.success(EmptyEvent())
}
}

func onEventsDone() {
eventSink?.endOfStream()
eventSink = nil
Expand All @@ -84,6 +90,8 @@ func sendEvents(_ eventListener: EventListener) {
} else {
if (count % 2) == 0 {
eventListener.onIntEvent(event: Int64(count))
} else if (count % 5) == 0 {
eventListener.onEmptyEvent()
} else {
eventListener.onStringEvent(event: String(count))
}
Expand Down
44 changes: 32 additions & 12 deletions packages/pigeon/example/app/ios/Runner/EventChannelMessages.g.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon, do not edit directly.
// Autogenerated from Pigeon (v22.7.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down Expand Up @@ -33,6 +33,7 @@ protocol PlatformEvent {
struct IntEvent: PlatformEvent {
var data: Int64


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> IntEvent? {
let data = pigeonVar_list[0] as! Int64
Expand All @@ -52,6 +53,7 @@ struct IntEvent: PlatformEvent {
struct StringEvent: PlatformEvent {
var data: String


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> StringEvent? {
let data = pigeonVar_list[0] as! String
Expand All @@ -67,13 +69,31 @@ struct StringEvent: PlatformEvent {
}
}

/// Generated class from Pigeon that represents data sent in messages.
struct EmptyEvent: PlatformEvent {


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> EmptyEvent? {

return EmptyEvent(
)
}
func toList() -> [Any?] {
return [
]
}
}

private class EventChannelMessagesPigeonCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 129:
return IntEvent.fromList(self.readValue() as! [Any?])
case 130:
return StringEvent.fromList(self.readValue() as! [Any?])
case 131:
return EmptyEvent.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand All @@ -88,6 +108,9 @@ private class EventChannelMessagesPigeonCodecWriter: FlutterStandardWriter {
} else if let value = value as? StringEvent {
super.writeByte(130)
super.writeValue(value.toList())
} else if let value = value as? EmptyEvent {
super.writeByte(131)
super.writeValue(value.toList())
} else {
super.writeValue(value)
}
Expand All @@ -105,12 +128,11 @@ private class EventChannelMessagesPigeonCodecReaderWriter: FlutterStandardReader
}

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

var eventChannelMessagesPigeonMethodCodec = FlutterStandardMethodCodec(
readerWriter: EventChannelMessagesPigeonCodecReaderWriter())
var eventChannelMessagesPigeonMethodCodec = FlutterStandardMethodCodec(readerWriter: EventChannelMessagesPigeonCodecReaderWriter());


private class PigeonStreamHandler<ReturnType>: NSObject, FlutterStreamHandler {
private let wrapper: PigeonEventChannelWrapper<ReturnType>
Expand Down Expand Up @@ -162,18 +184,16 @@ class PigeonEventSink<ReturnType> {
}

class StreamEventsStreamHandler: PigeonEventChannelWrapper<PlatformEvent> {
static func register(
with messenger: FlutterBinaryMessenger,
instanceName: String = "",
streamHandler: StreamEventsStreamHandler
) {
static func register(with messenger: FlutterBinaryMessenger,
instanceName: String = "",
streamHandler: StreamEventsStreamHandler) {
var channelName = "dev.flutter.pigeon.pigeon_example_package.EventChannelMethods.streamEvents"
if !instanceName.isEmpty {
channelName += ".\(instanceName)"
}
let internalStreamHandler = PigeonStreamHandler<PlatformEvent>(wrapper: streamHandler)
let channel = FlutterEventChannel(
name: channelName, binaryMessenger: messenger, codec: eventChannelMessagesPigeonMethodCodec)
let channel = FlutterEventChannel(name: channelName, binaryMessenger: messenger, codec: eventChannelMessagesPigeonMethodCodec)
channel.setStreamHandler(internalStreamHandler)
}
}

2 changes: 2 additions & 0 deletions packages/pigeon/example/app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class _MyHomePageState extends State<MyHomePage> {
case StringEvent():
final String stringData = event.data;
yield '$stringData, ';
case EmptyEvent():
yield 'EmptyEvent, ';
}
}
}
Expand Down
Loading

0 comments on commit 61a6f32

Please sign in to comment.