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

Support read-only views with random-access capability #225

Open
ptitjes opened this issue Sep 23, 2023 · 0 comments
Open

Support read-only views with random-access capability #225

ptitjes opened this issue Sep 23, 2023 · 0 comments

Comments

@ptitjes
Copy link

ptitjes commented Sep 23, 2023

For a lot of my use-cases, I would need some shared read-only buffer views with random-access capability.

The needed features would be:

  • being backed by a list of segments, to support large views
  • support random-access reads
  • support shared slices of views

Here is a proposed tentative design:

public fun Source.readView(byteCount: Long): BufferView

public fun Buffer.copyToView(startIndex: Long = 0L, endIndex: Long = size): BufferView

public class BufferView : AutoCloseableAlias {
    override fun close()

    public val size: Long

    public fun getByte(position: Long): Byte
    public fun getShort(position: Long): Short
    public fun getInt(position: Long): Int
    public fun getLong(position: Long): Long

    public fun slice(startIndex: Long = 0L, endIndex: Long = size): BufferView
}

I experimented with this design in this branch: https://github.com/ptitjes/kotlinx-io/tree/read-random-access

Corresponding discussion on kotlinlang's Slack: https://kotlinlang.slack.com/archives/CKCAAV8VB/p1694429247586879

This issue is dependent on #135.

@ptitjes ptitjes changed the title Support read-only views that support random-access Support read-only views with random-access capability Sep 23, 2023
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

No branches or pull requests

1 participant