-
Notifications
You must be signed in to change notification settings - Fork 60
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
Okio adapters #178
Comments
@BoD thank you for the suggestion! |
I don't have a specific need at the moment. I work on Apollo Kotlin, which exposes a few Okio symbols in its API. As of today this has been working well for us and our users. But I can imagine a future where Kotlinx-io becomes prevalent, and then the question will arise for us to decide whether we should switch - which will impact our users. If there is an easy way to transition (i.e, use a new version of Apollo Kotlin that uses Kotlinx-io, but keep using Okio in the project, by 'converting' the symbols as needed), this will help this decision. This reminds me a bit of the Coroutines to Rx adapters, which helped people transition. I agree that this certainly not urgent for now. (Although, this may help the adoption of Kotlinx-io?) |
@fzhinkin I've worked on three projects that use We've had a substantial ecosystem of libraries that work with Here are two examples I can recall off the top of my head: I'm using ksoup in one of my libraries that accepts In another project where I use |
I have this need in Krossbow. It's a STOMP library built on top of multiple interchangeable web socket implementations (very much like Ktor, which is actually one of the supported WS implementations). And OkHttp is also one of the web socket implementations (directly adapted to Krossbow, not through Ktor). I'm in the process of migrating all the internals of my library from When writing the OkHttp engine bindings, it would be great not to have to copy bytes around from Okio buffers to |
Currently looking at what functions could be provided. fun kotlinx.io.RawSource.asOkioSource(): okio.Source
fun kotlinx.io.RawSink.asOkioSink(): okio.Sink
fun okio.Sink.asKotlinxIoRawSink(): kotlinx.io.RawSink
fun okio.Source.asKotlinxIoRawSource(): kotlinx.io.RawSource
fun okio.ByteString.toKotlinxIoByteString(): kotlinx.io.ByteString
fun kotlinx.io.ByteString.toOkioByteString(): okio.ByteString
// These two only as a way to reduce a conversion overhead
fun okio.BufferedSink.write(buffer: kotlinx.io.Buffer, byteCount: Long)
fun kotlinx.io.Sink.write(buffer: okio.Buffer, byteCount: Long) Is there anything else worth supporting out of the box? |
These look good to me! |
I have a hard time seeing where you'd use the last two anywhere except as implementation for the first six. Not that it hurts to expose them or anything. |
I was considering them as an option for those who want to abstain from allocating new wrappers, but we can start without them and see how it goes. |
Created a new `kotlinx-io-okio` module that adapts: - `kotlinx.io.RawSource` to `okio.Source` and vice versa; - `kotlinx.io.RawSink` to `okio.Sink` and vice versa; - `kotlinx.io.bytestring.ByteString` to `okio.ByteString` and vice versa. The module will be published only for targets supported by Okio. Closes #178
Now that #131 is done (and with more work down the road to stabilize and make it full featured), this library should eventually become a good alternative to Okio.
Given that Okio is very popular, we can expect that the 2 libraries will cohabit for a while. Making adapters to go from one to the other would help with the transition period.
Things like
fun okio.Sink.asKotlinxIoRawSink(): kotlinx.io.RawSink
,fun kotlinx.io.RawSource.asOkioSource(): okio.Source
, etc.The text was updated successfully, but these errors were encountered: