-
Notifications
You must be signed in to change notification settings - Fork 28
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
kn: implement SdkBuffer
#1214
kn: implement SdkBuffer
#1214
Conversation
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
public suspend fun SdkSource.readToByteArray(): ByteArray = withContext(SdkDispatchers.IO) { | ||
use { it.buffer().readByteArray() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: the only reason I could see these were expect/actual
is because of Dispatchers.IO
, but we already have an expect/actual
version of that called SdkDispatchers
, so I've moved these to common and deleted the JVM/Native implementations
@InternalApi | ||
public actual object SdkDispatchers { | ||
/** | ||
* The CoroutineDispatcher that is designed for offloading blocking IO tasks to a shared pool of threads. | ||
*/ | ||
public actual val IO: CoroutineDispatcher | ||
get() = TODO("Not yet implemented") | ||
get() = Dispatchers.IO | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: we made this expect/actual
because Native didn't have Dispatchers.IO at the time. It does now, so we could remove SdkDispatchers and just use Dispatchers.IO
everywhere... but I think we'll need it again in the future when we support platforms like JS and WASM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless JetBrains implements dispatchers on those platforms first! 😁
import aws.smithy.kotlin.runtime.time.TimestampFormat | ||
import kotlinx.coroutines.IO | ||
import kotlinx.coroutines.withContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Why was this import added when nothing else changed in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was working in this file earlier, this import is unused now and I'm surprised ktlint didn't complain
/** | ||
* Used to wrap calls to Okio, catching Okio exceptions (e.g. okio.EOFException) and throwing our own (e.g. aws.smithy.kotlin.runtime.io.EOFException). | ||
*/ | ||
internal inline fun <T> SdkBufferedSource.wrapOkio(block: SdkBufferedSource.() -> T): T = try { | ||
block() | ||
} catch (e: okio.EOFException) { | ||
throw EOFException("Okio operation failed", e) | ||
} catch (e: okio.IOException) { | ||
throw IOException("Okio operation failed", e) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Consider adding the Okio exception message to the wrapped exception message:
throw EOFException("Okio operation failed: ${e.message}", e)
Different loggers and exception dumpers may print an entire exception including the cause but some won't and users may only have a top-level exception message to work with in some contexts.
public actual open class EOFException actual constructor(message: String?, cause: Throwable?) : IOException(message) { | ||
public actual constructor() : this(null, null) | ||
public actual constructor(message: String?) : this(message, null) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correctness: Pass the constructor cause
parameter to the superclass constructor:
class EOFException actual constructor(message: String?, cause: Throwable?) : IOException(message, cause)
actual override fun readShortLe(): Short { | ||
TODO("Not yet implemented") | ||
actual override fun emit() { | ||
wrapOkio { inner.emit() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Same as JVM implementation? Can this be moved to common?
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is SdkBuffer) return false | ||
return inner == other.inner | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Same as JVM implementation? Can this be moved to common?
@InternalApi | ||
public actual object SdkDispatchers { | ||
/** | ||
* The CoroutineDispatcher that is designed for offloading blocking IO tasks to a shared pool of threads. | ||
*/ | ||
public actual val IO: CoroutineDispatcher | ||
get() = TODO("Not yet implemented") | ||
get() = Dispatchers.IO | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless JetBrains implements dispatchers on those platforms first! 😁
@@ -4,157 +4,102 @@ | |||
*/ | |||
package aws.smithy.kotlin.runtime.io | |||
|
|||
import okio.Buffer | |||
import aws.smithy.kotlin.runtime.io.internal.* | |||
|
|||
public actual class SdkBuffer : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Do we still need platform-specific implementations of SDK buffer? Seems like basically everything is commonized or commonizable at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference I see is JVM has inputStream and outputStream methods. I'll see if this can be made common.
I think at some point we were considering using CRT for Native I/O. Okio is multiplatform so I was thinking we should just use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Their IO model matches ours better than CRT iirc.
This comment has been minimized.
This comment has been minimized.
Affected ArtifactsChanged in size
|
Issue #
Description of changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.