Skip to content

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

Open
@ptitjes

Description

@ptitjes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions