Skip to content
This repository was archived by the owner on Feb 22, 2025. It is now read-only.
This repository was archived by the owner on Feb 22, 2025. It is now read-only.

Type-safe read-only views #12

@ptitjes

Description

@ptitjes

In most of my use-cases, I need a read-only view of buffers (both Buffer and CompositeBuffer) with:

  • absolute read methods (i.e. random-access read)
  • relative read methods (i.e. sequential read)

It seems from e5l/view-and-refcount and whyoleg/resources that we are taking the route of having reference-counted underlying storages. So the following design proposal is based on this idea.

As a first step, I would propose that we extract a ReadBuffer interface from Buffer containing:

  • var readIndex: Int relative read index,
  • a new val readLimit: Int exclusive read limit index (always equal to writeIndex in Buffer's default implementation),
  • fun read*() relative read methods,
  • fun get*At(...) absolute read methods,
  • fun copyTo*(...) relative and absolute bulk read methods,
  • a new fun duplicate(): ReadBuffer method that returns a duplicate read buffer (with shared underlying storage but independent readIndex),
  • new fun slice(...): ReadBuffer methods that returns sliced duplicates.

Additionally, we would add the following to the Buffer interface:

  • a new val writeLimit: Int for "symmetry" (always equal to capacity)
  • an override override fun duplicate(): Buffer method that returns a duplicate buffer (with shared underlying storage but independent readIndex and writeIndex).

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