-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[pigeon] adds event channel support for kotlin and swift #7892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.