VP
Size: a a a
VP
KG
VP
KG
VP
VP
KG
abstract class BaseMessageType {}
class SomeType: BaseMessageType() {}
class OtherType: BaseMessageType() {}
interface UserCallbacks {
fun onSomeMessage(msg: SomeType)
fun onOtherMessage(msg: OtherType)
}
class LibraryApi(val callbacks: UserCallbacks) {
fun parse(msg: Array<Byte>) {
if (msg.size % 2 == 1) callbacks.onSomeMessage(SomeType())
else callbacks.onOtherMessage(OtherType())
}
}
fun Flow<Array<Byte>>.parse(): Flow<BaseMessageType> = callbackFlow {
val callbacks = object: UserCallbacks {
override fun onSomeMessage(msg: SomeType) { offer(msg) }
override fun onOtherMessage(msg: OtherType) { offer(msg) }
}
val parser = LibraryApi(callbacks)
collect { bytes -> parser.parse(bytes) }
}KG
VP
abstract class BaseMessageType {}
class SomeType: BaseMessageType() {}
class OtherType: BaseMessageType() {}
interface UserCallbacks {
fun onSomeMessage(msg: SomeType)
fun onOtherMessage(msg: OtherType)
}
class LibraryApi(val callbacks: UserCallbacks) {
fun parse(msg: Array<Byte>) {
if (msg.size % 2 == 1) callbacks.onSomeMessage(SomeType())
else callbacks.onOtherMessage(OtherType())
}
}
fun Flow<Array<Byte>>.parse(): Flow<BaseMessageType> = callbackFlow {
val callbacks = object: UserCallbacks {
override fun onSomeMessage(msg: SomeType) { offer(msg) }
override fun onOtherMessage(msg: OtherType) { offer(msg) }
}
val parser = LibraryApi(callbacks)
collect { bytes -> parser.parse(bytes) }
}suspend fun parse(bytes): MessageKG
suspend fun parse(bytes): MessageVP
VP
AN
VP
void doSomething(args, callback)AN
void doSomething(args, callback)AN
KG
AN
KG
VP
flowOf(foo).parse().toList()