Skip to content
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

Convert ByteString from/to Int8Array #386

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

fzhinkin
Copy link
Collaborator

@fzhinkin fzhinkin commented Sep 5, 2024

Closes #268


package kotlinx.io.bytestring

import org.khronos.webgl.ArrayBuffer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that should probably be addressed for all kotlinx libraries: should everyone use these built-in types, which are pretty weird considering we generally don't want anything to do with WebGL, or should they come from kotlin-wrappers, which tend to be the most used?

The question is important because the only "interop" between same types coming from different libs is unsafe-casting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an ArrayBuffer originating from kotlin-wrappers needs to be converted to/from ByteString, then it should be done either in kotlin-wrappers, or in a separate library.

Copy link
Contributor

@lppedd lppedd Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's reasonable. However I'm thinking that since most people on K/JS are using kotlin-wrappers (and most commonly its kotlin-js module), it would be a surprise to them that the code is red in the IDE when calling Int8Array.toByteString(), for example.

It's a bit of an unfortunate situation because it's all fragmented into multiple places.

  1. The org.khronos.webgl package is explicitly documented as a wrapper for WebGL, so the question "why am I using WebGL types?" would come up fairly naturally.

  2. The org.khronos.webgl package is a remnant of the extraction (KT-35973) of DOM APIs from the stdlib, and there is also an open issue about moving away from it (KT-57303). So maybe using kotlin-wrapper types ensures better stability on the long run.

I guess the right call would be to have the Kotlin team officially say "we will all use these types for JS", and I guess being kotlin-wrappers is the most complete and up to date collection, that could be the direction. If the stdlib needs a small interop layer, its externals could be made internal.

Anyway, from my perspective, it's all good anyway, I'd just unsafeCast<T>, but it's something I wanted to mention for more clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants