Skip to content

Instantly share code, notes, and snippets.

@Malinskiy
Created April 28, 2020 10:42
Show Gist options
  • Save Malinskiy/2a531188d07347fbfb3755173e4731b6 to your computer and use it in GitHub Desktop.
Save Malinskiy/2a531188d07347fbfb3755173e4731b6 to your computer and use it in GitHub Desktop.
/**
* This type of request starts with single serialized request
* and then proceed to do several reads and writes that have dynamic size
*/
abstract class ComplexRequest<T : Any?>(target: Target = NonSpecifiedTarget) : Request(target) {
/**
* Some requests ignore the initial OKAY/FAIL response and instead stream the actual response
* To implement these we allow overriding this method
*/
open suspend fun process(readChannel: AndroidReadChannel, writeChannel: AndroidWriteChannel): T {
handshake(readChannel, writeChannel)
return readElement(readChannel, writeChannel)
}
abstract suspend fun readElement(readChannel: AndroidReadChannel, writeChannel: AndroidWriteChannel): T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment