-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pigeon] adds event channel support for kotlin and swift (#7892)
adds event channel support for kotlin and swift work towards flutter/flutter#66711 adds sealed classes with extensions (empty base classes only) fixes flutter/flutter#155859 (Fix a small inconsistency with Pigeon docs) adds some convenience methods to Root fixes generation/format tests to include test pigeons Makes swift codec class names upper camel case
- Loading branch information
1 parent
ea90218
commit 71a2e70
Showing
48 changed files
with
4,144 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
.../app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/EventChannelMessages.g.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// 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. | ||
// See also: https://pub.dev/packages/pigeon | ||
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") | ||
|
||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.plugin.common.EventChannel | ||
import io.flutter.plugin.common.StandardMessageCodec | ||
import io.flutter.plugin.common.StandardMethodCodec | ||
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. | ||
*/ | ||
sealed class PlatformEvent | ||
/** Generated class from Pigeon that represents data sent in messages. */ | ||
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, | ||
) | ||
} | ||
} | ||
|
||
/** Generated class from Pigeon that represents data sent in messages. */ | ||
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, | ||
) | ||
} | ||
} | ||
|
||
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) } | ||
} | ||
130.toByte() -> { | ||
return (readValue(buffer) as? List<Any?>)?.let { StringEvent.fromList(it) } | ||
} | ||
else -> super.readValueOfType(type, buffer) | ||
} | ||
} | ||
|
||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { | ||
when (value) { | ||
is IntEvent -> { | ||
stream.write(129) | ||
writeValue(stream, value.toList()) | ||
} | ||
is StringEvent -> { | ||
stream.write(130) | ||
writeValue(stream, value.toList()) | ||
} | ||
else -> super.writeValue(stream, value) | ||
} | ||
} | ||
} | ||
|
||
val EventChannelMessagesPigeonMethodCodec = StandardMethodCodec(EventChannelMessagesPigeonCodec()) | ||
|
||
private class PigeonStreamHandler<T>(val wrapper: PigeonEventChannelWrapper<T>) : | ||
EventChannel.StreamHandler { | ||
var pigeonSink: PigeonEventSink<T>? = null | ||
|
||
override fun onListen(p0: Any?, sink: EventChannel.EventSink) { | ||
pigeonSink = PigeonEventSink<T>(sink) | ||
wrapper.onListen(p0, pigeonSink!!) | ||
} | ||
|
||
override fun onCancel(p0: Any?) { | ||
pigeonSink = null | ||
wrapper.onCancel(p0) | ||
} | ||
} | ||
|
||
interface PigeonEventChannelWrapper<T> { | ||
open fun onListen(p0: Any?, sink: PigeonEventSink<T>) {} | ||
|
||
open fun onCancel(p0: Any?) {} | ||
} | ||
|
||
class PigeonEventSink<T>(private val sink: EventChannel.EventSink) { | ||
fun success(value: T) { | ||
sink.success(value) | ||
} | ||
|
||
fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) { | ||
sink.error(errorCode, errorMessage, errorDetails) | ||
} | ||
|
||
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" | ||
if (instanceName.isNotEmpty()) { | ||
channelName += ".$instanceName" | ||
} | ||
val internalStreamHandler = PigeonStreamHandler<PlatformEvent>(streamHandler) | ||
EventChannel(messenger, channelName, EventChannelMessagesPigeonMethodCodec) | ||
.setStreamHandler(internalStreamHandler) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.