-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
zero-copy ByteArray to Buffer for reading purpose #1485
Comments
Could you use UnsafeCursor? |
How to wrap the array using unsafe cursor? I only see a transfer method to still write bytes to the buffer. Maybe by setting the bytes to |
You’d use this API to get a ByteArray that you can write bytes into. (That is only useful if the APIs you’re interacting with let you provide the target byte arrays.) |
Ah ok, this is already ok for the encoding part. I'm mainly talking about decoding data from a |
I would like something like |
@swankjesse do you have a solution for reading from a |
The problem is the the "Buffered" in Now looking at So it seems technically possible, and has the same relative guarantees as |
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 aByteArray
and we have no room for improvement to useByteBuffer
or even okio'sBuffer
.We can encode easily data to a
Buffer
then reading the content to aByteArray
.But for decoding from a
ByteArray
, with okio, we only have to choice to first copy the content to aBuffer
and then decode, that is really bad regarding performances.By the way, we are not using directly
Buffer
butBufferedSink
andBufferedSource
for this really great encoding/decoding API, but sadly those interfaces aresealed
.Proposal
A constructor of
BufferedSource
that takes aByteArray
to allow reading "complex" values (readLongLe, readUtf8, ...) over aByteArray
Non goal
Backing a
Buffer
with aByteArray
: #1360The text was updated successfully, but these errors were encountered: