Skip to content

zero-copy ByteArray to Buffer for reading purpose #1485

Open

Description

Context

I'm currently the maintainer of avro4k and I'm planning to use okio for kicking out java streams and hoping a day to be multiplatform.

A lot of apps/libs/frameworks are dealing only with ByteArray (I'm not saying it's a good idea though). On our side, in the avro world, and especially in the messaging world (kafka, rabbitmq, ...) everything is using a ByteArray and we have no room for improvement to use ByteBuffer or even okio's Buffer.

We can encode easily data to a Buffer then reading the content to a ByteArray.

But for decoding from a ByteArray, with okio, we only have to choice to first copy the content to a Buffer and then decode, that is really bad regarding performances.

By the way, we are not using directly Buffer but BufferedSink and BufferedSource for this really great encoding/decoding API, but sadly those interfaces are sealed.

Proposal

A constructor of BufferedSource that takes a ByteArray to allow reading "complex" values (readLongLe, readUtf8, ...) over a ByteArray

Non goal

Backing a Buffer with a ByteArray : #1360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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